Factor (programming language): Difference between revisions

Content deleted Content added
Monkbot (talk | contribs)
m Task 18 (cosmetic): eval 14 templates: del empty params (1×);
No edit summary
Line 33:
"hello world" print
<code>print</code> is a word in the <code>io</code> vocabulary that takes a string from the stack and returns nothing. It prints the string to the current output stream (by default, the terminal or the graphical listener).<ref name = "dls" />
 
The [[factorial|factorial function]] <math>n!</math> can be implemented in Factor in the following way:
<syntaxhighlight lang="factor">
: factorial ( n -- n! ) dup 1 > [ [1,b] product ] [ drop 1 ] if
</syntaxhighlight>
 
Not all data has to be passed around only with the stack. [[Lexical scoping|Lexically scoped]] local variables let you store and access [[temporary variable|temporaries]] used within a procedure. [[Dynamic scoping|Dynamically scoped]] variables are used to pass things between procedure calls without using the stack. For example, the current input and output streams are stored in dynamically scoped variables.<ref name="dls" />