Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
25
Task/Call-a-function/Forth/call-a-function.fth
Normal file
25
Task/Call-a-function/Forth/call-a-function.fth
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
a-function \ requiring no arguments
|
||||
a-function \ with a fixed number of arguents
|
||||
a-function \ having optional arguments
|
||||
a-function \ having a variable number of arguments
|
||||
a-function \ having such named arguments as we have in Forth
|
||||
' a-function var ! \ using a function in a first-class context (here: storing it in a variable)
|
||||
a-function \ in which we obtain a function's return value
|
||||
|
||||
\ forth lacks 'statement contenxt'
|
||||
\ forth doesn't distinguish between built-in and user-defined functions
|
||||
\ forth doesn't distinguish between functions and subroutines
|
||||
\ forth doesn't care about by-value or by-reference
|
||||
|
||||
\ partial application is achieved by creating functions and manipulating stacks
|
||||
: curried 0 a-function ;
|
||||
: only-want-third-argument 1 2 rot a-function ;
|
||||
|
||||
\ Realistic example:
|
||||
: move ( delta-x delta-y -- )
|
||||
y +! x +! ;
|
||||
|
||||
: down ( n -- ) 0 swap move ;
|
||||
: up ( n -- ) negate down ;
|
||||
: right ( n -- ) 0 move ;
|
||||
: left ( n -- ) negate right ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue