]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/help/cookbook/cookbook.factor
add mention of run-file to scripting cookbook
[factor.git] / basis / help / cookbook / cookbook.factor
index 724c0588257b82be2711e18a37f67950b49c9851..e4b753a961e7203fe9051870e5eb1506cf505cc7 100644 (file)
@@ -16,12 +16,12 @@ $nl
 $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
@@ -29,7 +29,6 @@ $nl
     "\"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:" }
@@ -191,6 +190,8 @@ ARTICLE: "cookbook-scripts" "Scripting cookbook"
 $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:"
@@ -199,7 +200,7 @@ $nl
 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
@@ -238,7 +239,7 @@ command-line get [
 { $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