langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1 @@
f ()

View file

@ -0,0 +1 @@
f 1 2 3

View file

@ -0,0 +1 @@
val f : ?a:int -> int -> unit

View file

@ -0,0 +1,2 @@
f 10
f ~a:6 10

View file

@ -0,0 +1,2 @@
g ()
g ~b:1.0 ()

View file

@ -0,0 +1 @@
f ~arg:3

View file

@ -0,0 +1,2 @@
let arg = 3 in
f ~arg

View file

@ -0,0 +1 @@
(* TODO *)

View file

@ -0,0 +1,4 @@
let ret = f ()
let a, b, c = f () (* if there are several returned values given as a tuple *)
let _ = f () (* if we want to ignore the returned value *)
let v, _ = f () (* if we want to ignore one of the returned value *)

View file

@ -0,0 +1,5 @@
f(); \\ zero arguments
sin(Pi/2); \\ fixed number of arguments
Str("gg", 1, "hh"); \\ variable number of arguments
(x->x^2)(3); \\ first-class
x = sin(0); \\ get function value

View file

@ -0,0 +1,8 @@
foo # as list operator
foo() # as function
foo.() # as function, explicit postfix form
$ref() # as object invocation
$ref.() # as object invocation, explicit postfix
&foo() # as object invocation
&foo.() # as object invocation, explicit postfix
::($name)() # as symbolic ref

View file

@ -0,0 +1 @@
my $result = somefunc(1,2,3) + 2;

View file

@ -0,0 +1,13 @@
foo 1 # as list operator
foo(1) # as named function
foo.(1) # as named function, explicit postfix
$ref(1) # as object invocation (must be hard ref)
$ref.(1) # as object invocation, explicit postfix
1.$foo # as pseudo-method meaning $foo(1) (hard ref only)
1.$foo() # as pseudo-method meaning $foo(1) (hard ref only)
1.&foo # as pseudo-method meaning &foo(1) (is hard foo)
1.&foo() # as pseudo-method meaning &foo(1) (is hard foo)
1.foo # as method via dispatcher
1.foo() # as method via dispatcher
1."$name"() # as method via dispatcher, symbolic
+1 # as operator to prefix:<+> function

View file

@ -0,0 +1,13 @@
foo 1,2 # as list operator
foo(1,2) # as named function
foo.(1,2) # as named function, explicit postfix
$ref(1,2) # as object invocation (must be hard ref)
$ref.(1,2) # as object invocation, explicit postfix
1.$foo: 2 # as pseudo-method meaning $foo(1,2) (hard ref only)
1.$foo(2) # as pseudo-method meaning $foo(1,2) (hard ref only)
1.&foo: 2 # as pseudo-method meaning &foo(1,2) (is hard foo)
1.&foo(2) # as pseudo-method meaning &foo(1,2) (is hard foo)
1.foo: 2 # as method via dispatcher
1.foo(2) # as method via dispatcher
1."$name"(2) # as method via dispatcher, symbolic
1 + 2 # as operator to infix:<+> function

View file

@ -0,0 +1,13 @@
foo @args # as list operator
foo(@args) # as named function
foo.(@args) # as named function, explicit postfix
$ref(@args) # as object invocation (must be hard ref)
$ref.(@args) # as object invocation, explicit postfix
1.$foo: @args # as pseudo-method meaning $foo(1,@args) (hard ref)
1.$foo(@args) # as pseudo-method meaning $foo(1,@args) (hard ref)
1.&foo: @args # as pseudo-method meaning &foo(1,@args)
1.&foo(@args) # as pseudo-method meaning &foo(1,@args)
1.foo: @args # as method via dispatcher
1.foo(@args) # as method via dispatcher
1."$name"(@args) # as method via dispatcher, symbolic
@args X @blargs # as list infix operator to infix:<X>

View file

@ -0,0 +1,2 @@
my @args = 1,2,3;
foo(|@args); # equivalent to foo(1,2,3)

View file

@ -0,0 +1,2 @@
foo :a, :b(4), :!c, d => "stuff"
foo(:a, :b(4), :!c, d => "stuff")

View file

@ -0,0 +1 @@
1 + 1 :a :b(4) :!c :d("stuff") # calls infix:<+>(1,1,:a, :b(4), :!c, d => "stuff")

View file

@ -0,0 +1 @@
foo(); bar(); baz(); # evaluate for side effects

View file

@ -0,0 +1 @@
1 / find-a-func(1,2,3)(4,5,6) ** 2;

View file

@ -0,0 +1,2 @@
sayhello # Call a function in statement context with no arguments
multiply 3 4 # Call a function in statement context with two arguments

View file

@ -0,0 +1,12 @@
10 REM functions cannot be called in statement context
20 PRINT FN a(5): REM The function is used in first class context. Arguments are not named
30 PRINT FN b(): REM Here we call a function that has no arguments
40 REM subroutines cannot be passed parameters, however variables are global
50 LET n=1: REM This variable will be visible to the called subroutine
60 GO SUB 1000: REM subroutines are called by line number and do not have names
70 REM subroutines do not return a value, but we can see any variables it defined
80 REM subroutines cannot be used in first class context
90 REM builtin functions are used in first class context, and do not need the FN keyword prefix
100 PRINT SIN(50): REM here we pass a parameter to a builtin function
110 PRINT RND(): REM here we use a builtin function without parameters
120 RANDOMIZE: REM statements are not functions and cannot be used in first class context.