Call a function: Difference between revisions
Content added Content deleted
m (→{{header|Factor}}: fixing formatting) |
m (→{{header|Factor}}: minor edits for clarity) |
||
Line 980: | Line 980: | ||
* Variable arguments are achieved by defining a word that takes an integer, and operates on that many items at the top of the stack: |
* Variable arguments are achieved by defining a word that takes an integer, and operates on that many items at the top of the stack: |
||
<lang Factor>"a" "b" "c" 3 narray |
<lang Factor>"a" "b" "c" 3 narray |
||
! { "a" "b" "c" }</lang> |
|||
* The named arguments idiom is to define a tuple, set its slots, and pass it to a word: |
* The named arguments idiom is to define a tuple, set its slots, and pass it to a word: |
||
Line 994: | Line 995: | ||
* First-class context: this pushes a word to the stack. Use execute to evaluate. |
* First-class context: this pushes a word to the stack. Use execute to evaluate. |
||
<lang Factor>\ foo</lang> |
<lang Factor>\ foo</lang> |
||
Additionally, you can put words directly inside sequences and quotations: |
Additionally, you can put words directly inside sequences and quotations for deferred execution: |
||
<lang Factor>{ foo } [ foo ]</lang> |
<lang Factor>{ foo } [ foo ]</lang> |
||
Line 1,003: | Line 1,004: | ||
<lang Factor>\ foo primitive?</lang> |
<lang Factor>\ foo primitive?</lang> |
||
* Factor makes no distinction between subroutines and functions. Presumably, a subroutine is just a word which puts nothing on the stack. |
* Factor makes no distinction between subroutines and functions. Presumably, a subroutine is just a word which puts nothing on the stack. However, if one thinks of words as taking a stack and returning a stack, then there are no subroutines in Factor. |
||
* By value or by reference is irrelevant; Factor is not applicative. |
* By value or by reference is irrelevant; Factor is not applicative. |