Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -0,0 +1,32 @@
# all functions used are from the standard library
# calling a function with no arguments:
random-int
# calling a function with a fixed number of arguments:
+ 1 2
# calling a function with optional arguments:
# optional arguments are not really possible as such
# generally differently named functions are used:
sort [ 3 2 1 ]
sort-by @len [ "Hello" "World" "Bob" ]
# calling a function with a variable number of arguments:
# generally with a special terminator value, which one depends
# on the function called
concat( 1 2 3 )
[ 1 2 3 ]
set{ :foo :bar :spam }
# calling a function with named arguments: not possible
# using a function in first-class context within an expression
$ @-- @len # $ is "compose", so the function returned is "one less than the length"
# obtaining the return value of a function
# return values are always pushed on the stack, so you don't need anything special
random-int
# discarding the return value of a function
drop random-int
# method call:
local :do { :nuthin @pass }
do!nuthin
!import!fooModule # same as eva!import :fooModule
# arguments are passed by object-identity, like in Python and Lua
# partial application is not possible, due to the fact that
# a function's arity is a property of its behavior and not
# of its definition

View file

@ -0,0 +1,42 @@
'Call a function - Liberty BASIC
'First, function result could not be discarded
' that is, you cannot do "f(x)" as a separate statement
'Calling a function that requires no arguments
res = f() 'brackets required
'Calling a function with a fixed number of arguments
res = g(x)
res = h(x,y)
'Calling a function with optional arguments
'impossible for user-defined functions
'Some build-in functions ex. INSTR and MID$ could be called with last argument omitted
'Calling a function with a variable number of arguments
'impossible
'Calling a function with named arguments
'impossible
'Using a function in statement context
'impossible (see starting notice)
'Using a function in first-class context within an expression
'impossible
'Obtaining the return value of a function
res = g(x)
'Distinguishing built-in functions and user-defined functions
'I would say impossible. Though built-in functions could be EVAL'ed,
'while user-defined would not be called (tries address array instead).
'Still cannot distinguish user-defined function from array.
'Distinguishing subroutines and functions
'then defined, subroutines and functions defined with words
'SUB and FUNCTION (case incensitive)
'Then used, function used as expression (with return value),
res = g(x)
'while subroutines called with special keyword CALL and without brackets
call test x, y
'Stating whether arguments are passed by value or by reference
'Variables passed as arguments into functions and subs are passed "by value" by default
'parameters could be passed "by reference" if formal parameter in sub/function definition uses the "byref" specifier
'Then calling a function, you can prevent pass by reference by changing variable to expression
' like x+0, x$+"" or just (x), (x$)
'Is partial application possible and how
'impossible