factor: Fixing postpone: etc in docs

modern-harvey2
Doug Coleman 2017-08-26 17:03:30 -05:00
parent 5a5776068c
commit 2551028f98
11 changed files with 51 additions and 53 deletions

View File

@ -44,7 +44,7 @@ ARTICLE: "cookbook-colon-defs" "Shuffle word and definition cookbook"
{ $code ": sq ( x -- y ) dup * ;" }
"(You could have looked this up yourself by clicking on the " { $link sq } " word itself.)"
$nl
"Note the key elements in a word definition: The colon " { $link postpone: : } " denotes the start of a word definition. The name of the new word and a stack effect declaration must immediately follow. The word definition then continues on until the " { $link postpone: ; } " token signifies the end of the definition. This type of word definition is called a " { $emphasis "compound definition." }
"Note the key elements in a word definition: The colon " { $link postpone: \: } " denotes the start of a word definition. The name of the new word and a stack effect declaration must immediately follow. The word definition then continues on until the " { $link postpone: \; } " token signifies the end of the definition. This type of word definition is called a " { $emphasis "compound definition." }
$nl
"Factor is all about code reuse through short and logical colon definitions. Breaking up a problem into small pieces which are easy to test is called " { $emphasis "factoring." }
$nl
@ -146,7 +146,7 @@ $nl
}
"Typically a source file will refer to words in multiple vocabularies, and they can all be added to the search path in one go:"
{ $code "USING: arrays kernel math ;" }
"New words go into the " { $vocab-link "scratchpad" } " vocabulary by default. You can change this with " { $link postpone: IN: } ":"
"New words go into the " { $vocab-link "scratchpad" } " vocabulary by default. You can change this with " { $link postpone: \IN: } ":"
{ $code
"IN: time-machine"
": time-travel ( when what -- ) frob fizz flap ;"
@ -157,7 +157,7 @@ $nl
": accelerate ( -- ) accelerator on ;"
": particles ( what -- ) [ (particles) ] each ;"
}
"You would have to place the first definition after the two others for the parser to accept the file. If you have a set of mutually recursive words, you can use " { $link postpone: DEFER: } "."
"You would have to place the first definition after the two others for the parser to accept the file. If you have a set of mutually recursive words, you can use " { $link postpone: \DEFER: } "."
{ $references
{ }
"word-search"
@ -173,7 +173,7 @@ ARTICLE: "cookbook-application" "Application cookbook"
""
"MAIN: play-life"
}
"See " { $link postpone: MAIN: } " for details. The " { $link run } " word loads a vocabulary if necessary, and calls its main entry point; try the following, it's fun:"
"See " { $link postpone: \MAIN: } " for details. The " { $link run } " word loads a vocabulary if necessary, and calls its main entry point; try the following, it's fun:"
{ $code "\"tetris\" run" }
"Factor can deploy stand-alone executables; they do not have any external dependencies and consist entirely of compiled native machine code:"
{ $code "\"tetris\" deploy-tool" }

View File

@ -34,7 +34,7 @@ $nl
"IN: palindrome"
}
$nl
"Notice that the file ends with an " { $link postpone: IN: } " form telling Factor that all definitions in this source file should go into the " { $snippet "palindrome" } " vocabulary using the " { $link postpone: IN: } " word. We will be adding new definitions after the " { $link postpone: IN: } " form."
"Notice that the file ends with an " { $link postpone: \IN: } " form telling Factor that all definitions in this source file should go into the " { $snippet "palindrome" } " vocabulary using the " { $link postpone: \IN: } " word. We will be adding new definitions after the " { $link postpone: \IN: } " form."
$nl
"In order to be able to call the words defined in the " { $snippet "palindrome" } " vocabulary, you need to issue the following command in the listener:"
{ $code "USE: palindrome" }
@ -42,7 +42,7 @@ $nl
"Now, we will be making some additions to the file. Since the file was loaded by the scaffold tool in the previous step, you need to tell Factor to reload it if it changes. Factor has a handy feature for this; pressing " { $command tool "common" refresh-all } " in the listener window will reload any changed source files. You can also force a single vocabulary to reload, in case the refresh feature does not pick up changes from disk:"
{ $code "\"palindrome\" reload" }
$nl
"We will now write our first word using " { $link postpone: : } ". This word will test if a string is a palindrome; it will take a string as input, and give back a boolean as output. We will call this word " { $snippet "palindrome?" } ", following a naming convention that words returning booleans have names ending with " { $snippet "?" } "."
"We will now write our first word using " { $link postpone: \: } ". This word will test if a string is a palindrome; it will take a string as input, and give back a boolean as output. We will call this word " { $snippet "palindrome?" } ", following a naming convention that words returning booleans have names ending with " { $snippet "?" } "."
$nl
"Recall that a string is a palindrome if it is spelled the same forwards or backwards; that is, if the string is equal to its reverse. We can express this in Factor as follows:"
{ $code ": palindrome? ( string -- ? ) dup reverse = ;" }

View File

@ -9,9 +9,9 @@ SYNTAX: :>
in-lambda? get [ :>-outside-lambda-error ] unless
scan-token parse-def suffix! ;
SYNTAX: |[ parse-lambda append! ;
SYNTAX: \|[ parse-lambda append! ;
SYNTAX: let[ parse-let append! ;
SYNTAX: \let[ parse-let append! ;
SYNTAX: \:: (::) define-declared ;

View File

@ -7,7 +7,7 @@ IN: prettyprint.stylesheet
<PRIVATE
{ postpone: USING: postpone: USE: postpone: IN: }
{ postpone: \USING: postpone: \USE: postpone: \IN: }
[
{ { foreground color: gray35 } }
"word-style" set-word-prop

View File

@ -113,8 +113,8 @@ TUPLE: slides < book ;
: strip-tease ( data -- seq )
first3 2 over length [a,b] [ head 3array ] with with with map ;
SYNTAX: \STRIP-TEASE:
parse-definition strip-tease append! ;
SYNTAX: \strip-tease{
\ } [ strip-tease ] parse-literal ;
\ slides H{
{ T{ button-down } [ request-focus ] }

View File

@ -28,7 +28,7 @@ CONSTANT: galois-slides
{ $slide "Vocabularies"
"Vocabularies: named sets of words"
{ $link "vocab-index" }
{ { $link postpone: USING: } " loads dependencies" }
{ { $link postpone: \USING: } " loads dependencies" }
"Source, docs, tests in one place"
}
{ $slide "Interactive development"
@ -137,7 +137,7 @@ CONSTANT: galois-slides
{ $code "\"ababbc\" R/ [ab]+c/ matches? ." }
}
{ $slide "Example: memoization"
{ "Memoization with " { $link postpone: MEMO: } }
{ "Memoization with " { $link postpone: \MEMO: } }
{ $code
": fib ( m -- n )"
" dup 1 > ["
@ -147,7 +147,7 @@ CONSTANT: galois-slides
"Very slow! Let's profile it..."
}
{ $slide "Example: memoization"
{ "Let's use " { $link postpone: : } " instead of " { $link postpone: MEMO: } }
{ "Let's use " { $link postpone: \: } " instead of " { $link postpone: \MEMO: } }
{ $code
"MEMO: fib ( m -- n )"
" dup 1 > ["
@ -157,10 +157,10 @@ CONSTANT: galois-slides
"Much faster"
}
{ $slide "Meta-circularity"
{ { $link postpone: MEMO: } " is just a library word" }
{ "But so is " { $link postpone: : } }
{ { $link postpone: \MEMO: } " is just a library word" }
{ "But so is " { $link postpone: \: } }
"Factor's parser is written in Factor"
{ "All syntax is just parsing words: " { $link postpone: [ } ", " { $link postpone: " } }
{ "All syntax is just parsing words: " { $link postpone: \[ } ", " { $link postpone: \" } }
}
{ $slide "Extensible syntax, DSLs"
"Most parsing words fall in one of two categories"
@ -169,7 +169,7 @@ CONSTANT: galois-slides
"Some parsing words are more complicated"
}
{ $slide "Example: printf"
{ { $link postpone: EBNF: } ": a complex parsing word" }
{ { $link postpone: \EBNF: } ": a complex parsing word" }
"Implements a custom syntax for expressing parsers: like OMeta!"
{ "Example: " { $vocab-link "printf-example" } }
{ $code "\"vegan\" \"cheese\" \"%s is not %s\\n\" printf" }
@ -188,10 +188,10 @@ CONSTANT: galois-slides
"Influenced by Scheme and Lisp"
}
{ $slide "Locals and lexical scope"
{ "Define lambda words with " { $link postpone: :: } }
{ "Establish bindings with " { $link postpone: let[ } " and " { $snippet "let[*" } }
{ "Define lambda words with " { $link postpone: \:: } }
{ "Establish bindings with " { $link postpone: \let[ } " and " { $snippet "let[*" } }
"Mutable bindings with correct semantics"
{ "Named inputs for quotations with " { $link postpone: |[ } }
{ "Named inputs for quotations with " { $link postpone: \|[ } }
"Full closures"
}
{ $slide "Locals and lexical scope"
@ -219,7 +219,7 @@ CONSTANT: galois-slides
"In the base image, only 59 words out of 13,000 use locals"
}
{ $slide "More about partial application"
{ { $link postpone: '[ } " is \"fry syntax\"" }
{ { $link postpone: \'[ } " is \"fry syntax\"" }
{ $code "'[ _ + ] == [ + ] curry" }
{ $code "'[ @ t ] == [ t ] compose" }
{ $code "'[ _ nth @ ] == [ [ nth ] curry ] dip compose" }

View File

@ -271,10 +271,10 @@ CONSTANT: google-slides
"Influenced by Scheme and Lisp"
}
{ $slide "Locals and lexical scope"
{ "Define lambda words with " { $link postpone: :: } }
{ "Establish bindings with " { $link postpone: let[ } " and " { $snippet "let[*" } }
{ "Define lambda words with " { $link postpone: \:: } }
{ "Establish bindings with " { $link postpone: \let[ } " and " { $snippet "let[*" } }
"Mutable bindings with correct semantics"
{ "Named inputs for quotations with " { $link postpone: |[ } }
{ "Named inputs for quotations with " { $link postpone: \|[ } }
"Full closures"
}
{ $slide "Locals and lexical scope"
@ -296,11 +296,11 @@ CONSTANT: google-slides
"Libraries can define new parsing words"
}
{ $slide "The parser"
{ "Example: URLs define a " { $link postpone: URL" } " word" }
{ "Example: URLs define a " { $link postpone: \URL" } " word" }
{ $code "URL\" http://paste.factorcode.org/paste?id=81\"" }
}
{ $slide "Example: memoization"
{ "Memoization with " { $link postpone: MEMO: } }
{ "Memoization with " { $link postpone: \MEMO: } }
{ $code
": fib ( m -- n )"
" dup 1 > ["
@ -310,7 +310,7 @@ CONSTANT: google-slides
"Very slow! Let's profile it..."
}
{ $slide "Example: memoization"
{ "Let's use " { $link postpone: : } " instead of " { $link postpone: MEMO: } }
{ "Let's use " { $link postpone: \: } " instead of " { $link postpone: \MEMO: } }
{ $code
"MEMO: fib ( m -- n )"
" dup 1 > ["
@ -320,10 +320,10 @@ CONSTANT: google-slides
"Much faster"
}
{ $slide "Meta-circularity"
{ { $link postpone: MEMO: } " is just a library word" }
{ "But so is " { $link postpone: : } }
{ { $link postpone: \MEMO: } " is just a library word" }
{ "But so is " { $link postpone: \: } }
"Factor's parser is written in Factor"
{ "All syntax is just parsing words: " { $link postpone: [ } ", " { $link postpone: " } }
{ "All syntax is just parsing words: " { $link postpone: \[ } ", " { $link postpone: \" } }
}
{ $slide "Extensible syntax, DSLs"
"Most parsing words fall in one of two categories"
@ -332,7 +332,7 @@ CONSTANT: google-slides
"Some parsing words are more complicated"
}
{ $slide "Parser expression grammars"
{ { $link postpone: EBNF: } ": a complex parsing word" }
{ { $link postpone: \EBNF: } ": a complex parsing word" }
"Implements a custom syntax for expressing parsers"
{ "Example: " { $vocab-link "printf-example" } }
{ $code "\"vegan\" \"cheese\" \"%s is not %s\\n\" printf" }
@ -437,7 +437,7 @@ CONSTANT: google-slides
}
{ $slide "Compiler: escape analysis"
"We identify allocations for tuples which are never returned or passed to other words (except slot access)"
{ "Partial application with " { $link postpone: '[ } }
{ "Partial application with " { $link postpone: \'[ } }
"Complex numbers"
}
{ $slide "Compiler: escape analysis"

View File

@ -77,7 +77,7 @@ CONSTANT: minneapolis-slides
"C: <rectangle> rectangle"
}
}
STRIP-TEASE:
strip-tease{
$slide "An example"
{ $code
"USE: math.constants"
@ -88,7 +88,7 @@ CONSTANT: minneapolis-slides
" dup rectangle-width"
" swap rectangle-height * ;"
}
;
}
{ $slide "An example"
{ $code "10 <square> area ." }
@ -110,10 +110,10 @@ CONSTANT: minneapolis-slides
"Let's profile it!"
}
{ $slide "Memoization"
{ { $link postpone: : } " is just another word" }
{ { $link postpone: \: } " is just another word" }
"What if we could define a word which caches its results?"
{ "The " { $vocab-link "memoize" } " library provides such a feature" }
{ "Just change " { $link postpone: : } " to " { $link postpone: MEMO: } }
{ "Just change " { $link postpone: \: } " to " { $link postpone: \MEMO: } }
}
{ $slide "Memoization"
{ $code

View File

@ -53,7 +53,7 @@ CONSTANT: otug-slides
{ $slide "Constructing quotations"
{ "Suppose we want a " { $snippet "remove-comments*" } " word" }
{ $code ": remove-comments* ( lines string -- lines' )" " [ ??? head? ] reject ;" }
{ "We use " { $link postpone: '[ } " instead of " { $link postpone: [ } }
{ "We use " { $link postpone: \'[ } " instead of " { $link postpone: \[ } }
{ "Create “holes” with " { $link _ } }
"Holes filled in left to right when quotation pushed on the stack"
}

View File

@ -78,7 +78,7 @@ CONSTANT: tc-lisp-slides
}
{ $slide "Object system"
"Based on CLOS"
{ "We define generic words that operate on the top of the stack with " { $link postpone: GENERIC: } " or on an implicit parameter with " { $link postpone: HOOK: } }
{ "We define generic words that operate on the top of the stack with " { $link postpone: \GENERIC: } " or on an implicit parameter with " { $link postpone: \HOOK: } }
}
{ $slide "Object system example: shape protocol"
"In ~/factor/work/shapes/shapes.factor"
@ -433,11 +433,9 @@ end: return;
{ $code ": glue ( left right middle -- seq' )
swap 3append ;"
}
{ $code HEREDOC: xyz
"a" "b" "c" 3append
{ $code [[ "a" "b" "c" 3append
"a" """""""" surround
"a" "b" ", " glue
xyz
"a" "b" ", " glue]]
}
}
{ $slide "C FFI demo"

View File

@ -157,7 +157,7 @@ CONSTANT: vpri-slides
{ $code "float-array{ 3.14 7.6 10.3 }" }
}
{ $slide "Example: memoization"
{ "Memoization with " { $link postpone: MEMO: } }
{ "Memoization with " { $link postpone: \MEMO: } }
{ $code
": fib ( m -- n )"
" dup 1 > ["
@ -167,7 +167,7 @@ CONSTANT: vpri-slides
"Very slow! Let's profile it..."
}
{ $slide "Example: memoization"
{ "Let's use " { $link postpone: : } " instead of " { $link postpone: MEMO: } }
{ "Let's use " { $link postpone: \: } " instead of " { $link postpone: \MEMO: } }
{ $code
"MEMO: fib ( m -- n )"
" dup 1 > ["
@ -177,10 +177,10 @@ CONSTANT: vpri-slides
"Much faster"
}
{ $slide "Meta-circularity"
{ { $link postpone: MEMO: } " is just a library word" }
{ "But so is " { $link postpone: : } }
{ { $link postpone: \MEMO: } " is just a library word" }
{ "But so is " { $link postpone: \: } }
"Factor's parser is written in Factor"
{ "All syntax is just parsing words: " { $link postpone: [ } ", " { $link postpone: " } }
{ "All syntax is just parsing words: " { $link postpone: \[ } ", " { $link postpone: \" } }
}
{ $slide "Extensible syntax, DSLs"
"Most parsing words fall in one of two categories"
@ -189,7 +189,7 @@ CONSTANT: vpri-slides
"Some parsing words are more complicated"
}
{ $slide "Example: printf"
{ { $link postpone: EBNF: } ": a complex parsing word" }
{ { $link postpone: \EBNF: } ": a complex parsing word" }
"Implements a custom syntax for expressing parsers: like OMeta!"
{ "Example: " { $vocab-link "printf-example" } }
{ $code "\"vegan\" \"cheese\" \"%s is not %s\\n\" printf" }
@ -208,10 +208,10 @@ CONSTANT: vpri-slides
"Influenced by Scheme and Lisp"
}
{ $slide "Locals and lexical scope"
{ "Define lambda words with " { $link postpone: :: } }
{ "Establish bindings with " { $link postpone: let[ } " and " { $snippet "let[*" } }
{ "Define lambda words with " { $link postpone: \:: } }
{ "Establish bindings with " { $link postpone: \let[ } " and " { $snippet "let[*" } }
"Mutable bindings with correct semantics"
{ "Named inputs for quotations with " { $link postpone: |[ } }
{ "Named inputs for quotations with " { $link postpone: \|[ } }
"Full closures"
}
{ $slide "Locals and lexical scope"
@ -241,7 +241,7 @@ CONSTANT: vpri-slides
"In the base image, only 59 words out of 13,000 use locals"
}
{ $slide "More about partial application"
{ { $link postpone: '[ } " is \"fry syntax\"" }
{ { $link postpone: \'[ } " is \"fry syntax\"" }
{ $code "'[ _ + ] == [ + ] curry" }
{ $code "'[ @ t ] == [ t ] compose" }
{ $code "'[ _ nth @ ] == [ [ nth ] curry ] dip compose" }