diff options
| author | admin (centauri.fritz.box) <puppet@mx.buetow.org> | 2014-06-30 23:53:04 +0200 |
|---|---|---|
| committer | admin (centauri.fritz.box) <puppet@mx.buetow.org> | 2014-06-30 23:53:04 +0200 |
| commit | adc4b59a3e7c9db6f33670164490830d87331228 (patch) | |
| tree | adc5d21856852bfb5c3cca794a9c07ad476d877e /examples | |
| parent | 63cf3028445d8d213ffc774f77aafd7283cb4fbd (diff) | |
| parent | 5ab5de91eb0ae6ed9db78a2c8c47ec67f105e504 (diff) | |
Mergebuild-010393-lambda
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/all-examples.txt | 377 | ||||
| -rw-r--r-- | examples/assert.fy | 14 | ||||
| -rw-r--r-- | examples/bitwise.fy | 32 | ||||
| -rw-r--r-- | examples/comments.fy | 21 | ||||
| -rw-r--r-- | examples/conditionals.fy | 41 | ||||
| -rw-r--r-- | examples/control.fy | 32 | ||||
| -rw-r--r-- | examples/expressions.fy | 31 | ||||
| -rw-r--r-- | examples/fork.fy | 14 | ||||
| -rw-r--r-- | examples/functions.fy | 25 | ||||
| -rw-r--r-- | examples/inlinefunctions.fy | 20 | ||||
| -rw-r--r-- | examples/io.fy | 13 | ||||
| -rw-r--r-- | examples/netsted.fype | 11 | ||||
| -rw-r--r-- | examples/procedures.fy | 30 | ||||
| -rw-r--r-- | examples/reverse.fype | 7 | ||||
| -rw-r--r-- | examples/scopeing.fy | 31 | ||||
| -rw-r--r-- | examples/synonyms.fy | 37 | ||||
| -rw-r--r-- | examples/types.fy | 14 | ||||
| -rw-r--r-- | examples/variables.fy | 21 |
18 files changed, 0 insertions, 771 deletions
diff --git a/examples/all-examples.txt b/examples/all-examples.txt deleted file mode 100644 index f71e8a2..0000000 --- a/examples/all-examples.txt +++ /dev/null @@ -1,377 +0,0 @@ - -#* - * Examples of how to use bitwise operators - *# - -# Prints "01\n" -assert 0 == (put 1 and 0); -assert 1 == (say 1 and 1); - -# Prints "01\n" -assert 0 == (put 0 or 0); -assert 1 == (say 0 or 1); - -# Prints "01\n" -assert 0 == (put 1 xor 1); -assert 1 == (say 1 xor 0); - -# Prints "82\n" -assert 8 == (put 2 :< 2); -assert 2 == (say 8 :> 2); - -# A bit more complex, prints "9\n" -assert 9 == (say 1 :< 5 :> 5 or 2 and 5 xor 8); - -# Same result, but with parenthesis: -assert 9 == (say ((((1 :< 5) :> 5) or 2) and 5) xor 8); - -# Different parenthesis, different result: "1\n" -assert 1 == (say 1 :< 5 :> 5 or 2 and (5 xor 8)); - -# Prints "-1" -assert (neg 1) == (say neg not 0); - - -#* - * Simple examples how to write comments - *# - -# This is a single lined comment - -say 1 + 1; # This is a comment at the end of the line - -say 1 #* This is an embedded comment *# + 1; - -#* This is - a - multiline - comment *# - -#* - * This is - * a nicer looking - * multiline comment - *# - - -#* - * Simple conditional tests - *# - -# "0010\n" -assert 0 == (put 1 < 1); -assert 0 == (put 1 < 0); -assert 1 == (put 0 < 1); -assert 0 == (say 0 < 0); - -# "0100\n" -assert 0 == (put 1 > 1); -assert 1 == (put 1 > 0); -assert 0 == (put 0 > 1); -assert 0 == (say 0 > 0); - -# "1001\n" -assert 1 == (put 1 == 1); -assert 0 == (put 1 == 0); -assert 0 == (put 0 == 1); -assert 1 == (say 0 == 0); - -# "0110\n" -assert 0 == (put 1 != 1); -assert 1 == (put 1 != 0); -assert 1 == (put 0 != 1); -assert 0 == (say 0 != 0); - -# "1011\n" -assert 1 == (put 1 <= 1); -assert 0 == (put 1 <= 0); -assert 1 == (put 0 <= 1); -assert 1 == (say 0 <= 0); - -## "1101\n" -assert 1 == (put 1 >= 1); -assert 1 == (put 1 >= 0); -assert 0 == (put 0 >= 1); -assert 1 == (say 0 >= 0); - - - -#* - * Examples of how to use control statements - *# - -if 1 { - say "if 1"; -} - -ifnot 0 == 1 { - say "ifnot 0 == 1"; -} - -# Calculate 10! - -my n = 10, fac = 0; - -while n > 1 { - ifnot fac { - fac = 1; - } - say fac = (fac * n); - decr n; -} - -# Count up to 10 - -n = 0; - -until n == 10 { - say incr n; -} - - -#* - * Simple expression tests - *# - -# Result 10 -assert 10 == say (8 / 2) + 2 * 3; - -# Result 12 -assert 12 == say 2 * (4 + 2); - -# Result 4 -assert 4 == say 2 * (4 / 2); - -# Result 4 -assert 4 == say 2 * (4 / 2); - -# Result 4 -assert 4 == say 2 * (4 / 2); - -# Result 46 -assert 46 == say "12" + "34"; - -# Result 1231 -assert 1231 == say "1234" - "3"; - -# Result 24 -assert "24" == say "2ab" * "12"; - -# Result 5.0 -assert 5 == say "10 bla" / 2; - - -#* - * Examples of how to use fork - *# - -my pid = fork; - -if pid { - put "I am the parent process and the child has the pid "; - say pid; -} - -ifnot pid { - say "I am the child process"; -} - -#* - * Examples of how to use functions - *# - -func foo { - say 1 + a * 3 + b; - - func bar { - say "Hello i am nested"; - } - - bar; # Calling nested -} - -my a = 2, b = 4; # Create global variables -foo; -assert 0 == (defined bar); # bar is not available anymore - -func baz { - say "I am baz"; - undef baz; -} - -baz; # Baz deletes itself -assert 0 == (defined baz); # baz is not available anymore - -#* - * Simple builtin function tests - *# - -# Print "-20\n" -assert (neg 20) == (say neg 20); - -# Print "30\n" -assert 30 == (say 10 - neg 20); - -# Print "-30\n" -assert (neg 30) == (say neg neg neg 10 - neg 20); - -# Print "Hello\n" -put "Hello"; -ln; - -# Exit with exit code 0 -exit 10 + 10 - 5 - 15; - - -#* - * Simple I/O examples. Currently only output is supported. - *# - -# Print out 10 followed by a newline -say 10; - -# Print out 20 without a newline followed -put 20; - -# Print out a newline -ln; - - -#* - * Examples of how to use procedures - *# - -proc foo { - say 1 + a * 3 + b; - my c = 6; -} - -my a = 2, b = 4; - -foo; # Run the procedure. Print out "11\n" -say c; # Print out "6\n"; - -proc bar { - say "I am bar"; - - undef baz; - - proc baz { - say "I am baz"; - } -} - -# Here bar would produce an error because the proc is not yet defined! -# bar; - -bar; # Here the procedure bar will define the procedure baz! -baz; # Now the procedure baz is defined! -bar; # Here the procedure bar will redefine baz again! - -#* - * Examples of how to use scopeing - *# - -my foo = 1; - -{ - # Prints out 1 - assert 1 == (put defined foo); - - { - my bar = 2; - - # Prints out 1 - assert 1 == (put defined bar); - - # Prints out all available symbols at - # the current program position. - scope; - } - - # Prints out 0 - assert 0 == (put defined bar); - - my baz = 3; -} - -# Prints out 0 -assert 0 == (say defined bar); - - - -#* - * Examples of how to use synonyms - *# - -# Create a variable foo, and bar is a synonym for foo -my foo = "foo"; -my bar = \foo; - -# Reset the value of foo -foo = "bar"; - -# The synonym variable should now also set to "bar" -assert "bar" == say bar; - -# Create a new procedure baz -proc baz { - say "I am baz"; -} - -# Make a synonym baz, and undefine baz -my bay = \baz; - -# Should be the num of syms for the same value -assert 2 == syms baz; -assert 2 == syms bay; -undef baz; -assert 1 == syms bay; - -# bay still has a reference of the original procedure baz -bay; # this prints aut "I am baz" - -assert 0 == defined baz; -assert 1 == defined bay; - -# This removes the procedure from memory -undef bay; - - -#* - * Examples how to convert types - *# - -assert 1 == say 1; # Integer output - -assert 1 == say double 1; # Double output - -assert 14 == say 1 + string 13; # Implicit type conversion to Integer - -assert 2 == say integer 2.8; # Rounds down to the Integer 2 - -assert say integer double string put say neg 12; # Nonsense but working :) - - -#* - * Examples of how to define variables - *# - -# Defines the variables -my foo = 1 + 1; -my bar = 4 - 1, baz = 100 + 1, bay; - -# bay has been initialized with the default value of 0 -say bay; - -# Prints out "5\n" -assert 5 == (say foo + bar); - -# Pritns out "51101\n" -assert 51 == (put baz - 50); -assert 101 == (say baz); - -# Change the value of the variable to 99 and print it out -assert 99 == (baz = 99); -say baz; - diff --git a/examples/assert.fy b/examples/assert.fy deleted file mode 100644 index d9871f5..0000000 --- a/examples/assert.fy +++ /dev/null @@ -1,14 +0,0 @@ -#* - * Examples of how to use asserts - *# - -# The built in function assert checks if a condition evaluates to true -# and aborts the interpreter if it evaluates to false. - -# Evaluates to true -assert 0 == 0 -assert 6 == 2 * 3 - -# Evaluates to false -# assert 1 == 0 - diff --git a/examples/bitwise.fy b/examples/bitwise.fy deleted file mode 100644 index 03fda6c..0000000 --- a/examples/bitwise.fy +++ /dev/null @@ -1,32 +0,0 @@ -#* - * Examples of how to use bitwise operators - *# - -# Prints "01\n" -assert 0 == (put 1 and 0); -assert 1 == (say 1 and 1); - -# Prints "01\n" -assert 0 == (put 0 or 0); -assert 1 == (say 0 or 1); - -# Prints "01\n" -assert 0 == (put 1 xor 1); -assert 1 == (say 1 xor 0); - -# Prints "82\n" -assert 8 == (put 2 :< 2); -assert 2 == (say 8 :> 2); - -# A bit more complex, prints "9\n" -assert 9 == (say 1 :< 5 :> 5 or 2 and 5 xor 8); - -# Same result, but with parenthesis: -assert 9 == (say ((((1 :< 5) :> 5) or 2) and 5) xor 8); - -# Different parenthesis, different result: "1\n" -assert 1 == (say 1 :< 5 :> 5 or 2 and (5 xor 8)); - -# Prints "-1" -assert (neg 1) == (say neg not 0); - diff --git a/examples/comments.fy b/examples/comments.fy deleted file mode 100644 index 216e41b..0000000 --- a/examples/comments.fy +++ /dev/null @@ -1,21 +0,0 @@ -#* - * Simple examples how to write comments - *# - -# This is a single lined comment - -say 1 + 1; # This is a comment at the end of the line - -say 1 #* This is an embedded comment *# + 1; - -#* This is - a - multiline - comment *# - -#* - * This is - * a nicer looking - * multiline comment - *# - diff --git a/examples/conditionals.fy b/examples/conditionals.fy deleted file mode 100644 index 1260ae2..0000000 --- a/examples/conditionals.fy +++ /dev/null @@ -1,41 +0,0 @@ -#* - * Simple conditional tests - *# - -# "0010\n" -assert 0 == (put 1 < 1); -assert 0 == (put 1 < 0); -assert 1 == (put 0 < 1); -assert 0 == (say 0 < 0); - -# "0100\n" -assert 0 == (put 1 > 1); -assert 1 == (put 1 > 0); -assert 0 == (put 0 > 1); -assert 0 == (say 0 > 0); - -# "1001\n" -assert 1 == (put 1 == 1); -assert 0 == (put 1 == 0); -assert 0 == (put 0 == 1); -assert 1 == (say 0 == 0); - -# "0110\n" -assert 0 == (put 1 != 1); -assert 1 == (put 1 != 0); -assert 1 == (put 0 != 1); -assert 0 == (say 0 != 0); - -# "1011\n" -assert 1 == (put 1 <= 1); -assert 0 == (put 1 <= 0); -assert 1 == (put 0 <= 1); -assert 1 == (say 0 <= 0); - -## "1101\n" -assert 1 == (put 1 >= 1); -assert 1 == (put 1 >= 0); -assert 0 == (put 0 >= 1); -assert 1 == (say 0 >= 0); - - diff --git a/examples/control.fy b/examples/control.fy deleted file mode 100644 index 0deac78..0000000 --- a/examples/control.fy +++ /dev/null @@ -1,32 +0,0 @@ -#* - * Examples of how to use control statements - *# - -if 1 { - say "if 1"; -} - -ifnot 0 == 1 { - say "ifnot 0 == 1"; -} - -# Calculate 10! - -my n = 10, fac = 0; - -while n > 1 { - ifnot fac { - fac = 1; - } - say fac = (fac * n); - decr n; -} - -# Count up to 10 - -n = 0; - -until n == 10 { - say incr n; -} - diff --git a/examples/expressions.fy b/examples/expressions.fy deleted file mode 100644 index 93a278f..0000000 --- a/examples/expressions.fy +++ /dev/null @@ -1,31 +0,0 @@ -#* - * Simple expression tests - *# - -# Result 10 -assert 10 == say (8 / 2) + 2 * 3; - -# Result 12 -assert 12 == say 2 * (4 + 2); - -# Result 4 -assert 4 == say 2 * (4 / 2); - -# Result 4 -assert 4 == say 2 * (4 / 2); - -# Result 4 -assert 4 == say 2 * (4 / 2); - -# Result 46 -assert 46 == say "12" + "34"; - -# Result 1231 -assert 1231 == say "1234" - "3"; - -# Result 24 -assert "24" == say "2ab" * "12"; - -# Result 5.0 -assert 5 == say "10 bla" / 2; - diff --git a/examples/fork.fy b/examples/fork.fy deleted file mode 100644 index c49c878..0000000 --- a/examples/fork.fy +++ /dev/null @@ -1,14 +0,0 @@ -#* - * Examples of how to use fork - *# - -my pid = fork; - -if pid { - put "I am the parent process and the child has the pid "; - say pid; -} - -ifnot pid { - say "I am the child process"; -} diff --git a/examples/functions.fy b/examples/functions.fy deleted file mode 100644 index 15856a0..0000000 --- a/examples/functions.fy +++ /dev/null @@ -1,25 +0,0 @@ -#* - * Examples of how to use functions - *# - -func foo { - say 1 + a * 3 + b; - - func bar { - say "Hello i am nested"; - } - - bar; # Calling nested -} - -my a = 2, b = 4; # Create global variables -foo; -assert 0 == (defined bar); # bar is not available anymore - -func baz { - say "I am baz"; - undef baz; -} - -baz; # Baz deletes itself -assert 0 == (defined baz); # baz is not available anymore diff --git a/examples/inlinefunctions.fy b/examples/inlinefunctions.fy deleted file mode 100644 index 81848ce..0000000 --- a/examples/inlinefunctions.fy +++ /dev/null @@ -1,20 +0,0 @@ -#* - * Simple builtin function tests - *# - -# Print "-20\n" -assert (neg 20) == (say neg 20); - -# Print "30\n" -assert 30 == (say 10 - neg 20); - -# Print "-30\n" -assert (neg 30) == (say neg neg neg 10 - neg 20); - -# Print "Hello\n" -put "Hello"; -ln; - -# Exit with exit code 0 -exit 10 + 10 - 5 - 15; - diff --git a/examples/io.fy b/examples/io.fy deleted file mode 100644 index fda514d..0000000 --- a/examples/io.fy +++ /dev/null @@ -1,13 +0,0 @@ -#* - * Simple I/O examples. Currently only output is supported. - *# - -# Print out 10 followed by a newline -say 10; - -# Print out 20 without a newline followed -put 20; - -# Print out a newline -ln; - diff --git a/examples/netsted.fype b/examples/netsted.fype deleted file mode 100644 index 2ddf89f..0000000 --- a/examples/netsted.fype +++ /dev/null @@ -1,11 +0,0 @@ -(def (test) - (say "This is test") - (def (test2) - (say "I am in test2" "And test3 will be defined next!") - (def (test3) - (say "Displaying all frames now:") - (show-frames)) - (test3)) - (test2)) -(test) - diff --git a/examples/procedures.fy b/examples/procedures.fy deleted file mode 100644 index cbe2121..0000000 --- a/examples/procedures.fy +++ /dev/null @@ -1,30 +0,0 @@ -#* - * Examples of how to use procedures - *# - -proc foo { - say 1 + a * 3 + b; - my c = 6; -} - -my a = 2, b = 4; - -foo; # Run the procedure. Print out "11\n" -say c; # Print out "6\n"; - -proc bar { - say "I am bar"; - - undef baz; - - proc baz { - say "I am baz"; - } -} - -# Here bar would produce an error because the proc is not yet defined! -# bar; - -bar; # Here the procedure bar will define the procedure baz! -baz; # Now the procedure baz is defined! -bar; # Here the procedure bar will redefine baz again! diff --git a/examples/reverse.fype b/examples/reverse.fype deleted file mode 100644 index a4384b6..0000000 --- a/examples/reverse.fype +++ /dev/null @@ -1,7 +0,0 @@ -(def (reverse x) - (def (my-reverse x y) - (if (null? x) - y - (my-reverse (cdr x) (cons (car x) y)))) - (my-reverse x '())) -(reverse (list 1 2 3)) diff --git a/examples/scopeing.fy b/examples/scopeing.fy deleted file mode 100644 index 434f38f..0000000 --- a/examples/scopeing.fy +++ /dev/null @@ -1,31 +0,0 @@ -#* - * Examples of how to use scopeing - *# - -my foo = 1; - -{ - # Prints out 1 - assert 1 == (put defined foo); - - { - my bar = 2; - - # Prints out 1 - assert 1 == (put defined bar); - - # Prints out all available symbols at - # the current program position. - scope; - } - - # Prints out 0 - assert 0 == (put defined bar); - - my baz = 3; -} - -# Prints out 0 -assert 0 == (say defined bar); - - diff --git a/examples/synonyms.fy b/examples/synonyms.fy deleted file mode 100644 index 0dd30f5..0000000 --- a/examples/synonyms.fy +++ /dev/null @@ -1,37 +0,0 @@ -#* - * Examples of how to use synonyms - *# - -# Create a variable foo, and bar is a synonym for foo -my foo = "foo"; -my bar = \foo; - -# Reset the value of foo -foo = "bar"; - -# The synonym variable should now also set to "bar" -assert "bar" == say bar; - -# Create a new procedure baz -proc baz { - say "I am baz"; -} - -# Make a synonym baz, and undefine baz -my bay = \baz; - -# Should be the num of syms for the same value -assert 2 == syms baz; -assert 2 == syms bay; -undef baz; -assert 1 == syms bay; - -# bay still has a reference of the original procedure baz -bay; # this prints aut "I am baz" - -assert 0 == defined baz; -assert 1 == defined bay; - -# This removes the procedure from memory -undef bay; - diff --git a/examples/types.fy b/examples/types.fy deleted file mode 100644 index 1b9a0ac..0000000 --- a/examples/types.fy +++ /dev/null @@ -1,14 +0,0 @@ -#* - * Examples how to convert types - *# - -assert 1 == say 1; # Integer output - -assert 1 == say double 1; # Double output - -assert 14 == say 1 + string 13; # Implicit type conversion to Integer - -assert 2 == say integer 2.8; # Rounds down to the Integer 2 - -assert say integer double string put say neg 12; # Nonsense but working :) - diff --git a/examples/variables.fy b/examples/variables.fy deleted file mode 100644 index ac619c9..0000000 --- a/examples/variables.fy +++ /dev/null @@ -1,21 +0,0 @@ -#* - * Examples of how to define variables - *# - -# Defines the variables -my foo = 1 + 1; -my bar = 4 - 1, baz = 100 + 1, bay; - -# bay has been initialized with the default value of 0 -say bay; - -# Prints out "5\n" -assert 5 == (say foo + bar); - -# Pritns out "51101\n" -assert 51 == (put baz - 50); -assert 101 == (say baz); - -# Change the value of the variable to 99 and print it out -assert 99 == (baz = 99); -say baz; |
