$nl
"Coming back to the example in the beginning of this article, the following series of steps occurs as the code is evaluated:"
{ $table
- { "Action" "Stack contents" }
+ { { $strong "Action" } { $strong "Stack contents" } }
{ "10 is pushed on the stack." { $snippet "10" } }
- { { "The " { $link sq } " word is executed. It pops one input from the stack - the integer 10 - and squares it, pushing the result." } { $snippet "100" } }
+ { { "The " { $link sq } " word is executed. It pops one input from the stack (the integer 10) and squares it, pushing the result." } { $snippet "100" } }
{ { "5 is pushed on the stack." } { $snippet "100 5" } }
- { { "The " { $link - } " word is executed. It pops two inputs from the stack - the integers 100 and 5 - and subtracts 5 from 100, pushing the result." } { $snippet "95" } }
- { { "The " { $link . } " word is executed. It pops one input from the stack - the integer 95 - and prints it in the listener's output area." } { } }
+ { { "The " { $link - } " word is executed. It pops two inputs from the stack (the integers 100 and 5) and subtracts 5 from 100, pushing the result." } { $snippet "95" } }
+ { { "The " { $link . } " word is executed. It pops one input from the stack (the integer 95) and prints it in the listener's output area." } { } }
}
"Factor supports many other data types:"
{ $code
"\"character strings\""
"{ 1 2 3 }"
"! by the way, this is a comment"
- "#! and so is this"
}
{ $references
{ "Factor's syntax can be extended, the parser can be called reflectively, and the " { $link . } " word is in fact a general facility for turning almost any object into a form which can be parsed back in again. If this interests you, consult the following sections:" }
$nl
"To run a script, simply pass it as an argument to the Factor executable:"
{ $code "./factor cleanup.factor" }
+"To test a script in the listener, you can use " { $link run-file } "."
+$nl
"The script may access command line arguments by inspecting the value of the " { $link command-line } " variable. It can also get its own path from the " { $link script } " variable."
{ $heading "Example: ls" }
"Here is an example implementing a simplified version of the Unix " { $snippet "ls" } " command in Factor:"
io.pathnames tools.files sequences kernel ;
command-line get [
- current-directory get directory.
+ \".\" directory.
] [
dup length 1 = [ first directory. ] [
[ [ nl write \":\" print ] [ directory. ] bi ] each
{ $code "USE: regexp" "save" }
"Now, the " { $snippet "grep.factor" } " script will start up much faster. See " { $link "images" } " for details."
{ $heading "Executable scripts" }
-"It is also possible to make executable scripts. A Factor file can begin with a comment like the following:"
+"It is also possible to make executable scripts. A Factor file can begin with a 'shebang' like the following:"
{ $code "#!/usr/bin/env factor" }
"If the text file is made executable, then it can be run, assuming the " { $snippet "factor" } " binary is in your " { $snippet "$PATH" } "."
{ $references