Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2008-03-11 21:46:44 -05:00
commit 01ec501f83
108 changed files with 446 additions and 400 deletions

View File

@ -84,11 +84,11 @@ HELP: alien>u16-string ( c-ptr -- string )
{ $values { "c-ptr" c-ptr } { "string" string } } { $values { "c-ptr" c-ptr } { "string" string } }
{ $description "Reads a null-terminated UCS-2 string from the specified address." } ; { $description "Reads a null-terminated UCS-2 string from the specified address." } ;
HELP: memory>byte-array ( base len -- string ) HELP: memory>byte-array
{ $values { "base" c-ptr } { "len" "a non-negative integer" } { "byte-array" byte-array } } { $values { "alien" c-ptr } { "len" "a non-negative integer" } { "byte-array" byte-array } }
{ $description "Reads " { $snippet "len" } " bytes starting from " { $snippet "base" } " and stores them in a new byte array." } ; { $description "Reads " { $snippet "len" } " bytes starting from " { $snippet "base" } " and stores them in a new byte array." } ;
HELP: byte-array>memory ( string base -- ) HELP: byte-array>memory
{ $values { "byte-array" byte-array } { "base" c-ptr } } { $values { "byte-array" byte-array } { "base" c-ptr } }
{ $description "Writes a byte array to memory starting from the " { $snippet "base" } " address." } { $description "Writes a byte array to memory starting from the " { $snippet "base" } " address." }
{ $warning "This word is unsafe. Improper use can corrupt memory." } ; { $warning "This word is unsafe. Improper use can corrupt memory." } ;

View File

@ -162,6 +162,7 @@ HELP: assoc-each
{ $description "Applies a quotation to each entry in the assoc." } { $description "Applies a quotation to each entry in the assoc." }
{ $examples { $examples
{ $example { $example
"USING: assocs kernel math prettyprint ;"
"H{ { \"bananas\" 5 } { \"apples\" 42 } { \"pears\" 17 } }" "H{ { \"bananas\" 5 } { \"apples\" 42 } { \"pears\" 17 } }"
"0 swap [ nip + ] assoc-each ." "0 swap [ nip + ] assoc-each ."
"64" "64"

View File

@ -19,7 +19,7 @@ HELP: box>
{ $errors "Throws an error if the box is empty." } ; { $errors "Throws an error if the box is empty." } ;
HELP: ?box HELP: ?box
{ $values { "box" box } { "value" "the value of the box or " { $link f } } { "?" "a boolean" } } { $values { "box" box } { "value/f" "the value of the box or " { $link f } } { "?" "a boolean" } }
{ $description "If the box is full, removes the value from the box and pushes " { $link t } ". If the box is empty pushes " { $snippet "f f" } "." } ; { $description "If the box is full, removes the value from the box and pushes " { $link t } ". If the box is empty pushes " { $snippet "f f" } "." } ;
ARTICLE: "boxes" "Boxes" ARTICLE: "boxes" "Boxes"

View File

@ -6,7 +6,7 @@ IN: byte-vectors
<PRIVATE <PRIVATE
: byte-array>vector ( byte-array capacity -- byte-vector ) : byte-array>vector ( byte-array length -- byte-vector )
byte-vector construct-boa ; inline byte-vector construct-boa ; inline
PRIVATE> PRIVATE>

View File

@ -1,4 +1,4 @@
USING: generic help.markup help.syntax kernel kernel.private USING: help.markup help.syntax kernel kernel.private
namespaces sequences words arrays layouts help effects math namespaces sequences words arrays layouts help effects math
layouts classes.private classes.union classes.mixin layouts classes.private classes.union classes.mixin
classes.predicate ; classes.predicate ;
@ -79,7 +79,7 @@ HELP: class
{ $values { "object" object } { "class" class } } { $values { "object" object } { "class" class } }
{ $description "Outputs an object's canonical class. While an object may be an instance of more than one class, the canonical class is either its built-in class, or if the object is a tuple, its tuple class." } { $description "Outputs an object's canonical class. While an object may be an instance of more than one class, the canonical class is either its built-in class, or if the object is a tuple, its tuple class." }
{ $class-description "The class of all class words. Subclasses include " { $link builtin-class } ", " { $link union-class } ", " { $link mixin-class } ", " { $link predicate-class } " and " { $link tuple-class } "." } { $class-description "The class of all class words. Subclasses include " { $link builtin-class } ", " { $link union-class } ", " { $link mixin-class } ", " { $link predicate-class } " and " { $link tuple-class } "." }
{ $examples { $example "USE: classes" "1.0 class ." "float" } { $example "USE: classes" "TUPLE: point x y z ;\nT{ point f 1 2 3 } class ." "point" } } ; { $examples { $example "USING: classes prettyprint ;" "1.0 class ." "float" } { $example "USING: classes prettyprint ;" "TUPLE: point x y z ;\nT{ point f 1 2 3 } class ." "point" } } ;
HELP: classes HELP: classes
{ $values { "seq" "a sequence of class words" } } { $values { "seq" "a sequence of class words" } }
@ -89,14 +89,14 @@ HELP: builtin-class
{ $class-description "The class of built-in classes." } { $class-description "The class of built-in classes." }
{ $examples { $examples
"The class of arrays is a built-in class:" "The class of arrays is a built-in class:"
{ $example "USE: classes" "array builtin-class? ." "t" } { $example "USING: arrays classes prettyprint ;" "array builtin-class? ." "t" }
"However, a literal array is not a built-in class; it is not even a class:" "However, an instance of the array class is not a built-in class; it is not even a class:"
{ $example "USE: classes" "{ 1 2 3 } builtin-class? ." "f" } { $example "USING: classes prettyprint ;" "{ 1 2 3 } builtin-class? ." "f" }
} ; } ;
HELP: tuple-class HELP: tuple-class
{ $class-description "The class of tuple class words." } { $class-description "The class of tuple class words." }
{ $examples { $example "USE: classes\nTUPLE: name title first last ;\nname tuple-class? ." "t" } } ; { $examples { $example "USING: classes prettyprint ;" "TUPLE: name title first last ;" "name tuple-class? ." "t" } } ;
HELP: typemap HELP: typemap
{ $var-description "Hashtable mapping unions to class words, used to implement " { $link class-and } " and " { $link class-or } "." } ; { $var-description "Hashtable mapping unions to class words, used to implement " { $link class-and } " and " { $link class-or } "." } ;
@ -167,7 +167,7 @@ HELP: types
HELP: class-empty? HELP: class-empty?
{ $values { "class" "a class" } { "?" "a boolean" } } { $values { "class" "a class" } { "?" "a boolean" } }
{ $description "Tests if a class is a union class with no members." } { $description "Tests if a class is a union class with no members." }
{ $examples { $example "USE: classes" "null class-empty? ." "t" } } ; { $examples { $example "USING: classes kernel prettyprint ;" "null class-empty? ." "t" } } ;
HELP: (class<) HELP: (class<)
{ $values { "class1" "a class" } { "class2" "a class" } { "?" "a boolean" } } { $values { "class1" "a class" } { "class2" "a class" } { "?" "a boolean" } }
@ -182,8 +182,6 @@ HELP: sort-classes
{ $values { "seq" "a sequence of class" } { "newseq" "a new seqence of classes" } } { $values { "seq" "a sequence of class" } { "newseq" "a new seqence of classes" } }
{ $description "Outputs a topological sort of a sequence of classes. Larger classes come before their subclasses." } ; { $description "Outputs a topological sort of a sequence of classes. Larger classes come before their subclasses." } ;
{ sort-classes methods order } related-words
HELP: lookup-union HELP: lookup-union
{ $values { "classes" "a hashtable mapping class words to themselves" } { "class" class } } { $values { "classes" "a hashtable mapping class words to themselves" } { "class" class } }
{ $description "Given a set of classes represented as a hashtable with equal keys and values, looks up a previously-defined union class having those members. If no union is defined, outputs " { $link object } "." } ; { $description "Given a set of classes represented as a hashtable with equal keys and values, looks up a previously-defined union class having those members. If no union is defined, outputs " { $link object } "." } ;

View File

@ -82,7 +82,7 @@ HELP: with-datastack
{ $values { "stack" sequence } { "quot" quotation } { "newstack" sequence } } { $values { "stack" sequence } { "quot" quotation } { "newstack" sequence } }
{ $description "Executes the quotation with the given data stack contents, and outputs the new data stack after the word returns. The input sequence is not modified. Does not affect the data stack in surrounding code, other than consuming the two inputs and pushing the output." } { $description "Executes the quotation with the given data stack contents, and outputs the new data stack after the word returns. The input sequence is not modified. Does not affect the data stack in surrounding code, other than consuming the two inputs and pushing the output." }
{ $examples { $examples
{ $example "{ 3 7 } [ + ] with-datastack ." "{ 10 }" } { $example "USING: combinators math prettyprint ;" "{ 3 7 } [ + ] with-datastack ." "{ 10 }" }
} ; } ;
HELP: recursive-hashcode HELP: recursive-hashcode

View File

@ -24,8 +24,8 @@ HELP: compiler-error.
{ $description "Prints a compiler error to the " { $link stdio } " stream." } ; { $description "Prints a compiler error to the " { $link stdio } " stream." } ;
HELP: compiler-errors. HELP: compiler-errors.
{ $values { "errors" "an assoc mapping words to errors" } } { $values { "type" symbol } }
{ $description "Prints a set of compiler errors to the " { $link stdio } " stream." } ; { $description "Prints compiler errors to the " { $link stdio } " stream. The type parameter is one of " { $link +error+ } ", " { $link +warning+ } ", or " { $link +linkage+ } "." } ;
HELP: :errors HELP: :errors
{ $description "Prints all serious compiler errors from the most recent compile to the " { $link stdio } " stream." } ; { $description "Prints all serious compiler errors from the most recent compile to the " { $link stdio } " stream." } ;

View File

@ -63,7 +63,7 @@ HELP: modify-code-heap ( alist -- )
{ $notes "This word is called at the end of " { $link with-compilation-unit } "." } ; { $notes "This word is called at the end of " { $link with-compilation-unit } "." } ;
HELP: compile HELP: compile
{ $values { "seq" "a sequence of words" } } { $values { "words" "a sequence of words" } }
{ $description "Compiles a set of words." } ; { $description "Compiles a set of words." } ;
HELP: compile-call HELP: compile-call

View File

@ -150,7 +150,7 @@ HELP: recover
{ $description "Calls the " { $snippet "try" } " quotation. If an exception is thrown in the dynamic extent of the " { $snippet "try" } " quotation, restores the data stack and calls the " { $snippet "recovery" } " quotation to handle the error." } ; { $description "Calls the " { $snippet "try" } " quotation. If an exception is thrown in the dynamic extent of the " { $snippet "try" } " quotation, restores the data stack and calls the " { $snippet "recovery" } " quotation to handle the error." } ;
HELP: ignore-errors HELP: ignore-errors
{ $values { "try" quotation } } { $values { "quot" quotation } }
{ $description "Calls the quotation. If an exception is thrown in the dynamic extent of the quotation, restores the data stack and returns." } ; { $description "Calls the quotation. If an exception is thrown in the dynamic extent of the quotation, restores the data stack and returns." } ;
HELP: rethrow HELP: rethrow

View File

@ -58,7 +58,7 @@ HELP: effect>string
{ $values { "effect" effect } { "string" string } } { $values { "effect" effect } { "string" string } }
{ $description "Turns a stack effect object into a string mnemonic." } { $description "Turns a stack effect object into a string mnemonic." }
{ $examples { $examples
{ $example "USE: effects" "1 2 <effect> effect>string print" "( object -- object object )" } { $example "USING: effects io ;" "1 2 <effect> effect>string print" "( object -- object object )" }
} ; } ;
HELP: stack-effect HELP: stack-effect

View File

@ -57,7 +57,7 @@ HELP: generate
{ $description "Generates machine code for " { $snippet "label" } " from " { $snippet "node" } ". The value of " { $snippet "word" } " is retained for debugging purposes; it is the word which will appear in a call stack trace if this compiled code block throws an error when run." } ; { $description "Generates machine code for " { $snippet "label" } " from " { $snippet "node" } ". The value of " { $snippet "word" } " is retained for debugging purposes; it is the word which will appear in a call stack trace if this compiled code block throws an error when run." } ;
HELP: word-dataflow HELP: word-dataflow
{ $values { "word" word } { "effect" effect } { "dependencies" sequence } { "dataflow" "a dataflow graph" } } { $values { "word" word } { "effect" effect } { "dataflow" "a dataflow graph" } }
{ $description "Outputs the dataflow graph of a word, taking specializers into account (see " { $link "specializers" } ")." } ; { $description "Outputs the dataflow graph of a word, taking specializers into account (see " { $link "specializers" } ")." } ;
HELP: define-intrinsics HELP: define-intrinsics

View File

@ -1,6 +1,6 @@
USING: help.markup help.syntax generic.math generic.standard USING: help.markup help.syntax words classes definitions kernel
words classes definitions kernel alien combinators sequences alien sequences math quotations generic.standard generic.math
math quotations ; combinators ;
IN: generic IN: generic
ARTICLE: "method-order" "Method precedence" ARTICLE: "method-order" "Method precedence"
@ -33,8 +33,6 @@ $nl
"New generic words can be defined:" "New generic words can be defined:"
{ $subsection define-generic } { $subsection define-generic }
{ $subsection define-simple-generic } { $subsection define-simple-generic }
"Methods are tuples:"
{ $subsection <method> }
"Methods can be added to existing generic words:" "Methods can be added to existing generic words:"
{ $subsection define-method } { $subsection define-method }
"Method definitions can be looked up:" "Method definitions can be looked up:"
@ -42,8 +40,10 @@ $nl
{ $subsection methods } { $subsection methods }
"A generic word contains methods; the list of methods specializing on a class can also be obtained:" "A generic word contains methods; the list of methods specializing on a class can also be obtained:"
{ $subsection implementors } { $subsection implementors }
"Low-level words which rebuilds the generic word after methods are added or removed, or the method combination is changed:" "Low-level word which rebuilds the generic word after methods are added or removed, or the method combination is changed:"
{ $subsection make-generic } { $subsection make-generic }
"Low-level method constructor:"
{ $subsection <method> }
"A " { $emphasis "method specifier" } " refers to a method and implements the " { $link "definition-protocol" } ":" "A " { $emphasis "method specifier" } " refers to a method and implements the " { $link "definition-protocol" } ":"
{ $subsection method-spec } ; { $subsection method-spec } ;
@ -126,7 +126,7 @@ HELP: method
{ method define-method POSTPONE: M: } related-words { method define-method POSTPONE: M: } related-words
HELP: <method> HELP: <method>
{ $values { "def" "a quotation" } { "method" "a new method definition" } } { $values { "quot" quotation } { "class" class } { "generic" generic } { "method" "a new method definition" } }
{ $description "Creates a new method." } ; { $description "Creates a new method." } ;
HELP: methods HELP: methods
@ -148,7 +148,7 @@ HELP: with-methods
$low-level-note ; $low-level-note ;
HELP: define-method HELP: define-method
{ $values { "method" quotation } { "class" class } { "generic" generic } } { $values { "quot" quotation } { "class" class } { "generic" generic } }
{ $description "Defines a method. This is the runtime equivalent of " { $link POSTPONE: M: } "." } ; { $description "Defines a method. This is the runtime equivalent of " { $link POSTPONE: M: } "." } ;
HELP: implementors HELP: implementors
@ -158,3 +158,5 @@ HELP: implementors
HELP: forget-methods HELP: forget-methods
{ $values { "class" class } } { $values { "class" class } }
{ $description "Remove all method definitions which specialize on the class." } ; { $description "Remove all method definitions which specialize on the class." } ;
{ sort-classes methods order } related-words

View File

@ -74,7 +74,7 @@ M: method-body stack-effect
"method-def" set "method-def" set
] H{ } make-assoc ; ] H{ } make-assoc ;
: <method> ( quot class generic -- word ) : <method> ( quot class generic -- method )
check-method check-method
[ make-method-def ] 3keep [ make-method-def ] 3keep
[ method-word-props ] 2keep [ method-word-props ] 2keep

View File

@ -1,26 +1,27 @@
USING: kernel generic help.markup help.syntax math classes USING: kernel generic help.markup help.syntax math classes
generic.math ; sequences quotations ;
IN: generic.math
HELP: math-upgrade HELP: math-upgrade
{ $values { "class1" "a class word" } { "class2" "a class word" } { "quot" "a quotation with stack effect " { $snippet "( n n -- n n )" } } } { $values { "class1" class } { "class2" class } { "quot" "a quotation with stack effect " { $snippet "( n n -- n n )" } } }
{ $description "Outputs a quotation for upgrading numberical types. It takes two numbers on the stack, an instance of " { $snippet "class1" } ", and an instance of " { $snippet "class2" } ", and converts the one with the lower priority to the higher priority type." } { $description "Outputs a quotation for upgrading numberical types. It takes two numbers on the stack, an instance of " { $snippet "class1" } ", and an instance of " { $snippet "class2" } ", and converts the one with the lower priority to the higher priority type." }
{ $examples { $example "USE: generic.math" "fixnum bignum math-upgrade ." "[ [ >bignum ] dip ]" } } ; { $examples { $example "USING: generic.math math kernel prettyprint ;" "fixnum bignum math-upgrade ." "[ [ >bignum ] dip ]" } } ;
HELP: no-math-method HELP: no-math-method
{ $values { "left" "an object" } { "right" "an object" } { "generic" "a generic word" } } { $values { "left" "an object" } { "right" "an object" } { "generic" generic } }
{ $description "Throws a " { $link no-math-method } " error." } { $description "Throws a " { $link no-math-method } " error." }
{ $error-description "Thrown by generic words using the " { $link math-combination } " method combination if there is no suitable method defined for the two inputs." } ; { $error-description "Thrown by generic words using the " { $link math-combination } " method combination if there is no suitable method defined for the two inputs." } ;
HELP: math-method HELP: math-method
{ $values { "word" "a generic word" } { "class1" "a class word" } { "class2" "a class word" } { "quot" "a quotation" } } { $values { "word" generic } { "class1" class } { "class2" class } { "quot" quotation } }
{ $description "Generates a definition for " { $snippet "word" } " when the two inputs are instances of " { $snippet "class1" } " and " { $snippet "class2" } ", respectively." } { $description "Generates a definition for " { $snippet "word" } " when the two inputs are instances of " { $snippet "class1" } " and " { $snippet "class2" } ", respectively." }
{ $examples { $example "USE: generic.math" "\\ + fixnum float math-method ." "[ [ >float ] dip float+ ]" } } ; { $examples { $example "USING: generic.math math prettyprint ;" "\\ + fixnum float math-method ." "[ [ >float ] dip float+ ]" } } ;
HELP: math-class HELP: math-class
{ $class-description "The class of subtypes of " { $link number } " which are not " { $link null } "." } ; { $class-description "The class of subtypes of " { $link number } " which are not " { $link null } "." } ;
HELP: math-combination HELP: math-combination
{ $values { "word" "a generic word" } { "quot" "a quotation" } } { $values { "word" generic } { "quot" quotation } }
{ $description "Generates a double-dispatching word definition. Only methods defined on numerical classes and " { $link object } " take effect in the math combination. Methods defined on numerical classes are guaranteed to have their two inputs upgraded to the highest priority type of the two." { $description "Generates a double-dispatching word definition. Only methods defined on numerical classes and " { $link object } " take effect in the math combination. Methods defined on numerical classes are guaranteed to have their two inputs upgraded to the highest priority type of the two."
$nl $nl
"The math method combination is used for binary operators such as " { $link + } " and " { $link * } "." "The math method combination is used for binary operators such as " { $link + } " and " { $link * } "."
@ -40,5 +41,5 @@ HELP: math-generic
{ $class-description "The class of generic words using " { $link math-combination } "." } ; { $class-description "The class of generic words using " { $link math-combination } "." } ;
HELP: last/first HELP: last/first
{ $values { "seq" "a sequence" } { "pair" "a two-element array" } } { $values { "seq" sequence } { "pair" "a two-element array" } }
{ $description "Creates an array holding the first and last element of the sequence." } ; { $description "Creates an array holding the first and last element of the sequence." } ;

View File

@ -1,5 +1,5 @@
USING: generic help.markup help.syntax sequences USING: generic help.markup help.syntax sequences ;
generic.standard ; IN: generic.standard
HELP: no-method HELP: no-method
{ $values { "object" "an object" } { "generic" "a generic word" } } { $values { "object" "an object" } { "generic" "a generic word" } }

View File

@ -18,19 +18,19 @@ $nl
ABOUT: "growable" ABOUT: "growable"
HELP: set-fill HELP: set-fill
{ $values { "n" "a new fill pointer" } { "seq" "a resizable sequence" } } { $values { "n" "a new fill pointer" } { "seq" growable } }
{ $contract "Sets the fill pointer (number of occupied elements in the underlying storage) of a resizable sequence." } { $contract "Sets the fill pointer (number of occupied elements in the underlying storage) of a resizable sequence." }
{ $side-effects "seq" } { $side-effects "seq" }
{ $warning "This word is in the " { $vocab-link "growable.private" } " vocabulary because it is not safe. Changing the fill pointer to a negative value, or a value higher than the underlying sequence length can lead to memory corruption. User code should use " { $link set-length } " instead." } ; { $warning "This word is not safe. Changing the fill pointer to a negative value, or a value higher than the underlying sequence length can lead to memory corruption. User code should use " { $link set-length } " instead." } ;
HELP: underlying HELP: underlying
{ $values { "seq" "a resizable sequence" } { "underlying" "the underlying sequence" } } { $values { "seq" growable } { "underlying" "the underlying sequence" } }
{ $contract "Outputs the underlying storage of a resizable sequence." } ; { $contract "Outputs the underlying storage of a resizable sequence." } ;
HELP: set-underlying HELP: set-underlying
{ $values { "underlying" "a sequence" } { "seq" "a resizable sequence" } } { $values { "underlying" sequence } { "seq" growable } }
{ $contract "Modifies the underlying storage of a resizable sequence." } { $contract "Modifies the underlying storage of a resizable sequence." }
{ $warning "This word is in the " { $vocab-link "growable.private" } " vocabulary because it is not safe. Setting an underlying sequence shorter than the fill pointer can lead to memory corruption." } ; { $warning "This word is not safe. Setting an underlying sequence shorter than the fill pointer can lead to memory corruption." } ;
HELP: capacity HELP: capacity
{ $values { "seq" "a vector or string buffer" } { "n" "the capacity of the sequence" } } { $values { "seq" "a vector or string buffer" } { "n" "the capacity of the sequence" } }
@ -41,7 +41,7 @@ HELP: new-size
{ $description "Computes the new size of a resizable sequence." } ; { $description "Computes the new size of a resizable sequence." } ;
HELP: ensure HELP: ensure
{ $values { "n" "a positive integer" } { "seq" "a resizable sequence" } } { $values { "n" "a positive integer" } { "seq" growable } }
{ $description "If " { $snippet "n" } " is less than the length of the sequence, does nothing. Otherwise, if " { $snippet "n" } " also exceeds the capacity of the underlying storage, the underlying storage is grown, and the fill pointer is reset. Finally, if " { $snippet "n" } " is greater than or equal to the length but less than the capacity of the underlying storage, the fill pointer is moved and nothing else is done." { $description "If " { $snippet "n" } " is less than the length of the sequence, does nothing. Otherwise, if " { $snippet "n" } " also exceeds the capacity of the underlying storage, the underlying storage is grown, and the fill pointer is reset. Finally, if " { $snippet "n" } " is greater than or equal to the length but less than the capacity of the underlying storage, the fill pointer is moved and nothing else is done."
$nl $nl
"This word is used in the implementation of the " { $link set-nth } " generic for sequences supporting the resizable sequence protocol (see " { $link "growable" } ")." "This word is used in the implementation of the " { $link set-nth } " generic for sequences supporting the resizable sequence protocol (see " { $link "growable" } ")."

View File

@ -128,14 +128,14 @@ HELP: prune
{ $values { "seq" "a sequence" } { "newseq" "a sequence" } } { $values { "seq" "a sequence" } { "newseq" "a sequence" } }
{ $description "Outputs a new sequence with each distinct element of " { $snippet "seq" } " appearing only once. Elements are compared for equality using " { $link = } " and elements are ordered according to their position in " { $snippet "seq" } "." } { $description "Outputs a new sequence with each distinct element of " { $snippet "seq" } " appearing only once. Elements are compared for equality using " { $link = } " and elements are ordered according to their position in " { $snippet "seq" } "." }
{ $examples { $examples
{ $example "USE: hashtables" "{ 1 1 t 3 t } prune ." "V{ 1 t 3 }" } { $example "USING: hashtables prettyprint ;" "{ 1 1 t 3 t } prune ." "V{ 1 t 3 }" }
} ; } ;
HELP: all-unique? HELP: all-unique?
{ $values { "seq" sequence } { "?" "a boolean" } } { $values { "seq" sequence } { "?" "a boolean" } }
{ $description "Tests whether a sequence contains any repeated elements." } { $description "Tests whether a sequence contains any repeated elements." }
{ $example { $example
"USE: combinators.lib" "USING: hashtables prettyprint ;"
"{ 0 1 1 2 3 5 } all-unique? ." "{ 0 1 1 2 3 5 } all-unique? ."
"f" "f"
} ; } ;

View File

@ -77,6 +77,7 @@ HELP: heap-size
{ $description "Returns the number of key/value pairs in the heap." } ; { $description "Returns the number of key/value pairs in the heap." } ;
HELP: heap-delete HELP: heap-delete
{ $values { "heap" "a heap" } { "key" object } { "value" object } } { $values { "entry" entry } { "heap" "a heap" } }
{ $description "Output and remove the first element in the heap." } { $description "Remove the specified entry from the heap." }
{ $errors "Throws an error if the entry is from another heap or if it has already been deleted." }
{ $side-effects "heap" } ; { $side-effects "heap" } ;

View File

@ -6,7 +6,7 @@ HELP: crc32
{ $description "Computes the CRC32 checksum of a sequence of bytes." } ; { $description "Computes the CRC32 checksum of a sequence of bytes." } ;
HELP: lines-crc32 HELP: lines-crc32
{ $values { "lines" "a sequence of strings" } { "n" integer } } { $values { "seq" "a sequence of strings" } { "n" integer } }
{ $description "Computes the CRC32 checksum of a sequence of lines of bytes." } ; { $description "Computes the CRC32 checksum of a sequence of lines of bytes." } ;
ARTICLE: "io.crc32" "CRC32 checksum calculation" ARTICLE: "io.crc32" "CRC32 checksum calculation"

View File

@ -104,18 +104,18 @@ HELP: path-separator?
HELP: parent-directory HELP: parent-directory
{ $values { "path" "a pathname string" } { "parent" "a pathname string" } } { $values { "path" "a pathname string" } { "parent" "a pathname string" } }
{ $description "Strips the last component off a pathname." } { $description "Strips the last component off a pathname." }
{ $examples { $example "USE: io.files" "\"/etc/passwd\" parent-directory print" "/etc/" } } ; { $examples { $example "USING: io io.files ;" "\"/etc/passwd\" parent-directory print" "/etc/" } } ;
HELP: file-name HELP: file-name
{ $values { "path" "a pathname string" } { "string" string } } { $values { "path" "a pathname string" } { "string" string } }
{ $description "Outputs the last component of a pathname string." } { $description "Outputs the last component of a pathname string." }
{ $examples { $examples
{ "\"/usr/bin/gcc\" file-name ." "\"gcc\"" } { $example "USING: io.files prettyprint ;" "\"/usr/bin/gcc\" file-name ." "\"gcc\"" }
{ "\"/usr/libexec/awk/\" file-name ." "\"awk\"" } { $example "USING: io.files prettyprint ;" "\"/usr/libexec/awk/\" file-name ." "\"awk\"" }
} ; } ;
HELP: <file-reader> HELP: <file-reader>
{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptors" } { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" { "stream" "an input stream" } }
{ "stream" "an input stream" } } { "stream" "an input stream" } }
{ $description "Outputs an input stream for reading from the specified pathname using the given encoding." } { $description "Outputs an input stream for reading from the specified pathname using the given encoding." }
{ $errors "Throws an error if the file is unreadable." } ; { $errors "Throws an error if the file is unreadable." } ;

View File

@ -13,21 +13,22 @@ ARTICLE: "io.streams.byte-array" "Byte-array streams"
HELP: <byte-reader> HELP: <byte-reader>
{ $values { "byte-array" byte-array } { $values { "byte-array" byte-array }
{ "encoding" "an encoding descriptor" } } { "encoding" "an encoding descriptor" }
{ $description "Provides an input stream reading off the given byte array using the given encoding." } ; { "stream" "a new byte reader" } }
{ $description "Creates an input stream reading from a byte array using an encoding." } ;
HELP: <byte-writer> HELP: <byte-writer>
{ $values { "encoding" "an encoding descriptor" } { $values { "encoding" "an encoding descriptor" }
{ "stream" "an output stream" } } { "stream" "a new byte writer" } }
{ $description "Provides an output stream, putting things in the given encoding, storing everything written to it in a byte-array." } ; { $description "Creates an output stream writing data to a byte array using an encoding." } ;
HELP: with-byte-reader HELP: with-byte-reader
{ $values { "encoding" "an encoding descriptor" } { $values { "encoding" "an encoding descriptor" }
{ "quot" quotation } { "byte-array" byte-array } } { "quot" quotation } { "byte-array" byte-array } }
{ $description "Calls the quotation in a new dynamic scope with " { $link stdio } " rebound to an input stream reading the byte array in the given encoding from beginning to end." } ; { $description "Calls the quotation in a new dynamic scope with " { $link stdio } " rebound to an input stream for reading from a byte array using an encoding." } ;
HELP: with-byte-writer HELP: with-byte-writer
{ $values { "encoding" "an encoding descriptor" } { $values { "encoding" "an encoding descriptor" }
{ "quot" quotation } { "quot" quotation }
{ "byte-array" byte-array } } { "byte-array" byte-array } }
{ $description "Calls the quotation in a new dynamic scope with " { $link stdio } " rebound to a new byte array writer, putting things in the given encoding. The accumulated byte array is output when the quotation returns." } ; { $description "Calls the quotation in a new dynamic scope with " { $link stdio } " rebound to an output stream writing data to a byte array using an encoding." } ;

View File

@ -264,7 +264,7 @@ HELP: compare
{ $values { "obj1" object } { "obj2" object } { "quot" "a quotation with stack effect " { $snippet "( obj -- newobj )" } } { "n" integer } } { $values { "obj1" object } { "obj2" object } { "quot" "a quotation with stack effect " { $snippet "( obj -- newobj )" } } { "n" integer } }
{ $description "Compares the results of applying the quotation to both objects via " { $link <=> } "." } { $description "Compares the results of applying the quotation to both objects via " { $link <=> } "." }
{ $examples { $examples
{ $example "\"hello\" \"hi\" [ length ] compare ." "3" } { $example "USING: kernel prettyprint sequences ;" "\"hello\" \"hi\" [ length ] compare ." "3" }
} ; } ;
HELP: clone HELP: clone
@ -296,9 +296,9 @@ HELP: and
{ $notes "This word implements boolean and, so applying it to integers will not yield useful results (all integers have a true value). Bitwise and is the " { $link bitand } " word." } { $notes "This word implements boolean and, so applying it to integers will not yield useful results (all integers have a true value). Bitwise and is the " { $link bitand } " word." }
{ $examples { $examples
"Usually only the boolean value of the result is used, however you can also explicitly rely on the behavior that if both inputs are true, the second is output:" "Usually only the boolean value of the result is used, however you can also explicitly rely on the behavior that if both inputs are true, the second is output:"
{ $example "t f and ." "f" } { $example "USING: kernel prettyprint ;" "t f and ." "f" }
{ $example "t 7 and ." "7" } { $example "USING: kernel prettyprint ;" "t 7 and ." "7" }
{ $example "\"hi\" 12.0 and ." "12.0" } { $example "USING: kernel prettyprint ;" "\"hi\" 12.0 and ." "12.0" }
} ; } ;
HELP: or HELP: or
@ -307,8 +307,8 @@ HELP: or
{ $notes "This word implements boolean inclusive or, so applying it to integers will not yield useful results (all integers have a true value). Bitwise inclusive or is the " { $link bitor } " word." } { $notes "This word implements boolean inclusive or, so applying it to integers will not yield useful results (all integers have a true value). Bitwise inclusive or is the " { $link bitor } " word." }
{ $examples { $examples
"Usually only the boolean value of the result is used, however you can also explicitly rely on the behavior that the result will be the first true input:" "Usually only the boolean value of the result is used, however you can also explicitly rely on the behavior that the result will be the first true input:"
{ $example "t f or ." "t" } { $example "USING: kernel prettyprint ;" "t f or ." "t" }
{ $example "\"hi\" 12.0 or ." "\"hi\"" } { $example "USING: kernel prettyprint ;" "\"hi\" 12.0 or ." "\"hi\"" }
} ; } ;
HELP: xor HELP: xor
@ -320,23 +320,21 @@ HELP: both?
{ $values { "quot" "a quotation with stack effect " { $snippet "( obj -- ? )" } } { "x" object } { "y" object } { "?" "a boolean" } } { $values { "quot" "a quotation with stack effect " { $snippet "( obj -- ? )" } } { "x" object } { "y" object } { "?" "a boolean" } }
{ $description "Tests if the quotation yields a true value when applied to both " { $snippet "x" } " and " { $snippet "y" } "." } { $description "Tests if the quotation yields a true value when applied to both " { $snippet "x" } " and " { $snippet "y" } "." }
{ $examples { $examples
{ $example "3 5 [ odd? ] both? ." "t" } { $example "USING: kernel math prettyprint ;" "3 5 [ odd? ] both? ." "t" }
{ $example "12 7 [ even? ] both? ." "f" } { $example "USING: kernel math prettyprint ;" "12 7 [ even? ] both? ." "f" }
} ; } ;
HELP: either? HELP: either?
{ $values { "quot" "a quotation with stack effect " { $snippet "( obj -- ? )" } } { "x" object } { "y" object } { "?" "a boolean" } } { $values { "quot" "a quotation with stack effect " { $snippet "( obj -- ? )" } } { "x" object } { "y" object } { "?" "a boolean" } }
{ $description "Tests if the quotation yields a true value when applied to either " { $snippet "x" } " or " { $snippet "y" } "." } { $description "Tests if the quotation yields a true value when applied to either " { $snippet "x" } " or " { $snippet "y" } "." }
{ $examples { $examples
{ $example "3 6 [ odd? ] either? ." "t" } { $example "USING: kernel math prettyprint ;" "3 6 [ odd? ] either? ." "t" }
{ $example "5 7 [ even? ] either? ." "f" } { $example "USING: kernel math prettyprint ;" "5 7 [ even? ] either? ." "f" }
} ; } ;
HELP: call ( callable -- ) HELP: call
{ $values { "quot" callable } } { $values { "callable" callable } }
{ $description "Calls a quotation." { $description "Calls a quotation." }
$nl
"Under the covers, pushes the current call frame on the call stack, and set the call frame to the given quotation." }
{ $examples { $examples
"The following two lines are equivalent:" "The following two lines are equivalent:"
{ $code "2 [ 2 + 3 * ] call" "2 2 + 3 *" } { $code "2 [ 2 + 3 * ] call" "2 2 + 3 *" }
@ -489,9 +487,9 @@ HELP: curry ( obj quot -- curry )
$nl $nl
"This operation is efficient and does not copy the quotation." } "This operation is efficient and does not copy the quotation." }
{ $examples { $examples
{ $example "5 [ . ] curry ." "[ 5 . ]" } { $example "USING: kernel prettyprint ;" "5 [ . ] curry ." "[ 5 . ]" }
{ $example "\\ = [ see ] curry ." "[ \\ = see ]" } { $example "USING: kernel prettyprint ;" "\\ = [ see ] curry ." "[ \\ = see ]" }
{ $example "{ 1 2 3 } 2 [ - ] curry map ." "{ -1 0 1 }" } { $example "USING: kernel math prettyprint sequences ;" "{ 1 2 3 } 2 [ - ] curry map ." "{ -1 0 1 }" }
} ; } ;
HELP: 2curry HELP: 2curry
@ -499,7 +497,7 @@ HELP: 2curry
{ $description "Outputs a " { $link callable } " which pushes " { $snippet "obj1" } " and " { $snippet "obj2" } " and then calls " { $snippet "quot" } "." } { $description "Outputs a " { $link callable } " which pushes " { $snippet "obj1" } " and " { $snippet "obj2" } " and then calls " { $snippet "quot" } "." }
{ $notes "This operation is efficient and does not copy the quotation." } { $notes "This operation is efficient and does not copy the quotation." }
{ $examples { $examples
{ $example "5 4 [ + ] 2curry ." "[ 5 4 + ]" } { $example "USING: kernel math prettyprint ;" "5 4 [ + ] 2curry ." "[ 5 4 + ]" }
} ; } ;
HELP: 3curry HELP: 3curry
@ -516,7 +514,7 @@ HELP: with
} }
{ $notes "This operation is efficient and does not copy the quotation." } { $notes "This operation is efficient and does not copy the quotation." }
{ $examples { $examples
{ $example "2 { 1 2 3 } [ - ] with map ." "{ 1 0 -1 }" } { $example "USING: kernel math prettyprint sequences ;" "2 { 1 2 3 } [ - ] with map ." "{ 1 0 -1 }" }
} ; } ;
HELP: compose HELP: compose

View File

@ -31,8 +31,8 @@ HELP: listener-hook
{ $var-description "Variable holding a quotation called by the listener before reading an input expression. The UI sets this variable to a quotation which updates the stack display in a listener gadget." } ; { $var-description "Variable holding a quotation called by the listener before reading an input expression. The UI sets this variable to a quotation which updates the stack display in a listener gadget." } ;
HELP: read-quot HELP: read-quot
{ $values { "stream" "an input stream" } { "quot/f" "a parsed quotation, or " { $link f } " indicating end of file" } } { $values { "quot/f" "a parsed quotation, or " { $link f } " indicating end of file" } }
{ $description "Reads a Factor expression from the stream, possibly spanning more than line. Additional lines of input are read while the parser stack height is greater than one. Since structural parsing words push partial quotations on the stack, this will keep on reading input until all delimited parsing words are terminated." } ; { $description "Reads a Factor expression which possibly spans more than one line from " { $link stdio } " stream. Additional lines of input are read while the parser stack height is greater than one. Since structural parsing words push partial quotations on the stack, this will keep on reading input until all delimited parsing words are terminated." } ;
HELP: listen HELP: listen
{ $description "Prompts for an expression on the " { $link stdio } " stream and evaluates it. On end of file, " { $link quit-flag } " is set to terminate the listener loop." } { $description "Prompts for an expression on the " { $link stdio } " stream and evaluates it. On end of file, " { $link quit-flag } " is set to terminate the listener loop." }

View File

@ -38,7 +38,7 @@ M: object stream-read-quot
M: duplex-stream stream-read-quot M: duplex-stream stream-read-quot
duplex-stream-in stream-read-quot ; duplex-stream-in stream-read-quot ;
: read-quot ( -- quot ) stdio get stream-read-quot ; : read-quot ( -- quot/f ) stdio get stream-read-quot ;
: bye ( -- ) quit-flag on ; : bye ( -- ) quit-flag on ;

View File

@ -213,41 +213,41 @@ HELP: incomparable
{ $description "Output value from " { $link interval<= } ", " { $link interval< } ", " { $link interval>= } " and " { $link interval> } " in the case where the result of the comparison is ambiguous." } ; { $description "Output value from " { $link interval<= } ", " { $link interval< } ", " { $link interval>= } " and " { $link interval> } " in the case where the result of the comparison is ambiguous." } ;
HELP: interval<= HELP: interval<=
{ $values { "int" interval } { "n" real } { "?" "a boolean or " { $link incomparable } } } { $values { "i1" interval } { "i2" interval } { "?" "a boolean or " { $link incomparable } } }
{ $description "Compares " { $snippet "int" } " with " { $snippet "n" } ", and outputs one of the following:" { $description "Compares " { $snippet "i1" } " with " { $snippet "i2" } ", and outputs one of the following:"
{ $list { $list
{ { $link t } " if every point in " { $snippet "int" } " is less than or equal to " { $snippet "n" } } { { $link t } " if every point in " { $snippet "i1" } " is less than or equal to every point in " { $snippet "i2" } }
{ { $link f } " if every point in " { $snippet "int" } " is greater than " { $snippet "n" } } { { $link f } " if every point in " { $snippet "i1" } " is greater than every point in " { $snippet "i2" } }
{ { $link incomparable } " if neither of the above conditions hold" } { { $link incomparable } " if neither of the above conditions hold" }
} }
} ; } ;
HELP: interval< HELP: interval<
{ $values { "int" interval } { "n" real } { "?" "a boolean or " { $link incomparable } } } { $values { "i1" interval } { "i2" interval } { "?" "a boolean or " { $link incomparable } } }
{ $description "Compares " { $snippet "int" } " with " { $snippet "n" } ", and outputs one of the following:" { $description "Compares " { $snippet "i1" } " with " { $snippet "i2" } ", and outputs one of the following:"
{ $list { $list
{ { $link t } " if every point in " { $snippet "int" } " is less than " { $snippet "n" } } { { $link t } " if every point in " { $snippet "i1" } " is less than every point in " { $snippet "i2" } }
{ { $link f } " if every point in " { $snippet "int" } " is greater than or equal to " { $snippet "n" } } { { $link f } " if every point in " { $snippet "i1" } " is greater than or equal to every point in " { $snippet "i2" } }
{ { $link incomparable } " if neither of the above conditions hold" } { { $link incomparable } " if neither of the above conditions hold" }
} }
} ; } ;
HELP: interval>= HELP: interval>=
{ $values { "int" interval } { "n" real } { "?" "a boolean or " { $link incomparable } } } { $values { "i1" interval } { "i2" interval } { "?" "a boolean or " { $link incomparable } } }
{ $description "Compares " { $snippet "int" } " with " { $snippet "n" } ", and outputs one of the following:" { $description "Compares " { $snippet "i1" } " with " { $snippet "i2" } ", and outputs one of the following:"
{ $list { $list
{ { $link t } " if every point in " { $snippet "int" } " is greater than or equal to " { $snippet "n" } } { { $link t } " if every point in " { $snippet "i1" } " is greater than or equal to every point in " { $snippet "i2" } }
{ { $link f } " if every point in " { $snippet "int" } " is less than " { $snippet "n" } } { { $link f } " if every point in " { $snippet "i1" } " is less than every point in " { $snippet "i2" } }
{ { $link incomparable } " if neither of the above conditions hold" } { { $link incomparable } " if neither of the above conditions hold" }
} }
} ; } ;
HELP: interval> HELP: interval>
{ $values { "int" interval } { "n" real } { "?" "a boolean or " { $link incomparable } } } { $values { "i1" interval } { "i2" interval } { "?" "a boolean or " { $link incomparable } } }
{ $description "Compares " { $snippet "int" } " with " { $snippet "n" } ", and outputs one of the following:" { $description "Compares " { $snippet "i1" } " with " { $snippet "i2" } ", and outputs one of the following:"
{ $list { $list
{ { $link t } " if every point in " { $snippet "int" } " is greater than " { $snippet "n" } } { { $link t } " if every point in " { $snippet "i1" } " is greater than every point in " { $snippet "i2" } }
{ { $link f } " if every point in " { $snippet "int" } " is less than or equal to " { $snippet "n" } } { { $link f } " if every point in " { $snippet "i1" } " is less than or equal to every point in " { $snippet "i2" } }
{ { $link incomparable } " if neither of the above conditions hold" } { { $link incomparable } " if neither of the above conditions hold" }
} }
} ; } ;

View File

@ -184,8 +184,8 @@ HELP: bitand
{ $values { "x" integer } { "y" integer } { "z" integer } } { $values { "x" integer } { "y" integer } { "z" integer } }
{ $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in both inputs." } { $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in both inputs." }
{ $examples { $examples
{ $example "BIN: 101 BIN: 10 bitand .b" "0" } { $example "USING: math prettyprint ;" "BIN: 101 BIN: 10 bitand .b" "0" }
{ $example "BIN: 110 BIN: 10 bitand .b" "10" } { $example "USING: math prettyprint ;" "BIN: 110 BIN: 10 bitand .b" "10" }
} }
{ $notes "This word implements bitwise and, so applying it to booleans will throw an error. Boolean and is the " { $link and } " word." } ; { $notes "This word implements bitwise and, so applying it to booleans will throw an error. Boolean and is the " { $link and } " word." } ;
@ -193,8 +193,8 @@ HELP: bitor
{ $values { "x" integer } { "y" integer } { "z" integer } } { $values { "x" integer } { "y" integer } { "z" integer } }
{ $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in at least one of the inputs." } { $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in at least one of the inputs." }
{ $examples { $examples
{ $example "BIN: 101 BIN: 10 bitor .b" "111" } { $example "USING: math prettyprint ;" "BIN: 101 BIN: 10 bitor .b" "111" }
{ $example "BIN: 110 BIN: 10 bitor .b" "110" } { $example "USING: math prettyprint ;" "BIN: 110 BIN: 10 bitor .b" "110" }
} }
{ $notes "This word implements bitwise inclusive or, so applying it to booleans will throw an error. Boolean inclusive or is the " { $link and } " word." } ; { $notes "This word implements bitwise inclusive or, so applying it to booleans will throw an error. Boolean inclusive or is the " { $link and } " word." } ;
@ -202,15 +202,15 @@ HELP: bitxor
{ $values { "x" integer } { "y" integer } { "z" integer } } { $values { "x" integer } { "y" integer } { "z" integer } }
{ $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in exactly one of the inputs." } { $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in exactly one of the inputs." }
{ $examples { $examples
{ $example "BIN: 101 BIN: 10 bitxor .b" "111" } { $example "USING: math prettyprint ;" "BIN: 101 BIN: 10 bitxor .b" "111" }
{ $example "BIN: 110 BIN: 10 bitxor .b" "100" } { $example "USING: math prettyprint ;" "BIN: 110 BIN: 10 bitxor .b" "100" }
} }
{ $notes "This word implements bitwise exclusive or, so applying it to booleans will throw an error. Boolean exclusive or is the " { $link xor } " word." } ; { $notes "This word implements bitwise exclusive or, so applying it to booleans will throw an error. Boolean exclusive or is the " { $link xor } " word." } ;
HELP: shift HELP: shift
{ $values { "x" integer } { "n" integer } { "y" integer } } { $values { "x" integer } { "n" integer } { "y" integer } }
{ $description "Shifts " { $snippet "x" } " to the left by " { $snippet "n" } " bits if " { $snippet "n" } " is positive, or " { $snippet "-n" } " bits to the right if " { $snippet "n" } " is negative. A left shift of a fixnum may overflow, yielding a bignum. A right shift may result in bits ``falling off'' the right hand side and being discarded." } { $description "Shifts " { $snippet "x" } " to the left by " { $snippet "n" } " bits if " { $snippet "n" } " is positive, or " { $snippet "-n" } " bits to the right if " { $snippet "n" } " is negative. A left shift of a fixnum may overflow, yielding a bignum. A right shift may result in bits ``falling off'' the right hand side and being discarded." }
{ $examples { $example "BIN: 101 5 shift .b" "10100000" } { $example "BIN: 11111 -2 shift .b" "111" } } ; { $examples { $example "USING: math prettyprint ;" "BIN: 101 5 shift .b" "10100000" } { $example "USING: math prettyprint ;" "BIN: 11111 -2 shift .b" "111" } } ;
HELP: bitnot HELP: bitnot
{ $values { "x" integer } { "y" integer } } { $values { "x" integer } { "y" integer } }
@ -222,7 +222,7 @@ $nl
HELP: bit? HELP: bit?
{ $values { "x" integer } { "n" integer } { "?" "a boolean" } } { $values { "x" integer } { "n" integer } { "?" "a boolean" } }
{ $description "Tests if the " { $snippet "n" } "th bit of " { $snippet "x" } " is set." } { $description "Tests if the " { $snippet "n" } "th bit of " { $snippet "x" } " is set." }
{ $examples { $example "BIN: 101 2 bit? ." "t" } } ; { $examples { $example "USING: math prettyprint ;" "BIN: 101 2 bit? ." "t" } } ;
HELP: log2 HELP: log2
{ $values { "x" "a positive integer" } { "n" integer } } { $values { "x" "a positive integer" } { "n" integer } }
@ -295,9 +295,9 @@ HELP: 2/
{ $values { "x" integer } { "y" integer } } { $values { "x" integer } { "y" integer } }
{ $description "Shifts " { $snippet "x" } " to the right by one bit." } { $description "Shifts " { $snippet "x" } " to the right by one bit." }
{ $examples { $examples
{ $example "14 2/ ." "7" } { $example "USING: math prettyprint ;" "14 2/ ." "7" }
{ $example "17 2/ ." "8" } { $example "USING: math prettyprint ;" "17 2/ ." "8" }
{ $example "-17 2/ ." "-9" } { $example "USING: math prettyprint ;" "-17 2/ ." "-9" }
} }
{ $notes "This word is not equivalent to " { $snippet "2 /" } " or " { $snippet "2 /i" } "; the name is historic and originates from the Forth programming language." } ; { $notes "This word is not equivalent to " { $snippet "2 /" } " or " { $snippet "2 /i" } "; the name is historic and originates from the Forth programming language." } ;

View File

@ -29,7 +29,7 @@ HELP: <mirror>
{ $description "Creates a " { $link mirror } " reflecting an object." } { $description "Creates a " { $link mirror } " reflecting an object." }
{ $examples { $examples
{ $example { $example
"USING: assocs mirrors ;" "USING: assocs mirrors prettyprint ;"
"TUPLE: circle center radius ;" "TUPLE: circle center radius ;"
"C: <circle> circle" "C: <circle> circle"
"{ 100 50 } 15 <circle> <mirror> >alist ." "{ 100 50 } 15 <circle> <mirror> >alist ."

View File

@ -87,7 +87,7 @@ HELP: +@
{ $description "Adds " { $snippet "n" } " to the value of the variable. A variable value of " { $link f } " is interpreted as being zero." } { $description "Adds " { $snippet "n" } " to the value of the variable. A variable value of " { $link f } " is interpreted as being zero." }
{ $side-effects "variable" } { $side-effects "variable" }
{ $examples { $examples
{ $example "SYMBOL: foo\n1 foo +@\n10 foo +@\nfoo get ." "11" } { $example "USING: namespaces prettyprint ;" "SYMBOL: foo\n1 foo +@\n10 foo +@\nfoo get ." "11" }
} ; } ;
HELP: inc HELP: inc
@ -168,7 +168,7 @@ HELP: building
HELP: make HELP: make
{ $values { "quot" quotation } { "exemplar" "a sequence" } { "seq" "a new sequence" } } { $values { "quot" quotation } { "exemplar" "a sequence" } { "seq" "a new sequence" } }
{ $description "Calls the quotation in a new " { $emphasis "dynamic scope" } ". The quotation and any words it calls can execute the " { $link , } " and " { $link % } " words to accumulate elements. When the quotation returns, all accumulated elements are collected into a sequence with the same type as " { $snippet "exemplar" } "." } { $description "Calls the quotation in a new " { $emphasis "dynamic scope" } ". The quotation and any words it calls can execute the " { $link , } " and " { $link % } " words to accumulate elements. When the quotation returns, all accumulated elements are collected into a sequence with the same type as " { $snippet "exemplar" } "." }
{ $examples { $example "[ 1 , 2 , 3 , ] { } make ." "{ 1 2 3 }" } } ; { $examples { $example "USING: namespaces prettyprint ;" "[ 1 , 2 , 3 , ] { } make ." "{ 1 2 3 }" } } ;
HELP: , HELP: ,
{ $values { "elt" object } } { $values { "elt" object } }

View File

@ -221,8 +221,8 @@ HELP: <parse-error>
{ $description "Creates a new " { $link parse-error } ", filling in the location information from the current " { $link lexer } "." } ; { $description "Creates a new " { $link parse-error } ", filling in the location information from the current " { $link lexer } "." } ;
HELP: skip HELP: skip
{ $values { "i" "a starting index" } { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( elt -- ? )" } } { "n" integer } } { $values { "i" "a starting index" } { "seq" sequence } { "?" "a boolean" } { "n" integer } }
{ $description "Variant of " { $link find* } " that outputs the length of the sequence instead of " { $link f } " if no elements satisfy the predicate." } ; { $description "Skips to the first space character (if " { $snippet "boolean" } " is " { $link f } ") or the first non-space character (otherwise)." } ;
HELP: change-column HELP: change-column
{ $values { "lexer" lexer } { "quot" "a quotation with stack effect " { $snippet "( col line -- newcol )" } } } { $values { "lexer" lexer } { "quot" "a quotation with stack effect " { $snippet "( col line -- newcol )" } } }
@ -264,7 +264,7 @@ HELP: bad-number
HELP: escape HELP: escape
{ $values { "escape" "a single-character escape" } { "ch" "a character" } } { $values { "escape" "a single-character escape" } { "ch" "a character" } }
{ $description "Converts from a single-character escape code and the corresponding character." } { $description "Converts from a single-character escape code and the corresponding character." }
{ $examples { $example "CHAR: n escape CHAR: \\n = ." "t" } } ; { $examples { $example "USING: kernel parser prettyprint ;" "CHAR: n escape CHAR: \\n = ." "t" } } ;
HELP: parse-string HELP: parse-string
{ $values { "str" "a new " { $link string } } } { $values { "str" "a new " { $link string } } }
@ -340,8 +340,8 @@ HELP: no-word
{ $notes "Apart from a missing " { $link POSTPONE: USE: } ", this error can also indicate an ordering issue. In Factor, words must be defined before they can be called. Mutual recursion can be implemented via " { $link POSTPONE: DEFER: } "." } ; { $notes "Apart from a missing " { $link POSTPONE: USE: } ", this error can also indicate an ordering issue. In Factor, words must be defined before they can be called. Mutual recursion can be implemented via " { $link POSTPONE: DEFER: } "." } ;
HELP: search HELP: search
{ $values { "str" string } { "word" word } } { $values { "str" string } { "word/f" "a word or " { $link f } } }
{ $description "Searches for a word by name in the current vocabulary search path. If no such word could be found, throws a " { $link no-word } " error. If the search path does not contain a word with this name but other vocabularies do, the error will have restarts offering to add vocabularies to the search path." } { $description "Searches for a word by name in the current vocabulary search path. If no such word could be found, outputs " { $link f } "." }
$parsing-note ; $parsing-note ;
HELP: scan-word HELP: scan-word
@ -459,7 +459,7 @@ HELP: forget-smudged
{ $description "Forgets removed definitions and prints a warning message if any of them are still referenced from other source files." } ; { $description "Forgets removed definitions and prints a warning message if any of them are still referenced from other source files." } ;
HELP: finish-parsing HELP: finish-parsing
{ $values { "quot" "the quotation just parsed" } } { $values { "lines" "the lines of text just parsed" } { "quot" "the quotation just parsed" } }
{ $description "Records information to the current " { $link file } " and prints warnings about any removed definitions which are still in use." } { $description "Records information to the current " { $link file } " and prints warnings about any removed definitions which are still in use." }
{ $notes "This is one of the factors of " { $link parse-stream } "." } ; { $notes "This is one of the factors of " { $link parse-stream } "." } ;

View File

@ -242,8 +242,8 @@ HELP: definer
{ $values { "defspec" "a definition specifier" } { "start" word } { "end" "a word or " { $link f } } } { $values { "defspec" "a definition specifier" } { "start" word } { "end" "a word or " { $link f } } }
{ $contract "Outputs the parsing words which delimit the definition." } { $contract "Outputs the parsing words which delimit the definition." }
{ $examples { $examples
{ $example ": foo ; \\ foo definer . ." ";\nPOSTPONE: :" } { $example "USING: definitions prettyprint ;" ": foo ; \\ foo definer . ." ";\nPOSTPONE: :" }
{ $example "SYMBOL: foo \\ foo definer . ." "f\nPOSTPONE: SYMBOL:" } { $example "USING: definitions prettyprint ;" "SYMBOL: foo \\ foo definer . ." "f\nPOSTPONE: SYMBOL:" }
} }
{ $notes "This word is used in the implementation of " { $link see } "." } ; { $notes "This word is used in the implementation of " { $link see } "." } ;
@ -251,6 +251,6 @@ HELP: definition
{ $values { "defspec" "a definition specifier" } { "seq" "a sequence" } } { $values { "defspec" "a definition specifier" } { "seq" "a sequence" } }
{ $contract "Outputs the body of a definition." } { $contract "Outputs the body of a definition." }
{ $examples { $examples
{ $example "USE: math" "\\ sq definition ." "[ dup * ]" } { $example "USING: definitions math prettyprint ;" "\\ sq definition ." "[ dup * ]" }
} }
{ $notes "This word is used in the implementation of " { $link see } "." } ; { $notes "This word is used in the implementation of " { $link see } "." } ;

View File

@ -51,8 +51,8 @@ HELP: literalize
{ $values { "obj" object } { "wrapped" object } } { $values { "obj" object } { "wrapped" object } }
{ $description "Outputs an object which evaluates to " { $snippet "obj" } " when placed in a quotation. If " { $snippet "obj" } " is not self-evaluating (for example, it is a word), then it will be wrapped." } { $description "Outputs an object which evaluates to " { $snippet "obj" } " when placed in a quotation. If " { $snippet "obj" } " is not self-evaluating (for example, it is a word), then it will be wrapped." }
{ $examples { $examples
{ $example "USE: quotations" "5 literalize ." "5" } { $example "USING: prettyprint quotations ;" "5 literalize ." "5" }
{ $example "USE: quotations" "[ + ] [ literalize ] map ." "[ \\ + ]" } { $example "USING: math prettyprint quotations sequences ;" "[ + ] [ literalize ] map ." "[ \\ + ]" }
} ; } ;
{ literalize curry <wrapper> POSTPONE: \ POSTPONE: W{ } related-words { literalize curry <wrapper> POSTPONE: \ POSTPONE: W{ } related-words

View File

@ -288,8 +288,8 @@ HELP: new-resizable
{ $values { "len" "a non-negative integer" } { "seq" sequence } { "newseq" "a resizable mutable sequence" } } { $values { "len" "a non-negative integer" } { "seq" sequence } { "newseq" "a resizable mutable sequence" } }
{ $contract "Outputs a resizable mutable sequence with an initial capacity of " { $snippet "n" } " elements and zero length, which can hold the elements of " { $snippet "seq" } "." } { $contract "Outputs a resizable mutable sequence with an initial capacity of " { $snippet "n" } " elements and zero length, which can hold the elements of " { $snippet "seq" } "." }
{ $examples { $examples
{ $example "300 V{ } new-resizable ." "V{ }" } { $example "USING: prettyprint sequences ;" "300 V{ } new-resizable ." "V{ }" }
{ $example "300 SBUF\" \" new-resizable ." "SBUF\" \"" } { $example "USING: prettyprint sequences ;" "300 SBUF\" \" new-resizable ." "SBUF\" \"" }
} ; } ;
HELP: like HELP: like
@ -435,14 +435,16 @@ HELP: reduce
{ $values { "seq" sequence } { "identity" object } { "quot" "a quotation with stack effect " { $snippet "( prev elt -- next )" } } { "result" "the final result" } } { $values { "seq" sequence } { "identity" object } { "quot" "a quotation with stack effect " { $snippet "( prev elt -- next )" } } { "result" "the final result" } }
{ $description "Combines successive elements of the sequence using a binary operation, and outputs the final result. On the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the sequence." } { $description "Combines successive elements of the sequence using a binary operation, and outputs the final result. On the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the sequence." }
{ $examples { $examples
{ $example "{ 1 5 3 } 0 [ + ] reduce ." "9" } { $example "USING: math prettyprint sequences ;" "{ 1 5 3 } 0 [ + ] reduce ." "9" }
} ; } ;
HELP: accumulate HELP: accumulate
{ $values { "identity" object } { "seq" sequence } { "quot" "a quotation with stack effect " { $snippet "( prev elt -- next )" } } { "final" "the final result" } { "newseq" "a new sequence" } } { $values { "identity" object } { "seq" sequence } { "quot" "a quotation with stack effect " { $snippet "( prev elt -- next )" } } { "final" "the final result" } { "newseq" "a new sequence" } }
{ $description "Combines successive elements of the sequence using a binary operation, and outputs a sequence of intermediate results together with the final result. On the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the sequence. Given the empty sequence, outputs a one-element sequence consisting of " { $snippet "identity" } "." } { $description "Combines successive elements of the sequence using a binary operation, and outputs a sequence of intermediate results together with the final result. On the first iteration, the two inputs to the quotation are " { $snippet "identity" } ", and the first element of the sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the sequence."
$nl
"When given the empty sequence, outputs an empty sequence together with the " { $snippet "identity" } "." }
{ $examples { $examples
{ $example "{ 2 2 2 2 2 } 0 [ + ] accumulate . ." "{ 0 2 4 6 8 }\n10" } { $example "USING: math prettyprint sequences ;" "{ 2 2 2 2 2 } 0 [ + ] accumulate . ." "{ 0 2 4 6 8 }\n10" }
} ; } ;
HELP: map HELP: map
@ -546,9 +548,9 @@ HELP: monotonic?
{ $description "Applies the relation to successive pairs of elements in the sequence, testing for a truth value. The relation should be a transitive relation, such as a total order or an equality relation." } { $description "Applies the relation to successive pairs of elements in the sequence, testing for a truth value. The relation should be a transitive relation, such as a total order or an equality relation." }
{ $examples { $examples
"Testing if a sequence is non-decreasing:" "Testing if a sequence is non-decreasing:"
{ $example "{ 1 1 2 } [ <= ] monotonic? ." "t" } { $example "USING: math prettyprint sequences ;" "{ 1 1 2 } [ <= ] monotonic? ." "t" }
"Testing if a sequence is decreasing:" "Testing if a sequence is decreasing:"
{ $example "{ 9 8 6 7 } [ < ] monotonic? ." "f" } { $example "USING: math prettyprint sequences ;" "{ 9 8 6 7 } [ < ] monotonic? ." "f" }
} ; } ;
{ monotonic? all-eq? all-equal? } related-words { monotonic? all-eq? all-equal? } related-words
@ -556,7 +558,7 @@ HELP: monotonic?
HELP: interleave HELP: interleave
{ $values { "seq" sequence } { "between" "a quotation" } { "quot" "a quotation with stack effect " { $snippet "( elt -- )" } } } { $values { "seq" sequence } { "between" "a quotation" } { "quot" "a quotation with stack effect " { $snippet "( elt -- )" } } }
{ $description "Applies " { $snippet "quot" } " to each element in turn, also invoking " { $snippet "between" } " in-between each pair of elements." } { $description "Applies " { $snippet "quot" } " to each element in turn, also invoking " { $snippet "between" } " in-between each pair of elements." }
{ $example "{ \"a\" \"b\" \"c\" } [ \"X\" write ] [ write ] interleave" "aXbXc" } ; { $example "USING: io sequences ;" "{ \"a\" \"b\" \"c\" } [ \"X\" write ] [ write ] interleave" "aXbXc" } ;
HELP: cache-nth HELP: cache-nth
{ $values { "i" "a non-negative integer" } { "seq" "a mutable sequence" } { "quot" "a quotation with stack effect " { $snippet "( i -- elt )" } } { "elt" object } } { $values { "i" "a non-negative integer" } { "seq" "a mutable sequence" } { "quot" "a quotation with stack effect " { $snippet "( i -- elt )" } } { "elt" object } }
@ -590,7 +592,7 @@ HELP: memq?
{ $description "Tests if the sequence contains the object." } { $description "Tests if the sequence contains the object." }
{ $examples { $examples
"This word uses identity comparison, so the following will most likely print " { $link f } ":" "This word uses identity comparison, so the following will most likely print " { $link f } ":"
{ $example "\"hello\" { \"hello\" } memq? ." "f" } { $example "USING: prettyprint sequences ;" "\"hello\" { \"hello\" } memq? ." "f" }
} ; } ;
HELP: remove HELP: remove
@ -629,6 +631,7 @@ HELP: push-new
{ $description "Removes all elements equal to " { $snippet "elt" } ", and adds " { $snippet "elt" } " at the end of the sequence." } { $description "Removes all elements equal to " { $snippet "elt" } ", and adds " { $snippet "elt" } " at the end of the sequence." }
{ $examples { $examples
{ $example { $example
"USING: namespaces prettyprint sequences ;"
"V{ \"beans\" \"salsa\" \"cheese\" } \"v\" set" "V{ \"beans\" \"salsa\" \"cheese\" } \"v\" set"
"\"nachos\" \"v\" get push-new" "\"nachos\" \"v\" get push-new"
"\"salsa\" \"v\" get push-new" "\"salsa\" \"v\" get push-new"
@ -645,7 +648,7 @@ HELP: add
{ $description "Outputs a new sequence obtained by adding " { $snippet "elt" } " at the end of " { $snippet "seq" } "." } { $description "Outputs a new sequence obtained by adding " { $snippet "elt" } " at the end of " { $snippet "seq" } "." }
{ $errors "Throws an error if the type of " { $snippet "elt" } " is not permitted in sequences of the same class as " { $snippet "seq1" } "." } { $errors "Throws an error if the type of " { $snippet "elt" } " is not permitted in sequences of the same class as " { $snippet "seq1" } "." }
{ $examples { $examples
{ $example "{ 1 2 3 } 4 add ." "{ 1 2 3 4 }" } { $example "USING: prettyprint sequences ;" "{ 1 2 3 } 4 add ." "{ 1 2 3 4 }" }
} ; } ;
HELP: add* HELP: add*
@ -653,7 +656,7 @@ HELP: add*
{ $description "Outputs a new sequence obtained by adding " { $snippet "elt" } " at the beginning of " { $snippet "seq" } "." } { $description "Outputs a new sequence obtained by adding " { $snippet "elt" } " at the beginning of " { $snippet "seq" } "." }
{ $errors "Throws an error if the type of " { $snippet "elt" } " is not permitted in sequences of the same class as " { $snippet "seq1" } "." } { $errors "Throws an error if the type of " { $snippet "elt" } " is not permitted in sequences of the same class as " { $snippet "seq1" } "." }
{ $examples { $examples
{ $example "{ 1 2 3 } 0 add* ." "{ 0 1 2 3 }" } { $example "USING: prettyprint sequences ;" "{ 1 2 3 } 0 add* ." "{ 0 1 2 3 }" }
} ; } ;
HELP: seq-diff HELP: seq-diff
@ -710,7 +713,7 @@ HELP: mismatch
HELP: flip HELP: flip
{ $values { "matrix" "a sequence of equal-length sequences" } { "newmatrix" "a sequence of equal-length sequences" } } { $values { "matrix" "a sequence of equal-length sequences" } { "newmatrix" "a sequence of equal-length sequences" } }
{ $description "Transposes the matrix; that is, rows become columns and columns become rows." } { $description "Transposes the matrix; that is, rows become columns and columns become rows." }
{ $examples { $example "{ { 1 2 3 } { 4 5 6 } } flip ." "{ { 1 4 } { 2 5 } { 3 6 } }" } } ; { $examples { $example "USING: prettyprint sequences ;" "{ { 1 2 3 } { 4 5 6 } } flip ." "{ { 1 4 } { 2 5 } { 3 6 } }" } } ;
HELP: exchange HELP: exchange
{ $values { "m" "a non-negative integer" } { "n" "a non-negative integer" } { "seq" "a mutable sequence" } } { $values { "m" "a non-negative integer" } { "n" "a non-negative integer" } { "seq" "a mutable sequence" } }
@ -728,12 +731,12 @@ HELP: padding
HELP: pad-left HELP: pad-left
{ $values { "seq" sequence } { "n" "a non-negative integer" } { "elt" object } { "padded" "a new sequence" } } { $values { "seq" sequence } { "n" "a non-negative integer" } { "elt" object } { "padded" "a new sequence" } }
{ $description "Outputs a new sequence consisting of " { $snippet "seq" } " padded on the left with enough repetitions of " { $snippet "elt" } " to have the result be of length " { $snippet "n" } "." } { $description "Outputs a new sequence consisting of " { $snippet "seq" } " padded on the left with enough repetitions of " { $snippet "elt" } " to have the result be of length " { $snippet "n" } "." }
{ $examples { $example "{ \"ab\" \"quux\" } [ 5 CHAR: - pad-left print ] each" "---ab\n-quux" } } ; { $examples { $example "USING: io sequences ;" "{ \"ab\" \"quux\" } [ 5 CHAR: - pad-left print ] each" "---ab\n-quux" } } ;
HELP: pad-right HELP: pad-right
{ $values { "seq" sequence } { "n" "a non-negative integer" } { "elt" object } { "padded" "a new sequence" } } { $values { "seq" sequence } { "n" "a non-negative integer" } { "elt" object } { "padded" "a new sequence" } }
{ $description "Outputs a new sequence consisting of " { $snippet "seq" } " padded on the right with enough repetitions of " { $snippet "elt" } " to have the result be of length " { $snippet "n" } "." } { $description "Outputs a new sequence consisting of " { $snippet "seq" } " padded on the right with enough repetitions of " { $snippet "elt" } " to have the result be of length " { $snippet "n" } "." }
{ $examples { $example "{ \"ab\" \"quux\" } [ 5 CHAR: - pad-right print ] each" "ab---\nquux-" } } ; { $examples { $example "USING: io sequences ;" "{ \"ab\" \"quux\" } [ 5 CHAR: - pad-right print ] each" "ab---\nquux-" } } ;
HELP: sequence= HELP: sequence=
{ $values { "seq1" sequence } { "seq2" sequence } { "?" "a boolean" } } { $values { "seq1" sequence } { "seq2" sequence } { "?" "a boolean" } }
@ -798,6 +801,7 @@ HELP: <column> ( seq n -- column )
{ $description "Outputs a new virtual sequence which presents a fixed column of a matrix represented as a sequence of rows." "The " { $snippet "i" } "th element of a column is the " { $snippet "n" } "th element of the " { $snippet "i" } "th element of" { $snippet "seq" } ". Every element of " { $snippet "seq" } " must be a sequence, and all sequences must have equal length." } { $description "Outputs a new virtual sequence which presents a fixed column of a matrix represented as a sequence of rows." "The " { $snippet "i" } "th element of a column is the " { $snippet "n" } "th element of the " { $snippet "i" } "th element of" { $snippet "seq" } ". Every element of " { $snippet "seq" } " must be a sequence, and all sequences must have equal length." }
{ $examples { $examples
{ $example { $example
"USING: arrays prettyprint sequences ;"
"{ { 1 2 3 } { 4 5 6 } { 7 8 9 } } 0 <column> >array ." "{ { 1 2 3 } { 4 5 6 } { 7 8 9 } } 0 <column> >array ."
"{ 1 4 7 }" "{ 1 4 7 }"
} }
@ -813,8 +817,8 @@ HELP: <repetition> ( len elt -- repetition )
{ $values { "len" "a non-negative integer" } { "elt" object } { "repetition" repetition } } { $values { "len" "a non-negative integer" } { "elt" object } { "repetition" repetition } }
{ $description "Creates a new " { $link repetition } "." } { $description "Creates a new " { $link repetition } "." }
{ $examples { $examples
{ $example "10 \"X\" <repetition> >array ." "{ \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" }" } { $example "USING: arrays prettyprint sequences ;" "10 \"X\" <repetition> >array ." "{ \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" \"X\" }" }
{ $example "10 \"X\" <repetition> >array concat ." "\"XXXXXXXXXX\"" } { $example "USING: prettyprint sequences ;" "10 \"X\" <repetition> concat ." "\"XXXXXXXXXX\"" }
} ; } ;
HELP: copy HELP: copy
{ $values { "src" sequence } { "i" "an index in " { $snippet "dest" } } { "dst" "a mutable sequence" } } { $values { "src" sequence } { "i" "an index in " { $snippet "dest" } } { "dst" "a mutable sequence" } }
@ -936,7 +940,7 @@ HELP: unclip
{ $values { "seq" sequence } { "rest" sequence } { "first" object } } { $values { "seq" sequence } { "rest" sequence } { "first" object } }
{ $description "Outputs a tail sequence and the first element of " { $snippet "seq" } "; the tail sequence consists of all elements of " { $snippet "seq" } " but the first." } { $description "Outputs a tail sequence and the first element of " { $snippet "seq" } "; the tail sequence consists of all elements of " { $snippet "seq" } " but the first." }
{ $examples { $examples
{ $example "{ 1 2 3 } unclip add ." "{ 2 3 1 }" } { $example "USING: prettyprint sequences ;" "{ 1 2 3 } unclip add ." "{ 2 3 1 }" }
} ; } ;
HELP: unclip-slice HELP: unclip-slice
@ -966,7 +970,7 @@ HELP: unfold
{ $description "Calls " { $snippet "pred" } " repeatedly. If the predicate yields " { $link f } ", stops, otherwise, calls " { $snippet "quot" } " to yield a value. Values are accumulated and returned in a sequence at the end." } { $description "Calls " { $snippet "pred" } " repeatedly. If the predicate yields " { $link f } ", stops, otherwise, calls " { $snippet "quot" } " to yield a value. Values are accumulated and returned in a sequence at the end." }
{ $examples { $examples
"The following example divides a number by two until we reach zero, and accumulates intermediate results:" "The following example divides a number by two until we reach zero, and accumulates intermediate results:"
{ $example "1337 [ dup 0 > ] [ 2/ dup ] [ ] unfold nip ." "{ 668 334 167 83 41 20 10 5 2 1 0 }" } { $example "USING: kernel math prettyprint sequences ;" "1337 [ dup 0 > ] [ 2/ dup ] [ ] unfold nip ." "{ 668 334 167 83 41 20 10 5 2 1 0 }" }
"The " { $snippet "tail" } " quotation is used when the predicate produces more than one output value. In this case, we have to drop this value even if the predicate fails in order for stack inference to calculate a stack effect for the " { $link unfold } " call:" "The " { $snippet "tail" } " quotation is used when the predicate produces more than one output value. In this case, we have to drop this value even if the predicate fails in order for stack inference to calculate a stack effect for the " { $link unfold } " call:"
{ $unchecked-example "[ 10 random dup 1 > ] [ ] [ drop ] unfold ." "{ 8 2 2 9 }" } { $unchecked-example "USING: kernel prettyprint random sequences ;" "[ 10 random dup 1 > ] [ ] [ drop ] unfold ." "{ 8 2 2 9 }" }
} ; } ;

View File

@ -68,7 +68,7 @@ HELP: reader-quot
HELP: slot-reader HELP: slot-reader
{ $class-description "The class of slot reader words." } { $class-description "The class of slot reader words." }
{ $examples { $examples
{ $example "USING: classes slots ;" "TUPLE: circle center radius ;" "\\ circle-center slot-reader? ." "t" } { $example "USING: classes prettyprint slots ;" "TUPLE: circle center radius ;" "\\ circle-center slot-reader? ." "t" }
} ; } ;
HELP: define-reader HELP: define-reader
@ -83,7 +83,7 @@ HELP: writer-effect
HELP: slot-writer HELP: slot-writer
{ $class-description "The class of slot writer words." } { $class-description "The class of slot writer words." }
{ $examples { $examples
{ $example "USING: classes slots ;" "TUPLE: circle center radius ;" "\\ set-circle-center slot-writer? ." "t" } { $example "USING: classes prettyprint slots ;" "TUPLE: circle center radius ;" "\\ set-circle-center slot-writer? ." "t" }
} ; } ;
HELP: define-writer HELP: define-writer

View File

@ -51,7 +51,7 @@ HELP: record-modified
$low-level-note ; $low-level-note ;
HELP: record-checksum HELP: record-checksum
{ $values { "source-file" source-file } { "contents" string } } { $values { "source-file" source-file } { "lines" "a sequence of strings" } }
{ $description "Records the CRC32 checksm of the source file's contents." } { $description "Records the CRC32 checksm of the source file's contents." }
$low-level-note ; $low-level-note ;

View File

@ -85,7 +85,7 @@ M: pathname where pathname-string 1 2array ;
M: pathname forget* M: pathname forget*
pathname-string forget-source ; pathname-string forget-source ;
: rollback-source-file ( source-file -- ) : rollback-source-file ( file -- )
dup source-file-definitions new-definitions get [ union ] 2map dup source-file-definitions new-definitions get [ union ] 2map
swap set-source-file-definitions ; swap set-source-file-definitions ;

View File

@ -33,7 +33,7 @@ HELP: last-split1
HELP: split HELP: split
{ $values { "seq" "a sequence" } { "separators" "a sequence" } { "pieces" "a new array" } } { $values { "seq" "a sequence" } { "separators" "a sequence" } { "pieces" "a new array" } }
{ $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } ", and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." } { $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } ", and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
{ $examples { $example "USE: splitting" "\"hello world-how are you?\" \" -\" split ." "{ \"hello\" \"world\" \"how\" \"are\" \"you?\" }" } } ; { $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split ." "{ \"hello\" \"world\" \"how\" \"are\" \"you?\" }" } } ;
HELP: groups HELP: groups
{ $class-description "Instances are virtual sequences whose elements are fixed-length subsequences or slices of an underlying sequence. Groups are mutable and resizable if the underlying sequence is mutable and resizable, respectively." { $class-description "Instances are virtual sequences whose elements are fixed-length subsequences or slices of an underlying sequence. Groups are mutable and resizable if the underlying sequence is mutable and resizable, respectively."
@ -51,7 +51,7 @@ HELP: <groups>
{ $description "Outputs a virtual sequence whose elements are subsequences consisting of groups of " { $snippet "n" } " elements from the underlying sequence." } { $description "Outputs a virtual sequence whose elements are subsequences consisting of groups of " { $snippet "n" } " elements from the underlying sequence." }
{ $examples { $examples
{ $example { $example
"USE: splitting" "USING: arrays kernel prettyprint sequences splitting ;"
"9 >array 3 <groups> dup reverse-here concat >array ." "{ 6 7 8 3 4 5 0 1 2 }" "9 >array 3 <groups> dup reverse-here concat >array ." "{ 6 7 8 3 4 5 0 1 2 }"
} }
} ; } ;
@ -61,7 +61,7 @@ HELP: <sliced-groups>
{ $description "Outputs a virtual sequence whose elements are slices consisting of groups of " { $snippet "n" } " elements from the underlying sequence." } { $description "Outputs a virtual sequence whose elements are slices consisting of groups of " { $snippet "n" } " elements from the underlying sequence." }
{ $examples { $examples
{ $example { $example
"USE: splitting" "USING: arrays kernel prettyprint sequences splitting ;"
"9 >array 3 <sliced-groups>" "9 >array 3 <sliced-groups>"
"dup [ reverse-here ] each concat >array ." "dup [ reverse-here ] each concat >array ."
"{ 2 1 0 5 4 3 8 7 6 }" "{ 2 1 0 5 4 3 8 7 6 }"
@ -90,5 +90,5 @@ HELP: string-lines
{ $values { "str" string } { "seq" "a sequence of strings" } } { $values { "str" string } { "seq" "a sequence of strings" } }
{ $description "Splits a string along line breaks." } { $description "Splits a string along line breaks." }
{ $examples { $examples
{ $example "USE: splitting" "\"Hello\\r\\nworld\\n\" string-lines ." "{ \"Hello\" \"world\" \"\" }" } { $example "USING: prettyprint splitting ;" "\"Hello\\r\\nworld\\n\" string-lines ." "{ \"Hello\" \"world\" \"\" }" }
} ; } ;

View File

@ -204,7 +204,7 @@ HELP: delimiter
HELP: parsing HELP: parsing
{ $syntax ": foo ... ; parsing" } { $syntax ": foo ... ; parsing" }
{ $description "Declares the most recently defined word as a parsing word." } { $description "Declares the most recently defined word as a parsing word." }
{ $examples "In the below example, the " { $snippet "world" } " word is never called, however its body references a parsing word which executes immediately:" { $example ": hello \"Hello parser!\" print ; parsing\n: world hello ;" "Hello parser!" } } ; { $examples "In the below example, the " { $snippet "world" } " word is never called, however its body references a parsing word which executes immediately:" { $example "USE: io" "<< : hello \"Hello parser!\" print ; parsing >>\n: world hello ;" "Hello parser!" } } ;
HELP: inline HELP: inline
{ $syntax ": foo ... ; inline" } { $syntax ": foo ... ; inline" }
@ -367,7 +367,7 @@ HELP: SYMBOL:
{ $syntax "SYMBOL: word" } { $syntax "SYMBOL: word" }
{ $values { "word" "a new word to define" } } { $values { "word" "a new word to define" } }
{ $description "Defines a new symbol word in the current vocabulary. Symbols push themselves on the stack when executed, and are used to identify variables (see " { $link "namespaces" } ") as well as for storing crufties in word properties (see " { $link "word-props" } ")." } { $description "Defines a new symbol word in the current vocabulary. Symbols push themselves on the stack when executed, and are used to identify variables (see " { $link "namespaces" } ") as well as for storing crufties in word properties (see " { $link "word-props" } ")." }
{ $examples { $example "SYMBOL: foo\nfoo ." "foo" } } ; { $examples { $example "USE: prettyprint" "SYMBOL: foo\nfoo ." "foo" } } ;
{ define-symbol POSTPONE: SYMBOL: } related-words { define-symbol POSTPONE: SYMBOL: } related-words
@ -424,19 +424,19 @@ HELP: "
{ $syntax "\"string...\"" } { $syntax "\"string...\"" }
{ $values { "string" "literal and escaped characters" } } { $values { "string" "literal and escaped characters" } }
{ $description "Reads from the input string until the next occurrence of " { $link POSTPONE: " } ", and appends the resulting string to the parse tree. String literals cannot span multiple lines. Strings containing the " { $link POSTPONE: " } " character and various other special characters can be read by inserting escape sequences." } { $description "Reads from the input string until the next occurrence of " { $link POSTPONE: " } ", and appends the resulting string to the parse tree. String literals cannot span multiple lines. Strings containing the " { $link POSTPONE: " } " character and various other special characters can be read by inserting escape sequences." }
{ $examples { $example "\"Hello\\nworld\" print" "Hello\nworld" } } ; { $examples { $example "USE: io" "\"Hello\\nworld\" print" "Hello\nworld" } } ;
HELP: SBUF" HELP: SBUF"
{ $syntax "SBUF\" string... \"" } { $syntax "SBUF\" string... \"" }
{ $values { "string" "literal and escaped characters" } } { $values { "string" "literal and escaped characters" } }
{ $description "Reads from the input string until the next occurrence of " { $link POSTPONE: " } ", converts the string to a string buffer, and appends it to the parse tree." } { $description "Reads from the input string until the next occurrence of " { $link POSTPONE: " } ", converts the string to a string buffer, and appends it to the parse tree." }
{ $examples { $example "SBUF\" Hello world\" >string print" "Hello world" } } ; { $examples { $example "USING: io strings ;" "SBUF\" Hello world\" >string print" "Hello world" } } ;
HELP: P" HELP: P"
{ $syntax "P\" pathname\"" } { $syntax "P\" pathname\"" }
{ $values { "pathname" "a pathname string" } } { $values { "pathname" "a pathname string" } }
{ $description "Reads from the input string until the next occurrence of " { $link POSTPONE: " } ", creates a new " { $link pathname } ", and appends it to the parse tree." } { $description "Reads from the input string until the next occurrence of " { $link POSTPONE: " } ", creates a new " { $link pathname } ", and appends it to the parse tree." }
{ $examples { $example "USE: io.files" "P\" foo.txt\" pathname-string print" "foo.txt" } } ; { $examples { $example "USING: io io.files ;" "P\" foo.txt\" pathname-string print" "foo.txt" } } ;
HELP: ( HELP: (
{ $syntax "( inputs -- outputs )" } { $syntax "( inputs -- outputs )" }
@ -460,19 +460,19 @@ HELP: HEX:
{ $syntax "HEX: integer" } { $syntax "HEX: integer" }
{ $values { "integer" "hexadecimal digits (0-9, a-f, A-F)" } } { $values { "integer" "hexadecimal digits (0-9, a-f, A-F)" } }
{ $description "Adds an integer read from a hexadecimal literal to the parse tree." } { $description "Adds an integer read from a hexadecimal literal to the parse tree." }
{ $examples { $example "HEX: ff ." "255" } } ; { $examples { $example "USE: prettyprint" "HEX: ff ." "255" } } ;
HELP: OCT: HELP: OCT:
{ $syntax "OCT: integer" } { $syntax "OCT: integer" }
{ $values { "integer" "octal digits (0-7)" } } { $values { "integer" "octal digits (0-7)" } }
{ $description "Adds an integer read from an octal literal to the parse tree." } { $description "Adds an integer read from an octal literal to the parse tree." }
{ $examples { $example "OCT: 31337 ." "13023" } } ; { $examples { $example "USE: prettyprint" "OCT: 31337 ." "13023" } } ;
HELP: BIN: HELP: BIN:
{ $syntax "BIN: integer" } { $syntax "BIN: integer" }
{ $values { "integer" "binary digits (0 and 1)" } } { $values { "integer" "binary digits (0 and 1)" } }
{ $description "Adds an integer read from an binary literal to the parse tree." } { $description "Adds an integer read from an binary literal to the parse tree." }
{ $examples { $example "BIN: 100 ." "4" } } ; { $examples { $example "USE: prettyprint" "BIN: 100 ." "4" } } ;
HELP: GENERIC: HELP: GENERIC:
{ $syntax "GENERIC: word" } { $syntax "GENERIC: word" }
@ -500,6 +500,7 @@ HELP: HOOK:
{ $description "Defines a new hook word in the current vocabulary. Hook words are generic words which dispatch on the value of a variable, so methods are defined with " { $link POSTPONE: M: } ". Hook words differ from other generic words in that the dispatch value is removed from the stack before the chosen method is called." } { $description "Defines a new hook word in the current vocabulary. Hook words are generic words which dispatch on the value of a variable, so methods are defined with " { $link POSTPONE: M: } ". Hook words differ from other generic words in that the dispatch value is removed from the stack before the chosen method is called." }
{ $examples { $examples
{ $example { $example
"USING: io namespaces ;"
"SYMBOL: transport" "SYMBOL: transport"
"TUPLE: land-transport ;" "TUPLE: land-transport ;"
"TUPLE: air-transport ;" "TUPLE: air-transport ;"

View File

@ -73,8 +73,10 @@ HELP: self
{ $description "Pushes the currently-running thread." } ; { $description "Pushes the currently-running thread." } ;
HELP: <thread> HELP: <thread>
{ $values { "quot" quotation } { "name" string } { "error-handler" quotation } } { $values { "quot" quotation } { "name" string } { "thread" thread } }
{ $description "Low-level thread constructor. The thread runs the quotation when spawned; the name is simply used to identify the thread for debugging purposes. The error handler is called if the thread's quotation throws an unhandled error; it should either print the error or notify another thread." } { $description "Low-level thread constructor. The thread runs the quotation when spawned."
$nl
"The name is used to identify the thread for debugging purposes; see " { $link "tools.threads" } "." }
{ $notes "In most cases, user code should call " { $link spawn } " instead, however for control over the error handler quotation, threads can be created with " { $link <thread> } " then passed to " { $link (spawn) } "." } ; { $notes "In most cases, user code should call " { $link spawn } " instead, however for control over the error handler quotation, threads can be created with " { $link <thread> } " then passed to " { $link (spawn) } "." } ;
HELP: run-queue HELP: run-queue
@ -96,7 +98,7 @@ HELP: sleep-queue
{ $var-description "A " { $link min-heap } " storing the queue of sleeping threads." } ; { $var-description "A " { $link min-heap } " storing the queue of sleeping threads." } ;
HELP: sleep-time HELP: sleep-time
{ $values { "ms" "a non-negative integer or " { $link f } } } { $values { "ms/f" "a non-negative integer or " { $link f } } }
{ $description "Outputs the time until the next sleeping thread is scheduled to wake up, which could be zero if there are threads in the run queue, or threads which need to wake up right now. If there are no runnable or sleeping threads, outputs " { $link f } "." } ; { $description "Outputs the time until the next sleeping thread is scheduled to wake up, which could be zero if there are threads in the run queue, or threads which need to wake up right now. If there are no runnable or sleeping threads, outputs " { $link f } "." } ;
HELP: stop HELP: stop
@ -122,11 +124,15 @@ HELP: interrupt
{ $description "Interrupts a sleeping thread." } ; { $description "Interrupts a sleeping thread." } ;
HELP: suspend HELP: suspend
{ $values { "quot" "a quotation with stack effect " { $snippet "( thread -- )" } } { "obj" object } } { $values { "quot" "a quotation with stack effect " { $snippet "( thread -- )" } } { "state" string } { "obj" object } }
{ $description "Suspends the current thread and passes it to the quotation. After the quotation returns, control yields to the next runnable thread and the current thread does not execute again until it is resumed, and so the quotation must arrange for another thread to later resume the suspended thread with a call to " { $link resume } " or " { $link resume-with } "." } ; { $description "Suspends the current thread and passes it to the quotation."
$nl
"After the quotation returns, control yields to the next runnable thread and the current thread does not execute again until it is resumed, and so the quotation must arrange for another thread to later resume the suspended thread with a call to " { $link resume } " or " { $link resume-with } "."
$nl
"The status string is for debugging purposes; see " { $link "tools.threads" } "." } ;
HELP: spawn HELP: spawn
{ $values { "quot" quotation } { "name" string } } { $values { "quot" quotation } { "name" string } { "thread" thread } }
{ $description "Spawns a new thread. The thread begins executing the given quotation; the name is for debugging purposes. The new thread begins running immediately and the current thread is added to the end of the run queue." { $description "Spawns a new thread. The thread begins executing the given quotation; the name is for debugging purposes. The new thread begins running immediately and the current thread is added to the end of the run queue."
$nl $nl
"The new thread begins with an empty data stack, an empty retain stack, and an empty catch stack. The name stack is inherited from the parent thread but may be cleared with " { $link init-namespaces } "." } "The new thread begins with an empty data stack, an empty retain stack, and an empty catch stack. The name stack is inherited from the parent thread but may be cleared with " { $link init-namespaces } "." }
@ -138,7 +144,7 @@ $nl
} ; } ;
HELP: spawn-server HELP: spawn-server
{ $values { "quot" "a quotation with stack effect " { $snippet "( -- ? )" } } { "name" string } } { $values { "quot" "a quotation with stack effect " { $snippet "( -- ? )" } } { "name" string } { "thread" thread } }
{ $description "Convenience wrapper around " { $link spawn } " which repeatedly calls the quotation in a new thread until it outputs " { $link f } "." } { $description "Convenience wrapper around " { $link spawn } " which repeatedly calls the quotation in a new thread until it outputs " { $link f } "." }
{ $examples { $examples
"A thread that runs forever:" "A thread that runs forever:"

View File

@ -180,6 +180,7 @@ HELP: construct-empty
{ $description "Creates a new instance of " { $snippet "class" } " with all slots initially set to " { $link f } "." } { $description "Creates a new instance of " { $snippet "class" } " with all slots initially set to " { $link f } "." }
{ $examples { $examples
{ $example { $example
"USING: kernel prettyprint ;"
"TUPLE: employee number name department ;" "TUPLE: employee number name department ;"
"employee construct-empty ." "employee construct-empty ."
"T{ employee f f f f }" "T{ employee f f f f }"

View File

@ -5,7 +5,7 @@ IN: vectors
<PRIVATE <PRIVATE
: array>vector ( byte-array capacity -- byte-vector ) : array>vector ( array length -- vector )
vector construct-boa ; inline vector construct-boa ; inline
PRIVATE> PRIVATE>

View File

@ -65,12 +65,12 @@ HELP: load-help?
{ $var-description "If set to a true value, documentation will be automatically loaded when vocabularies are loaded. This variable is usually on, except when Factor has been bootstrapped without the help system." } ; { $var-description "If set to a true value, documentation will be automatically loaded when vocabularies are loaded. This variable is usually on, except when Factor has been bootstrapped without the help system." } ;
HELP: load-source HELP: load-source
{ $values { "root" "a pathname string" } { "name" "a vocabulary name" } } { $values { "vocab" "a vocabulary specifier" } }
{ $description "Loads a vocabulary's source code from the specified vocabulary root." } ; { $description "Loads a vocabulary's source code." } ;
HELP: load-docs HELP: load-docs
{ $values { "root" "a pathname string" } { "name" "a vocabulary name" } } { $values { "vocab" "a vocabulary specifier" } }
{ $description "If " { $link load-help? } " is on, loads a vocabulary's documentation from the specified vocabulary root." } ; { $description "If " { $link load-help? } " is on, loads a vocabulary's documentation." } ;
HELP: reload HELP: reload
{ $values { "name" "a vocabulary name" } } { $values { "name" "a vocabulary name" } }

View File

@ -75,7 +75,7 @@ SYMBOL: load-help?
: source-wasn't-loaded f swap set-vocab-source-loaded? ; : source-wasn't-loaded f swap set-vocab-source-loaded? ;
: load-source ( vocab-link -- ) : load-source ( vocab -- )
[ source-wasn't-loaded ] keep [ source-wasn't-loaded ] keep
[ vocab-source-path bootstrap-file ] keep [ vocab-source-path bootstrap-file ] keep
source-was-loaded ; source-was-loaded ;
@ -84,7 +84,7 @@ SYMBOL: load-help?
: docs-weren't-loaded f swap set-vocab-docs-loaded? ; : docs-weren't-loaded f swap set-vocab-docs-loaded? ;
: load-docs ( vocab-link -- ) : load-docs ( vocab -- )
load-help? get [ load-help? get [
[ docs-weren't-loaded ] keep [ docs-weren't-loaded ] keep
[ vocab-docs-path ?run-file ] keep [ vocab-docs-path ?run-file ] keep

View File

@ -197,7 +197,7 @@ HELP: execute ( word -- )
{ $values { "word" word } } { $values { "word" word } }
{ $description "Executes a word." } { $description "Executes a word." }
{ $examples { $examples
{ $example ": twice dup execute execute ;\n: hello \"Hello\" print ;\n\\ hello twice" "Hello\nHello" } { $example "USING: kernel io words ;" ": twice dup execute execute ;\n: hello \"Hello\" print ;\n\\ hello twice" "Hello\nHello" }
} ; } ;
HELP: word-props ( word -- props ) HELP: word-props ( word -- props )
@ -322,7 +322,7 @@ HELP: create
HELP: constructor-word HELP: constructor-word
{ $values { "name" string } { "vocab" string } { "word" word } } { $values { "name" string } { "vocab" string } { "word" word } }
{ $description "Creates a new word, surrounding " { $snippet "name" } " in angle brackets." } { $description "Creates a new word, surrounding " { $snippet "name" } " in angle brackets." }
{ $examples { $example "\"salmon\" \"scratchpad\" constructor-word ." "<salmon>" } } ; { $examples { $example "USING: prettyprint words ;" "\"salmon\" \"scratchpad\" constructor-word ." "<salmon>" } } ;
HELP: forget-word HELP: forget-word
{ $values { "word" word } } { $values { "word" word } }

View File

@ -9,7 +9,7 @@ HELP: add-alarm
{ $description "Creates and registers an alarm. If " { $snippet "frequency" } " is " { $link f } ", this will be a one-time alarm, otherwise it will fire with the given frequency. The quotation will be called from the alarm thread." } ; { $description "Creates and registers an alarm. If " { $snippet "frequency" } " is " { $link f } ", this will be a one-time alarm, otherwise it will fire with the given frequency. The quotation will be called from the alarm thread." } ;
HELP: later HELP: later
{ $values { "quot" quotation } { "time" duration } { "alarm" alarm } } { $values { "quot" quotation } { "dt" duration } { "alarm" alarm } }
{ $description "Creates and registers an alarm which calls the quotation once at " { $snippet "time" } { $link from-now } "." } ; { $description "Creates and registers an alarm which calls the quotation once at " { $snippet "time" } { $link from-now } "." } ;
HELP: cancel-alarm HELP: cancel-alarm

View File

@ -7,7 +7,7 @@ HELP: generate
{ $description "Loop until the generator quotation generates an object that satisfies predicate quotation." } { $description "Loop until the generator quotation generates an object that satisfies predicate quotation." }
{ $unchecked-example { $unchecked-example
"! Generate a random 20-bit prime number congruent to 3 (mod 4)" "! Generate a random 20-bit prime number congruent to 3 (mod 4)"
"USE: math.miller-rabin" "USING: combinators.lib math math.miller-rabin prettyprint ;"
"[ 20 random-prime ] [ 4 mod 3 = ] generate ." "[ 20 random-prime ] [ 4 mod 3 = ] generate ."
"526367" "526367"
} ; } ;
@ -20,8 +20,8 @@ HELP: ndip
"stack. The quotation can consume and produce any number of items." "stack. The quotation can consume and produce any number of items."
} }
{ $examples { $examples
{ $example "USE: combinators.lib" "1 2 [ dup ] 1 ndip .s" "1\n1\n2" } { $example "USING: combinators.lib kernel prettyprint ;" "1 2 [ dup ] 1 ndip .s" "1\n1\n2" }
{ $example "USE: combinators.lib" "1 2 3 [ drop ] 2 ndip .s" "2\n3" } { $example "USING: combinators.lib kernel prettyprint ;" "1 2 3 [ drop ] 2 ndip .s" "2\n3" }
} }
{ $see-also dip dipd } ; { $see-also dip dipd } ;
@ -32,7 +32,7 @@ HELP: nslip
"removed from the stack, the quotation called, and the items restored." "removed from the stack, the quotation called, and the items restored."
} }
{ $examples { $examples
{ $example "USE: combinators.lib" "[ 99 ] 1 2 3 4 5 5 nslip .s" "99\n1\n2\n3\n4\n5" } { $example "USING: combinators.lib prettyprint ;" "[ 99 ] 1 2 3 4 5 5 nslip .s" "99\n1\n2\n3\n4\n5" }
} }
{ $see-also slip nkeep } ; { $see-also slip nkeep } ;
@ -43,7 +43,7 @@ HELP: nkeep
"saved, the quotation called, and the items restored." "saved, the quotation called, and the items restored."
} }
{ $examples { $examples
{ $example "USE: combinators.lib" "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep .s" "99\n1\n2\n3\n4\n5" } { $example "USING: combinators.lib kernel prettyprint ;" "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep .s" "99\n1\n2\n3\n4\n5" }
} }
{ $see-also keep nslip } ; { $see-also keep nslip } ;

View File

@ -2,9 +2,7 @@ USING: help.markup help.syntax concurrency.messaging threads ;
IN: concurrency.distributed IN: concurrency.distributed
HELP: local-node HELP: local-node
{ $values { "addrspec" "an address specifier" } { $var-description "A variable containing the node the current thread is running on." } ;
}
{ $description "Return the node the current thread is running on." } ;
HELP: start-node HELP: start-node
{ $values { "port" "a port number between 0 and 65535" } } { $values { "port" "a port number between 0 and 65535" } }

View File

@ -6,7 +6,7 @@ namespaces kernel io.encodings.binary ;
QUALIFIED: io.sockets QUALIFIED: io.sockets
IN: concurrency.distributed IN: concurrency.distributed
SYMBOL: local-node ( -- addrspec ) SYMBOL: local-node
: handle-node-client ( -- ) : handle-node-client ( -- )
deserialize first2 get-process send ; deserialize first2 get-process send ;

View File

@ -1,4 +1,5 @@
USING: help.markup help.syntax sequences kernel quotations ; USING: help.markup help.syntax sequences kernel quotations
calendar ;
IN: concurrency.locks IN: concurrency.locks
HELP: lock HELP: lock
@ -12,11 +13,15 @@ HELP: <reentrant-lock>
{ $values { "lock" lock } } { $values { "lock" lock } }
{ $description "Creates a reentrant lock." } ; { $description "Creates a reentrant lock." } ;
HELP: with-lock HELP: with-lock-timeout
{ $values { "lock" lock } { "timeout" "a timeout in milliseconds or " { $link f } } { "quot" quotation } } { $values { "lock" lock } { "timeout" "a " { $link duration } " or " { $link f } } { "quot" quotation } }
{ $description "Calls the quotation, ensuring that only one thread executes with the lock held at a time. If another thread is holding the lock, blocks until the thread releases the lock." } { $description "Calls the quotation, ensuring that only one thread executes with the lock held at a time. If another thread is holding the lock, blocks until the thread releases the lock." }
{ $errors "Throws an error if the lock could not be acquired before the timeout expires. A timeout value of " { $link f } " means the thread is willing to wait indefinitely." } ; { $errors "Throws an error if the lock could not be acquired before the timeout expires. A timeout value of " { $link f } " means the thread is willing to wait indefinitely." } ;
HELP: with-lock
{ $values { "lock" lock } { "quot" quotation } }
{ $description "Calls the quotation, ensuring that only one thread executes with the lock held at a time. If another thread is holding the lock, blocks until the thread releases the lock." } ;
ARTICLE: "concurrency.locks.mutex" "Mutual-exclusion locks" ARTICLE: "concurrency.locks.mutex" "Mutual-exclusion locks"
"A mutual-exclusion lock ensures that only one thread executes with the lock held at a time. They are used to protect critical sections so that certain operations appear to be atomic to other threads." "A mutual-exclusion lock ensures that only one thread executes with the lock held at a time. They are used to protect critical sections so that certain operations appear to be atomic to other threads."
$nl $nl
@ -24,21 +29,30 @@ $nl
{ $subsection lock } { $subsection lock }
{ $subsection <lock> } { $subsection <lock> }
{ $subsection <reentrant-lock> } { $subsection <reentrant-lock> }
{ $subsection with-lock } ; { $subsection with-lock }
{ $subsection with-lock-timeout } ;
HELP: rw-lock HELP: rw-lock
{ $class-description "The class of reader/writer locks." } ; { $class-description "The class of reader/writer locks." } ;
HELP: with-read-lock HELP: with-read-lock-timeout
{ $values { "lock" lock } { "timeout" "a timeout in milliseconds or " { $link f } } { "quot" quotation } } { $values { "lock" lock } { "timeout" "a " { $link duration } " or " { $link f } } { "quot" quotation } }
{ $description "Calls the quotation, ensuring that no other thread is holding a write lock at the same time. If another thread is holding a write lock, blocks until the thread releases the lock." } { $description "Calls the quotation, ensuring that no other thread is holding a write lock at the same time. If another thread is holding a write lock, blocks until the thread releases the lock." }
{ $errors "Throws an error if the lock could not be acquired before the timeout expires. A timeout value of " { $link f } " means the thread is willing to wait indefinitely." } ; { $errors "Throws an error if the lock could not be acquired before the timeout expires. A timeout value of " { $link f } " means the thread is willing to wait indefinitely." } ;
HELP: with-write-lock HELP: with-read-lock
{ $values { "lock" lock } { "timeout" "a timeout in milliseconds or " { $link f } } { "quot" quotation } } { $values { "lock" lock } { "quot" quotation } }
{ $description "Calls the quotation, ensuring that no other thread is holding a write lock at the same time. If another thread is holding a write lock, blocks until the thread releases the lock." } ;
HELP: with-write-lock-timeout
{ $values { "lock" lock } { "timeout" "a " { $link duration } " or " { $link f } } { "quot" quotation } }
{ $description "Calls the quotation, ensuring that no other thread is holding a read or write lock at the same time. If another thread is holding a read or write lock, blocks until the thread releases the lock." } { $description "Calls the quotation, ensuring that no other thread is holding a read or write lock at the same time. If another thread is holding a read or write lock, blocks until the thread releases the lock." }
{ $errors "Throws an error if the lock could not be acquired before the timeout expires. A timeout value of " { $link f } " means the thread is willing to wait indefinitely." } ; { $errors "Throws an error if the lock could not be acquired before the timeout expires. A timeout value of " { $link f } " means the thread is willing to wait indefinitely." } ;
HELP: with-write-lock
{ $values { "lock" lock } { "quot" quotation } }
{ $description "Calls the quotation, ensuring that no other thread is holding a read or write lock at the same time. If another thread is holding a read or write lock, blocks until the thread releases the lock." } ;
ARTICLE: "concurrency.locks.rw" "Read-write locks" ARTICLE: "concurrency.locks.rw" "Read-write locks"
"A read-write lock encapsulates a common pattern in the implementation of concurrent data structures, where one wishes to ensure that a thread is able to see a consistent view of the structure for a period of time, during which no other thread modifies the structure." "A read-write lock encapsulates a common pattern in the implementation of concurrent data structures, where one wishes to ensure that a thread is able to see a consistent view of the structure for a period of time, during which no other thread modifies the structure."
$nl $nl
@ -50,7 +64,10 @@ $nl
{ $subsection rw-lock } { $subsection rw-lock }
{ $subsection <rw-lock> } { $subsection <rw-lock> }
{ $subsection with-read-lock } { $subsection with-read-lock }
{ $subsection with-write-lock } ; { $subsection with-write-lock }
"Versions of the above that take a timeout duration:"
{ $subsection with-read-lock-timeout }
{ $subsection with-write-lock-timeout } ;
ARTICLE: "concurrency.locks" "Locks" ARTICLE: "concurrency.locks" "Locks"
"A " { $emphasis "lock" } " is an object protecting a critical region of code, enforcing a particular mutual-exclusion policy. The " { $vocab-link "concurrency.locks" } " vocabulary implements two types of locks:" "A " { $emphasis "lock" } " is an object protecting a critical region of code, enforcing a particular mutual-exclusion policy. The " { $vocab-link "concurrency.locks" } " vocabulary implements two types of locks:"

View File

@ -1,12 +1,12 @@
! Copyright (C) 2006 Chris Double. ! Copyright (C) 2006 Chris Double.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: help.syntax help.markup concurrency.messaging.private USING: help.syntax help.markup concurrency.messaging.private
threads kernel arrays quotations ; threads kernel arrays quotations threads strings ;
IN: concurrency.messaging IN: concurrency.messaging
HELP: send HELP: send
{ $values { "message" object } { $values { "message" object }
{ "thread" "a thread object" } { "thread" thread }
} }
{ $description "Send the message to the thread by placing it in the threades mailbox. This is an asynchronous operation and will return immediately. The receving thread will act on the message the next time it retrieves that item from its mailbox (usually using the " { $link receive } " word. The message can be any Factor object. For destinations that are instances of remote-thread the message must be a serializable Factor type." } { $description "Send the message to the thread by placing it in the threades mailbox. This is an asynchronous operation and will return immediately. The receving thread will act on the message the next time it retrieves that item from its mailbox (usually using the " { $link receive } " word. The message can be any Factor object. For destinations that are instances of remote-thread the message must be a serializable Factor type." }
{ $see-also receive receive-if } ; { $see-also receive receive-if } ;
@ -26,7 +26,8 @@ HELP: receive-if
HELP: spawn-linked HELP: spawn-linked
{ $values { "quot" quotation } { $values { "quot" quotation }
{ "thread" "a thread object" } { "name" string }
{ "thread" thread }
} }
{ $description "Start a thread which runs the given quotation. If that quotation throws an error which is not caught then the error will get propagated to the thread that spawned it. This can be used to set up 'supervisor' threades that restart child threades that crash due to uncaught errors.\n" } { $description "Start a thread which runs the given quotation. If that quotation throws an error which is not caught then the error will get propagated to the thread that spawned it. This can be used to set up 'supervisor' threades that restart child threades that crash due to uncaught errors.\n" }
{ $see-also spawn } ; { $see-also spawn } ;

View File

@ -7,7 +7,7 @@ USING: kernel threads concurrency.mailboxes continuations
namespaces assocs random ; namespaces assocs random ;
IN: concurrency.messaging IN: concurrency.messaging
GENERIC: send ( message process -- ) GENERIC: send ( message thread -- )
: mailbox-of ( thread -- mailbox ) : mailbox-of ( thread -- mailbox )
dup thread-mailbox [ ] [ dup thread-mailbox [ ] [

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2008 Chris Double, Slava Pestov. ! Copyright (C) 2005, 2008 Chris Double, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: concurrency.messaging kernel arrays USING: concurrency.messaging kernel arrays
continuations help.markup help.syntax quotations ; continuations help.markup help.syntax quotations calendar ;
IN: concurrency.promises IN: concurrency.promises
HELP: promise HELP: promise
@ -12,12 +12,12 @@ HELP: promise-fulfilled?
{ $description "Tests if " { $link fulfill } " has previously been called on the promise, in which case " { $link ?promise } " will return immediately without blocking." } ; { $description "Tests if " { $link fulfill } " has previously been called on the promise, in which case " { $link ?promise } " will return immediately without blocking." } ;
HELP: ?promise-timeout HELP: ?promise-timeout
{ $values { "promise" promise } { "timeout" "a timeout in milliseconds or " { $link f } } { "value" object } } { $values { "promise" promise } { "timeout" "a " { $link duration } " or " { $link f } } { "result" object } }
{ $description "Waits for another thread to fulfill a promise, returning immediately if the promise has already been fulfilled. A timeout of " { $link f } " indicates that the thread may block indefinitely, otherwise it will wait up to " { $snippet "timeout" } " milliseconds." } { $description "Waits for another thread to fulfill a promise, returning immediately if the promise has already been fulfilled. A timeout of " { $link f } " indicates that the thread may block indefinitely, otherwise it will wait up to " { $snippet "timeout" } " milliseconds." }
{ $errors "Throws an error if the timeout expires before the promise has been fulfilled." } ; { $errors "Throws an error if the timeout expires before the promise has been fulfilled." } ;
HELP: ?promise HELP: ?promise
{ $values { "promise" promise } { "value" object } } { $values { "promise" promise } { "result" object } }
{ $description "Waits for another thread to fulfill a promise, returning immediately if the promise has already been fulfilled." } ; { $description "Waits for another thread to fulfill a promise, returning immediately if the promise has already been fulfilled." } ;
HELP: fulfill HELP: fulfill

View File

@ -9,12 +9,12 @@ HELP: <semaphore>
{ $description "Creates a counting semaphore with the specified initial count." } ; { $description "Creates a counting semaphore with the specified initial count." } ;
HELP: acquire-timeout HELP: acquire-timeout
{ $values { "semaphore" semaphore } { "timeout" "a " { $link duration } " or " { $link f } } { "value" object } } { $values { "semaphore" semaphore } { "timeout" "a " { $link duration } " or " { $link f } } }
{ $description "If the semaphore has a non-zero count, decrements it and returns immediately. Otherwise, if the timeout is " { $link f } ", waits indefinitely for the semaphore to be released. If the timeout is not " { $link f } ", waits a certain period of time, and if the semaphore still has not been released, throws an error." } { $description "If the semaphore has a non-zero count, decrements it and returns immediately. Otherwise, if the timeout is " { $link f } ", waits indefinitely for the semaphore to be released. If the timeout is not " { $link f } ", waits a certain period of time, and if the semaphore still has not been released, throws an error." }
{ $errors "Throws an error if the timeout expires before the semaphore is released." } ; { $errors "Throws an error if the timeout expires before the semaphore is released." } ;
HELP: acquire HELP: acquire
{ $values { "semaphore" semaphore } { "value" object } } { $values { "semaphore" semaphore } }
{ $description "If the semaphore has a non-zero count, decrements it and returns immediately. Otherwise, waits for it to be released." } ; { $description "If the semaphore has a non-zero count, decrements it and returns immediately. Otherwise, waits for it to be released." } ;
HELP: release HELP: release

View File

@ -3,19 +3,19 @@ math.private ;
IN: crypto.common IN: crypto.common
HELP: >32-bit HELP: >32-bit
{ $values { "x" "an integer" } { "y" "an integer" } } { $values { "x" integer } { "y" integer } }
{ $description "Used to implement 32-bit integer overflow." } ; { $description "Used to implement 32-bit integer overflow." } ;
HELP: >64-bit HELP: >64-bit
{ $values { "x" "an integer" } { "y" "an integer" } } { $values { "x" integer } { "y" integer } }
{ $description "Used to implement 64-bit integer overflow." } ; { $description "Used to implement 64-bit integer overflow." } ;
HELP: bitroll HELP: bitroll
{ $values { "x" "an integer (input)" } { "s" "an integer (shift)" } { "w" "an integer (wrap)" } { "y" "an integer" } } { $values { "x" "an integer (input)" } { "s" "an integer (shift)" } { "w" "an integer (wrap)" } { "y" integer } }
{ $description "Roll n by s bits to the left, wrapping around after w bits." } { $description "Roll n by s bits to the left, wrapping around after w bits." }
{ $examples { $examples
{ $example "USE: crypto.common" "1 -1 32 bitroll .b" "10000000000000000000000000000000" } { $example "USING: crypto.common prettyprint ;" "1 -1 32 bitroll .b" "10000000000000000000000000000000" }
{ $example "USE: crypto.common" "HEX: ffff0000 8 32 bitroll .h" "ff0000ff" } { $example "USING: crypto.common prettyprint ;" "HEX: ffff0000 8 32 bitroll .h" "ff0000ff" }
} ; } ;
@ -23,7 +23,7 @@ HELP: hex-string
{ $values { "seq" "a sequence" } { "str" "a string" } } { $values { "seq" "a sequence" } { "str" "a string" } }
{ $description "Converts a sequence of values from 0-255 to a string of hex numbers from 0-ff." } { $description "Converts a sequence of values from 0-255 to a string of hex numbers from 0-ff." }
{ $examples { $examples
{ $example "USE: crypto.common" "B{ 1 2 3 4 } hex-string print" "01020304" } { $example "USING: crypto.common io ;" "B{ 1 2 3 4 } hex-string print" "01020304" }
} }
{ $notes "Numbers are zero-padded on the left." } ; { $notes "Numbers are zero-padded on the left." } ;

View File

@ -1,4 +1,4 @@
USING: kernel db.sql ; USING: kernel namespaces db.sql sequences math ;
IN: db.sql.tests IN: db.sql.tests
TUPLE: person name age ; TUPLE: person name age ;

View File

@ -1,6 +1,6 @@
USING: help.markup help.syntax ; USING: help.markup help.syntax ;
IN: farkup IN: farkup
HELP: parse-farkup HELP: convert-farkup
{ $values { "string" "a string" } { "string'" "a string" } } { $values { "string" "a string" } { "string'" "a string" } }
{ $description "Parse a string as farkup (Factor mARKUP) and output the result aas an string of HTML." } ; { $description "Parse a string as farkup (Factor mARKUP) and output the result aas an string of HTML." } ;

View File

@ -1,4 +1,5 @@
USING: help.crossref help.topics help.syntax help.markup ; USING: help.topics help.syntax help.markup ;
IN: help.crossref
HELP: article-children HELP: article-children
{ $values { "topic" "an article name or a word" } { "seq" "a new sequence" } } { $values { "topic" "an article name or a word" } { "seq" "a new sequence" } }
@ -12,7 +13,7 @@ HELP: help-path
{ $values { "topic" "an article name or a word" } { "seq" "a new sequence" } } { $values { "topic" "an article name or a word" } { "seq" "a new sequence" } }
{ $description "Outputs a sequence of all help articles which contain " { $snippet "topic" } " as a subsection, traversing all the way up to the root." } { $description "Outputs a sequence of all help articles which contain " { $snippet "topic" } " as a subsection, traversing all the way up to the root." }
{ $examples { $examples
{ $example "USE: help.crossref" "\"sequences\" help-path ." "{ \"collections\" \"handbook\" }" } { $example "USING: help.crossref prettyprint ;" "\"sequences\" help-path ." "{ \"collections\" \"handbook\" }" }
} ; } ;
HELP: xref-article HELP: xref-article

View File

@ -0,0 +1,8 @@
IN: help.handbook.tests
USING: help tools.test ;
[ ] [ "article-index" help ] unit-test
[ ] [ "primitive-index" help ] unit-test
[ ] [ "error-index" help ] unit-test
[ ] [ "type-index" help ] unit-test
[ ] [ "class-index" help ] unit-test

View File

@ -230,17 +230,17 @@ HELP: $examples
{ $values { "element" "a markup element" } } { $values { "element" "a markup element" } }
{ $description "Prints a heading followed by some examples. Word documentation should include examples, at least if the usage of the word is not entirely obvious." } { $description "Prints a heading followed by some examples. Word documentation should include examples, at least if the usage of the word is not entirely obvious." }
{ $examples { $examples
{ $markup-example { $examples { $example "2 2 + ." "4" } } } { $markup-example { $examples { $example "USING: math prettyprint ;" "2 2 + ." "4" } } }
} ; } ;
HELP: $example HELP: $example
{ $values { "element" "a markup element of the form " { $snippet "{ inputs... output }" } } } { $values { "element" "a markup element of the form " { $snippet "{ inputs... output }" } } }
{ $description "Prints a clickable example with sample output. The markup element must be an array of strings. All but the last string are joined by newlines and taken as the input text, and the last string is the output. The example becomes clickable if the output stream supports it, and clicking it opens a listener window with the input text inserted at the input prompt." } { $description "Prints a clickable example with sample output. The markup element must be an array of strings. All but the last string are joined by newlines and taken as the input text, and the last string is the output. The example becomes clickable if the output stream supports it, and clicking it opens a listener window with the input text inserted at the input prompt." }
{ $examples { $examples
"The output text should be a string of what the input prints when executed, not the final stack contents or anything like that. So the following is an incorrect example:" "The input text must contain a correct " { $link POSTPONE: USING: } " declaration, and output text should be a string of what the input prints when executed, not the final stack contents or anything like that. So the following is an incorrect example:"
{ $markup-example { $unchecked-example "2 2 +" "4" } } { $markup-example { $unchecked-example "2 2 +" "4" } }
"However the following is right:" "However the following is right:"
{ $markup-example { $example "2 2 + ." "4" } } { $markup-example { $example "USING: math prettyprint ;" "2 2 + ." "4" } }
"Examples can incorporate a call to " { $link .s } " to show multiple output values; the convention is that you may assume the stack is empty before the example evaluates." "Examples can incorporate a call to " { $link .s } " to show multiple output values; the convention is that you may assume the stack is empty before the example evaluates."
} ; } ;
@ -270,7 +270,7 @@ HELP: textual-list
{ $values { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( elt -- )" } } } { $values { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( elt -- )" } } }
{ $description "Applies the quotation to each element of the sequence, printing a comma between each pair of elements." } { $description "Applies the quotation to each element of the sequence, printing a comma between each pair of elements." }
{ $examples { $examples
{ $example "USE: help.markup" "{ \"fish\" \"chips\" \"salt\" } [ write ] textual-list" "fish, chips, salt" } { $example "USING: help.markup io ;" "{ \"fish\" \"chips\" \"salt\" } [ write ] textual-list" "fish, chips, salt" }
} ; } ;
HELP: $links HELP: $links

View File

@ -109,9 +109,7 @@ M: word set-article-parent swap "help-parent" set-word-prop ;
] ?if ; ] ?if ;
: ($index) ( articles -- ) : ($index) ( articles -- )
subsection-style get [ sort-articles [ \ $subsection swap 2array ] map print-element ;
sort-articles [ nl ] [ ($subsection) ] interleave
] with-style ;
: $index ( element -- ) : $index ( element -- )
first call dup empty? first call dup empty?

View File

@ -5,7 +5,7 @@ HELP: help-lint-all
{ $description "Checks all word help and articles in all loaded vocabularies." } ; { $description "Checks all word help and articles in all loaded vocabularies." } ;
HELP: help-lint HELP: help-lint
{ $values { "vocab" "a vocabulary specifier" } } { $values { "prefix" "a vocabulary specifier" } }
{ $description "Checks all word help and articles in the given vocabulary and all child vocabularies." } ; { $description "Checks all word help and articles in the given vocabulary and all child vocabularies." } ;
ARTICLE: "help.lint" "Help lint tool" ARTICLE: "help.lint" "Help lint tool"

View File

@ -5,7 +5,7 @@ words strings classes tools.browser namespaces io
io.streams.string prettyprint definitions arrays vectors io.streams.string prettyprint definitions arrays vectors
combinators splitting debugger hashtables sorting effects vocabs combinators splitting debugger hashtables sorting effects vocabs
vocabs.loader assocs editors continuations classes.predicate vocabs.loader assocs editors continuations classes.predicate
macros combinators.lib sequences.lib ; macros combinators.lib sequences.lib math ;
IN: help.lint IN: help.lint
: check-example ( element -- ) : check-example ( element -- )
@ -27,8 +27,13 @@ IN: help.lint
] unless ; ] unless ;
: effect-values ( word -- seq ) : effect-values ( word -- seq )
stack-effect dup effect-in swap effect-out stack-effect dup effect-in swap effect-out append [
append [ string? ] subset prune natural-sort ; {
{ [ dup word? ] [ word-name ] }
{ [ dup integer? ] [ drop "object" ] }
{ [ dup string? ] [ ] }
} cond
] map prune natural-sort ;
: contains-funky-elements? ( element -- ? ) : contains-funky-elements? ( element -- ? )
{ {

View File

@ -115,11 +115,11 @@ HELP: n>buffer
{ $errors "Throws an error if the buffer does not contain " { $snippet "n" } " bytes of data." } ; { $errors "Throws an error if the buffer does not contain " { $snippet "n" } " bytes of data." } ;
HELP: buffer-peek HELP: buffer-peek
{ $values { "buffer" buffer } { "ch" "a character" } } { $values { "buffer" buffer } { "byte" "a byte" } }
{ $description "Outputs the byte at the buffer position." } ; { $description "Outputs the byte at the buffer position." } ;
HELP: buffer-pop HELP: buffer-pop
{ $values { "buffer" buffer } { "ch" "a character" } } { $values { "buffer" buffer } { "byte" "a byte" } }
{ $description "Outputs the byte at the buffer position and advances the position." } ; { $description "Outputs the byte at the buffer position and advances the position." } ;
HELP: buffer-until HELP: buffer-until

View File

@ -31,10 +31,10 @@ TUPLE: buffer size ptr fill pos ;
: buffer-end ( buffer -- alien ) : buffer-end ( buffer -- alien )
dup buffer-fill swap buffer-ptr <displaced-alien> ; dup buffer-fill swap buffer-ptr <displaced-alien> ;
: buffer-peek ( buffer -- ch ) : buffer-peek ( buffer -- byte )
buffer@ 0 alien-unsigned-1 ; buffer@ 0 alien-unsigned-1 ;
: buffer-pop ( buffer -- ch ) : buffer-pop ( buffer -- byte )
dup buffer-peek 1 rot buffer-consume ; dup buffer-peek 1 rot buffer-consume ;
: (buffer>) ( n buffer -- byte-array ) : (buffer>) ( n buffer -- byte-array )
@ -90,7 +90,7 @@ HINTS: search-buffer-until { fixnum fixnum simple-alien string } ;
[ buffer-end byte-array>memory ] 2keep [ buffer-end byte-array>memory ] 2keep
[ buffer-fill swap length + ] keep set-buffer-fill ; [ buffer-fill swap length + ] keep set-buffer-fill ;
: byte>buffer ( ch buffer -- ) : byte>buffer ( byte buffer -- )
1 over check-overflow 1 over check-overflow
[ buffer-end 0 set-alien-unsigned-1 ] keep [ buffer-end 0 set-alien-unsigned-1 ] keep
[ buffer-fill 1+ ] keep set-buffer-fill ; [ buffer-fill 1+ ] keep set-buffer-fill ;

View File

@ -75,8 +75,8 @@ HELP: current-process-handle
{ $description "Returns the handle of the current process." } ; { $description "Returns the handle of the current process." } ;
HELP: run-process* HELP: run-process*
{ $values { "desc" "a launch descriptor" } { "handle" "a process handle" } } { $values { "process" process } { "handle" "a process handle" } }
{ $contract "Launches a process using the launch descriptor." } { $contract "Launches a process." }
{ $notes "User code should call " { $link run-process } " instead." } ; { $notes "User code should call " { $link run-process } " instead." } ;
HELP: run-process HELP: run-process

View File

@ -115,7 +115,7 @@ TUPLE: process-failed code ;
: process-failed ( code -- * ) : process-failed ( code -- * )
\ process-failed construct-boa throw ; \ process-failed construct-boa throw ;
: try-process ( command/process -- ) : try-process ( desc -- )
run-process wait-for-process dup zero? run-process wait-for-process dup zero?
[ drop ] [ process-failed ] if ; [ drop ] [ process-failed ] if ;

View File

@ -2,13 +2,13 @@ IN: io.monitors
USING: help.markup help.syntax continuations ; USING: help.markup help.syntax continuations ;
HELP: <monitor> HELP: <monitor>
{ $values { "path" "a pathname string" } { "recursive?" "a boolean" } } { $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "monitor" "a new monitor" } }
{ $description "Opens a file system change monitor which listens for changes on " { $snippet "path" } ". The boolean indicates whether changes in subdirectories should be reported." { $description "Opens a file system change monitor which listens for changes on " { $snippet "path" } ". The boolean indicates whether changes in subdirectories should be reported."
$nl $nl
"Not all operating systems support recursive monitors; if recursive monitoring is not available, an error is thrown and the caller must implement alternative logic for monitoring subdirectories." } ; "Not all operating systems support recursive monitors; if recursive monitoring is not available, an error is thrown and the caller must implement alternative logic for monitoring subdirectories." } ;
HELP: next-change HELP: next-change
{ $values { "monitor" "a monitor" } { "path" "a pathname string" } { "changes" "a change descriptor" } } { $values { "monitor" "a monitor" } { "path" "a pathname string" } { "changed" "a change descriptor" } }
{ $description "Waits for file system changes and outputs the pathname of the first changed file. The change descriptor is aq sequence of symbols documented in " { $link "io.monitors.descriptors" } "." } ; { $description "Waits for file system changes and outputs the pathname of the first changed file. The change descriptor is aq sequence of symbols documented in " { $link "io.monitors.descriptors" } "." } ;
HELP: with-monitor HELP: with-monitor

View File

@ -58,17 +58,17 @@ HELP: <port>
$low-level-note ; $low-level-note ;
HELP: <buffered-port> HELP: <buffered-port>
{ $values { "handle" "a native handle identifying an I/O resource" } { "port" "a new " { $link port } } } { $values { "handle" "a native handle identifying an I/O resource" } { "type" symbol } { "port" "a new " { $link port } } }
{ $description "Creates a new " { $link port } " using the specified native handle and a default-sized I/O buffer." } { $description "Creates a new " { $link port } " using the specified native handle and a default-sized I/O buffer." }
$low-level-note ; $low-level-note ;
HELP: <reader> HELP: <reader>
{ $values { "handle" "a native handle identifying an I/O resource" } { "stream" "a new " { $link input-port } } } { $values { "handle" "a native handle identifying an I/O resource" } { "input-port" "a new " { $link input-port } } }
{ $description "Creates a new " { $link input-port } " using the specified native handle and a default-sized input buffer." } { $description "Creates a new " { $link input-port } " using the specified native handle and a default-sized input buffer." }
$low-level-note ; $low-level-note ;
HELP: <writer> HELP: <writer>
{ $values { "handle" "a native handle identifying an I/O resource" } { "stream" "a new " { $link output-port } } } { $values { "handle" "a native handle identifying an I/O resource" } { "output-port" "a new " { $link output-port } } }
{ $description "Creates a new " { $link output-port } " using the specified native handle and a default-sized input buffer." } { $description "Creates a new " { $link output-port } " using the specified native handle and a default-sized input buffer." }
$low-level-note ; $low-level-note ;

View File

@ -109,7 +109,7 @@ M: input-port stream-read
buffer-until buffer-until
] if ; ] if ;
: read-until-loop ( seps port byte-vector -- separator/f ) : read-until-loop ( seps port accum -- separator/f )
2over read-until-step over [ 2over read-until-step over [
>r over push-all r> dup [ >r over push-all r> dup [
>r 3drop r> >r 3drop r>
@ -125,7 +125,7 @@ M: input-port stream-read-until ( seps port -- byte-array/f sep/f )
>r 2nip r> >r 2nip r>
] [ ] [
over [ over [
drop >byte-vector drop BV{ } like
[ read-until-loop ] keep [ read-until-loop ] keep
B{ } like swap B{ } like swap
] [ ] [

View File

@ -2,7 +2,7 @@ USING: help help.syntax help.markup io ;
IN: io.server IN: io.server
HELP: with-server HELP: with-server
{ $values { "seq" "a sequence of address specifiers" } { "service" "a string or " { $link f } } { "quot" "a quotation" } } { $values { "seq" "a sequence of address specifiers" } { "service" "a string or " { $link f } } { "encoding" "an encoding to use for client connections" } { "quot" "a quotation" } }
{ $description "Starts a TCP/IP server. The quotation is called in a new thread for each client connection, with the client connection being the " { $link stdio } " stream. Client connections are logged to the " { $link stdio } " stream at the time the server was started." } ; { $description "Starts a TCP/IP server. The quotation is called in a new thread for each client connection, with the client connection being the " { $link stdio } " stream. Client connections are logged to the " { $link stdio } " stream at the time the server was started." } ;
HELP: with-datagrams HELP: with-datagrams

View File

@ -26,7 +26,7 @@ HELP: nil?
{ $values { "cons" "a cons object" } { "?" "a boolean" } } { $values { "cons" "a cons object" } { "?" "a boolean" } }
{ $description "Return true if the cons object is the nil cons." } ; { $description "Return true if the cons object is the nil cons." } ;
HELP: list? HELP: list? ( object -- ? )
{ $values { "object" "an object" } { "?" "a boolean" } } { $values { "object" "an object" } { "?" "a boolean" } }
{ $description "Returns true if the object conforms to the list protocol." } ; { $description "Returns true if the object conforms to the list protocol." } ;
@ -175,7 +175,7 @@ HELP: lmerge
{ $values { "list1" "a list" } { "list2" "a list" } { "result" "lazy list merging list1 and list2" } } { $values { "list1" "a list" } { "list2" "a list" } { "result" "lazy list merging list1 and list2" } }
{ $description "Return the result of merging the two lists in a lazy manner." } { $description "Return the result of merging the two lists in a lazy manner." }
{ $examples { $examples
{ $example "USE: lazy-lists" "{ 1 2 3 } >list { 4 5 6 } >list lmerge list>array ." "{ 1 4 2 5 3 6 }" } { $example "USING: lazy-lists prettyprint ;" "{ 1 2 3 } >list { 4 5 6 } >list lmerge list>array ." "{ 1 4 2 5 3 6 }" }
} ; } ;
HELP: lcontents HELP: lcontents

View File

@ -23,3 +23,7 @@ IN: lazy-lists.tests
[ { 5 6 7 8 } ] [ [ { 5 6 7 8 } ] [
{ 1 2 3 } >list { 4 5 } >list 2list { [ first odd? ] } [ first2 + ] lcomp* list>array { 1 2 3 } >list { 4 5 } >list 2list { [ first odd? ] } [ first2 + ] lcomp* list>array
] unit-test ] unit-test
[ { 4 5 6 } ] [
3 { 1 2 3 } >list [ + ] lmap-with list>array
] unit-test

View File

@ -144,25 +144,8 @@ M: lazy-map cdr ( lazy-map -- cdr )
M: lazy-map nil? ( lazy-map -- bool ) M: lazy-map nil? ( lazy-map -- bool )
lazy-map-cons nil? ; lazy-map-cons nil? ;
TUPLE: lazy-map-with value cons quot ;
C: <lazy-map-with> lazy-map-with
: lmap-with ( value list quot -- result ) : lmap-with ( value list quot -- result )
over nil? [ 3drop nil ] [ <lazy-map-with> <memoized-cons> ] if ; with lmap ;
M: lazy-map-with car ( lazy-map-with -- car )
[ lazy-map-with-value ] keep
[ lazy-map-with-cons car ] keep
lazy-map-with-quot call ;
M: lazy-map-with cdr ( lazy-map-with -- cdr )
[ lazy-map-with-value ] keep
[ lazy-map-with-cons cdr ] keep
lazy-map-with-quot lmap-with ;
M: lazy-map-with nil? ( lazy-map-with -- bool )
lazy-map-with-cons nil? ;
TUPLE: lazy-take n cons ; TUPLE: lazy-take n cons ;
@ -453,7 +436,6 @@ INSTANCE: lazy-io list
INSTANCE: lazy-concat list INSTANCE: lazy-concat list
INSTANCE: lazy-cons list INSTANCE: lazy-cons list
INSTANCE: lazy-map list INSTANCE: lazy-map list
INSTANCE: lazy-map-with list
INSTANCE: lazy-take list INSTANCE: lazy-take list
INSTANCE: lazy-append list INSTANCE: lazy-append list
INSTANCE: lazy-from-by list INSTANCE: lazy-from-by list

View File

@ -15,7 +15,7 @@ HELP: [|
{ $description "A lambda abstraction. When called, reads stack values into the bindings from left to right; the body may then refer to these bindings." } { $description "A lambda abstraction. When called, reads stack values into the bindings from left to right; the body may then refer to these bindings." }
{ $examples { $examples
{ $example { $example
"USE: locals" "USING: kernel locals math prettyprint ;"
":: adder ( n -- quot ) [| m | m n + ] ;" ":: adder ( n -- quot ) [| m | m n + ] ;"
"3 5 adder call ." "3 5 adder call ."
"8" "8"
@ -28,7 +28,7 @@ HELP: [let
{ $description "Introduces a set of lexical bindings and evaluates the body. The values are evaluated in parallel, and may not refer to other bindings within the same " { $link POSTPONE: [let } " form; for Lisp programmers, this means that Factor's " { $link POSTPONE: [let } " is equivalent to the Lisp " { $snippet "let" } ", not " { $snippet "let*" } "." } { $description "Introduces a set of lexical bindings and evaluates the body. The values are evaluated in parallel, and may not refer to other bindings within the same " { $link POSTPONE: [let } " form; for Lisp programmers, this means that Factor's " { $link POSTPONE: [let } " is equivalent to the Lisp " { $snippet "let" } ", not " { $snippet "let*" } "." }
{ $examples { $examples
{ $example { $example
"USING: locals math.functions ;" "USING: kernel locals math math.functions prettyprint sequences ;"
":: frobnicate ( n seq -- newseq )" ":: frobnicate ( n seq -- newseq )"
" [let | n' [ n 6 * ] |" " [let | n' [ n 6 * ] |"
" seq [ n' gcd nip ] map ] ;" " seq [ n' gcd nip ] map ] ;"
@ -43,7 +43,7 @@ HELP: [wlet
{ $description "Introduces a set of lexically-scoped non-recursive local functions. The bodies may not refer to other bindings within the same " { $link POSTPONE: [wlet } " form; for Lisp programmers, this means that Factor's " { $link POSTPONE: [wlet } " is equivalent to the Lisp " { $snippet "flet" } ", not " { $snippet "labels" } "." } { $description "Introduces a set of lexically-scoped non-recursive local functions. The bodies may not refer to other bindings within the same " { $link POSTPONE: [wlet } " form; for Lisp programmers, this means that Factor's " { $link POSTPONE: [wlet } " is equivalent to the Lisp " { $snippet "flet" } ", not " { $snippet "labels" } "." }
{ $examples { $examples
{ $example { $example
"USE: locals" "USING: locals math prettyprint sequences ;"
":: quuxify ( n seq -- newseq )" ":: quuxify ( n seq -- newseq )"
" [wlet | add-n [| m | m n + ] |" " [wlet | add-n [| m | m n + ] |"
" seq [ add-n ] map ] ;" " seq [ add-n ] map ] ;"

View File

@ -16,7 +16,7 @@ HELP: analysis.
{ $description "Prints a logging report output by " { $link analyze-entries } ". Formatted output words are used, so the report looks nice in the UI or if sent to an HTML stream." } ; { $description "Prints a logging report output by " { $link analyze-entries } ". Formatted output words are used, so the report looks nice in the UI or if sent to an HTML stream." } ;
HELP: analyze-log HELP: analyze-log
{ $values { "service" "a log service name" } { "n" integer } { "word-names" "a sequence of strings" } } { $values { "lines" "a parsed log file" } { "word-names" "a sequence of strings" } }
{ $description "Analyzes a log file and prints a formatted report. The " { $snippet "word-names" } " parameter is documented in " { $link analyze-entries } "." } ; { $description "Analyzes a log file and prints a formatted report. The " { $snippet "word-names" } " parameter is documented in " { $link analyze-entries } "." } ;
ARTICLE: "logging.analysis" "Log analysis" ARTICLE: "logging.analysis" "Log analysis"

View File

@ -9,7 +9,7 @@ HELP: insomniac-recipients
{ $var-description "A sequence of e-mail addresses to mail log reports to. Must be set before " { $vocab-link "logging.insomniac" } " is used." } ; { $var-description "A sequence of e-mail addresses to mail log reports to. Must be set before " { $vocab-link "logging.insomniac" } " is used." } ;
HELP: ?analyze-log HELP: ?analyze-log
{ $values { "service" "a log service name" } { "word-names" "a sequence of strings" } { "string" string } } { $values { "service" "a log service name" } { "word-names" "a sequence of strings" } { "string/f" string } }
{ $description "Analyzes the most recent log and outputs the string analysis, or outputs " { $link f } " if it doesn't exist." } { $description "Analyzes the most recent log and outputs the string analysis, or outputs " { $link f } " if it doesn't exist." }
{ $see-also analyze-log } ; { $see-also analyze-log } ;
@ -18,7 +18,7 @@ HELP: email-log-report
{ $description "E-mails a log report for the given log service. The " { $link insomniac-sender } " and " { $link insomniac-recipients } " parameters must be set up first. The " { $snippet "word-names" } " parameter is documented in " { $link analyze-entries } "." } ; { $description "E-mails a log report for the given log service. The " { $link insomniac-sender } " and " { $link insomniac-recipients } " parameters must be set up first. The " { $snippet "word-names" } " parameter is documented in " { $link analyze-entries } "." } ;
HELP: schedule-insomniac HELP: schedule-insomniac
{ $values { "alist" "a sequence of pairs of shape " { $snippet "{ service word-names }" } } } { $values { "service" "a log service name" } { "word-names" "a sequence of strings" } }
{ $description "Starts a thread which e-mails log reports and rotates logs daily." } ; { $description "Starts a thread which e-mails log reports and rotates logs daily." } ;
ARTICLE: "logging.insomniac" "Automated log analysis" ARTICLE: "logging.insomniac" "Automated log analysis"

View File

@ -39,19 +39,19 @@ HELP: log-message
{ $description "Sends a message to the current log. Does nothing if not executing in a dynamic scope established by " { $link with-logging } "." } ; { $description "Sends a message to the current log. Does nothing if not executing in a dynamic scope established by " { $link with-logging } "." } ;
HELP: add-logging HELP: add-logging
{ $values { "word" word } } { $values { "level" "a log level" } { "word" word } }
{ $description "Causes the word to log a message every time it is called." } ; { $description "Causes the word to log a message every time it is called." } ;
HELP: add-input-logging HELP: add-input-logging
{ $values { "word" word } } { $values { "level" "a log level" } { "word" word } }
{ $description "Causes the word to log its input values every time it is called. The word must have a stack effect declaration." } ; { $description "Causes the word to log its input values every time it is called. The word must have a stack effect declaration." } ;
HELP: add-output-logging HELP: add-output-logging
{ $values { "word" word } } { $values { "level" "a log level" } { "word" word } }
{ $description "Causes the word to log its output values every time it is called. The word must have a stack effect declaration." } ; { $description "Causes the word to log its output values every time it is called. The word must have a stack effect declaration." } ;
HELP: add-error-logging HELP: add-error-logging
{ $values { "word" word } } { $values { "level" "a log level" } { "word" word } }
{ $description "Causes the word to log its input values and any errors it throws." { $description "Causes the word to log its input values and any errors it throws."
$nl $nl
"If the word is not executed in a dynamic scope established by " { $link with-logging } ", its behavior is unchanged, and any errors it throws are passed to the caller." "If the word is not executed in a dynamic scope established by " { $link with-logging } ", its behavior is unchanged, and any errors it throws are passed to the caller."
@ -63,7 +63,7 @@ HELP: log-error
{ $description "Logs an error." } ; { $description "Logs an error." } ;
HELP: log-critical HELP: log-critical
{ $values { "critical" "an critical" } { "word" word } } { $values { "error" "an error" } { "word" word } }
{ $description "Logs a critical error." } ; { $description "Logs a critical error." } ;
HELP: LOG: HELP: LOG:

View File

@ -6,7 +6,7 @@ HELP: parse-log
{ $description "Parses a sequence of log entries. Malformed entries are printed out and ignore. The result is a sequence of arrays of the shape " { $snippet "{ timestamp level word-name message }" } ", where" { $description "Parses a sequence of log entries. Malformed entries are printed out and ignore. The result is a sequence of arrays of the shape " { $snippet "{ timestamp level word-name message }" } ", where"
{ $list { $list
{ { $snippet "timestamp" } " is a " { $link timestamp } } { { $snippet "timestamp" } " is a " { $link timestamp } }
{ { $snippet "level" } " is a log level; see " { $link "logger.levels" } } { { $snippet "level" } " is a log level; see " { $link "logging.levels" } }
{ { $snippet "word-name" } " is a string" } { { $snippet "word-name" } " is a string" }
{ { $snippet "message" } " is a string" } { { $snippet "message" } " is a string" }
} }

View File

@ -41,7 +41,7 @@ HELP: match-replace
{ $description "Matches the " { $snippet "object" } " against " { $snippet "pattern1" } ". The pattern match variables in " { $snippet "pattern1" } " are assigned the values from the matching " { $snippet "object" } ". These are then replaced into the " { $snippet "pattern2" } " pattern match variables." } { $description "Matches the " { $snippet "object" } " against " { $snippet "pattern1" } ". The pattern match variables in " { $snippet "pattern1" } " are assigned the values from the matching " { $snippet "object" } ". These are then replaced into the " { $snippet "pattern2" } " pattern match variables." }
{ $examples { $examples
{ $example { $example
"USE: match" "USING: match prettyprint ;"
"MATCH-VARS: ?a ?b ;" "MATCH-VARS: ?a ?b ;"
"{ 1 2 } { ?a ?b } { ?b ?a } match-replace ." "{ 1 2 } { ?a ?b } { ?b ?a } match-replace ."
"{ 2 1 }" "{ 2 1 }"

View File

@ -4,46 +4,46 @@ IN: math.combinatorics
HELP: factorial HELP: factorial
{ $values { "n" "a non-negative integer" } { "n!" integer } } { $values { "n" "a non-negative integer" } { "n!" integer } }
{ $description "Outputs the product of all positive integers less than or equal to " { $snippet "n" } "." } { $description "Outputs the product of all positive integers less than or equal to " { $snippet "n" } "." }
{ $examples { $example "4 factorial ." "24" } } ; { $examples { $example "USING: math.combinatorics prettyprint ;" "4 factorial ." "24" } } ;
HELP: nPk HELP: nPk
{ $values { "n" "a non-negative integer" } { "k" "a non-negative integer" } { "nPk" integer } } { $values { "n" "a non-negative integer" } { "k" "a non-negative integer" } { "nPk" integer } }
{ $description "Outputs the total number of unique permutations of size " { $snippet "k" } " (order does matter) that can be taken from a set of size " { $snippet "n" } "." } { $description "Outputs the total number of unique permutations of size " { $snippet "k" } " (order does matter) that can be taken from a set of size " { $snippet "n" } "." }
{ $examples { $example "10 4 nPk ." "5040" } } ; { $examples { $example "USING: math.combinatorics prettyprint ;" "10 4 nPk ." "5040" } } ;
HELP: nCk HELP: nCk
{ $values { "n" "a non-negative integer" } { "k" "a non-negative integer" } { "nCk" integer } } { $values { "n" "a non-negative integer" } { "k" "a non-negative integer" } { "nCk" integer } }
{ $description "Outputs the total number of unique combinations of size " { $snippet "k" } " (order does not matter) that can be taken from a set of size " { $snippet "n" } ". Commonly written as \"n choose k\"." } { $description "Outputs the total number of unique combinations of size " { $snippet "k" } " (order does not matter) that can be taken from a set of size " { $snippet "n" } ". Commonly written as \"n choose k\"." }
{ $examples { $example "10 4 nCk ." "210" } } ; { $examples { $example "USING: math.combinatorics prettyprint ;" "10 4 nCk ." "210" } } ;
HELP: permutation HELP: permutation
{ $values { "n" "a non-negative integer" } { "seq" sequence } { "seq" sequence } } { $values { "n" "a non-negative integer" } { "seq" sequence } { "seq" sequence } }
{ $description "Outputs the " { $snippet "nth" } " lexicographical permutation of " { $snippet "seq" } "." } { $description "Outputs the " { $snippet "nth" } " lexicographical permutation of " { $snippet "seq" } "." }
{ $notes "Permutations are 0-based and a bounds error will be thrown if " { $snippet "n" } " is larger than " { $snippet "seq length factorial 1-" } "." } { $notes "Permutations are 0-based and a bounds error will be thrown if " { $snippet "n" } " is larger than " { $snippet "seq length factorial 1-" } "." }
{ $examples { $example "1 3 permutation ." "{ 0 2 1 }" } { $example "5 { \"apple\" \"banana\" \"orange\" } permutation ." "{ \"orange\" \"banana\" \"apple\"}" } } ; { $examples { $example "USING: math.combinatorics prettyprint ;" "1 3 permutation ." "{ 0 2 1 }" } { $example "USING: math.combinatorics prettyprint ;" "5 { \"apple\" \"banana\" \"orange\" } permutation ." "{ \"orange\" \"banana\" \"apple\" }" } } ;
HELP: all-permutations HELP: all-permutations
{ $values { "seq" sequence } { "seq" sequence } } { $values { "seq" sequence } { "seq" sequence } }
{ $description "Outputs a sequence containing all permutations of " { $snippet "seq" } " in lexicographical order." } { $description "Outputs a sequence containing all permutations of " { $snippet "seq" } " in lexicographical order." }
{ $examples { $example "3 all-permutations ." "{ { 0 1 2 } { 0 2 1 } { 1 0 2 } { 1 2 0 } { 2 0 1 } { 2 1 0 } }" } } ; { $examples { $example "USING: math.combinatorics prettyprint ;" "3 all-permutations ." "{ { 0 1 2 } { 0 2 1 } { 1 0 2 } { 1 2 0 } { 2 0 1 } { 2 1 0 } }" } } ;
HELP: inverse-permutation HELP: inverse-permutation
{ $values { "seq" sequence } { "permutation" sequence } } { $values { "seq" sequence } { "permutation" sequence } }
{ $description "Outputs a sequence of indices representing the lexicographical permutation of " { $snippet "seq" } "." } { $description "Outputs a sequence of indices representing the lexicographical permutation of " { $snippet "seq" } "." }
{ $notes "All items in " { $snippet "seq" } " must be comparable by " { $link <=> } "." } { $notes "All items in " { $snippet "seq" } " must be comparable by " { $link <=> } "." }
{ $examples { $example "\"dcba\" inverse-permutation ." "{ 3 2 1 0 }" } { $example "{ 12 56 34 78 } inverse-permutation ." "{ 0 2 1 3 }" } } ; { $examples { $example "USING: math.combinatorics prettyprint ;" "\"dcba\" inverse-permutation ." "{ 3 2 1 0 }" } { $example "USING: math.combinatorics prettyprint ;" "{ 12 56 34 78 } inverse-permutation ." "{ 0 2 1 3 }" } } ;
IN: math.combinatorics.private IN: math.combinatorics.private
HELP: factoradic HELP: factoradic
{ $values { "n" integer } { "seq" sequence } } { $values { "n" integer } { "factoradic" sequence } }
{ $description "Converts a positive integer " { $snippet "n" } " to factoradic form. The factoradic of an integer is its representation based on a mixed radix numerical system that corresponds to the values of " { $snippet "n" } " factorial." } { $description "Converts a positive integer " { $snippet "n" } " to factoradic form. The factoradic of an integer is its representation based on a mixed radix numerical system that corresponds to the values of " { $snippet "n" } " factorial." }
{ $examples { $example "859 factoradic ." "{ 1 1 0 3 0 1 0 }" } } ; { $examples { $example "USING: math.combinatorics.private prettyprint ;" "859 factoradic ." "{ 1 1 0 3 0 1 0 }" } } ;
HELP: >permutation HELP: >permutation
{ $values { "factoradic" sequence } { "permutation" sequence } } { $values { "factoradic" sequence } { "permutation" sequence } }
{ $description "Converts an integer represented in factoradic form into its corresponding unique permutation (0-based)." } { $description "Converts an integer represented in factoradic form into its corresponding unique permutation (0-based)." }
{ $notes "For clarification, the following two statements are equivalent:" { $code "10 factoradic >permutation" "{ 1 2 0 0 } >permutation" } } { $notes "For clarification, the following two statements are equivalent:" { $code "10 factoradic >permutation" "{ 1 2 0 0 } >permutation" } }
{ $examples { $example "{ 0 0 0 0 } >permutation ." "{ 0 1 2 3 }" } } ; { $examples { $example "USING: math.combinatorics.private prettyprint ;" "{ 0 0 0 0 } >permutation ." "{ 0 1 2 3 }" } } ;

View File

@ -3,4 +3,4 @@ IN: math.erato
HELP: lerato HELP: lerato
{ $values { "n" "a positive number" } { "lazy-list" "a lazy prime numbers generator" } } { $values { "n" "a positive number" } { "lazy-list" "a lazy prime numbers generator" } }
{ $description "Builds a lazy list containing the prime numbers between 2 and " { $snippet "n" } " (inclusive). Lazy lists are described in " { $link "lazy-lists" } "." } ; { $description "Builds a lazy list containing the prime numbers between 2 and " { $snippet "n" } " (inclusive)." } ;

View File

@ -273,16 +273,16 @@ HELP: mod-inv
{ $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." } { $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
{ $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." } { $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." }
{ $examples { $examples
{ $example "USE: math.functions" "173 1119 mod-inv ." "815" } { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
{ $example "USE: math.functions" "173 815 * 1119 mod ." "1" } { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
} ; } ;
HELP: each-bit HELP: each-bit
{ $values { "n" integer } { "quot" "a quotation with stack effect " { $snippet "( ? -- )" } } } { $values { "n" integer } { "quot" "a quotation with stack effect " { $snippet "( ? -- )" } } }
{ $description "Applies the quotation to each bit of the integer, starting from the least significant bit, and stopping at the last bit from which point on all bits are either clear (if the integer is positive) or all bits are set (if the integer is negataive)." } { $description "Applies the quotation to each bit of the integer, starting from the least significant bit, and stopping at the last bit from which point on all bits are either clear (if the integer is positive) or all bits are set (if the integer is negataive)." }
{ $examples { $examples
{ $example "USE: math.functions" "[ BIN: 1101 [ , ] each-bit ] { } make ." "{ t f t t }" } { $example "USING: math.functions namespaces prettyprint ;" "[ BIN: 1101 [ , ] each-bit ] { } make ." "{ t f t t }" }
{ $example "USE: math.functions" "[ -3 [ , ] each-bit ] { } make ." "{ t f }" } { $example "USING: math.functions namespaces prettyprint ;" "[ -3 [ , ] each-bit ] { } make ." "{ t f }" }
} ; } ;
HELP: ~ HELP: ~

View File

@ -6,17 +6,17 @@ IN: math.primes.factors
HELP: factors HELP: factors
{ $values { "n" "a positive integer" } { "seq" sequence } } { $values { "n" "a positive integer" } { "seq" sequence } }
{ $description { "Return an ordered list of a number's prime factors, possibly repeated." } } { $description { "Return an ordered list of a number's prime factors, possibly repeated." } }
{ $examples { $example "300 factors ." "{ 2 2 3 5 5 }" } } ; { $examples { $example "USING: math.primes.factors prettyprint ;" "300 factors ." "{ 2 2 3 5 5 }" } } ;
HELP: group-factors HELP: group-factors
{ $values { "n" "a positive integer" } { "seq" sequence } } { $values { "n" "a positive integer" } { "seq" sequence } }
{ $description { "Return a sequence of pairs representing each prime factor in the number and its corresponding power (multiplicity)." } } { $description { "Return a sequence of pairs representing each prime factor in the number and its corresponding power (multiplicity)." } }
{ $examples { $example "300 group-factors ." "{ { 2 2 } { 3 1 } { 5 2 } }" } } ; { $examples { $example "USING: math.primes.factors prettyprint ;" "300 group-factors ." "{ { 2 2 } { 3 1 } { 5 2 } }" } } ;
HELP: unique-factors HELP: unique-factors
{ $values { "n" "a positive integer" } { "seq" sequence } } { $values { "n" "a positive integer" } { "seq" sequence } }
{ $description { "Return an ordered list of a number's unique prime factors." } } { $description { "Return an ordered list of a number's unique prime factors." } }
{ $examples { $example "300 unique-factors ." "{ 2 3 5 }" } } ; { $examples { $example "USING: math.primes.factors prettyprint ;" "300 unique-factors ." "{ 2 3 5 }" } } ;
HELP: totient HELP: totient
{ $values { "n" "a positive integer" } { "t" integer } } { $values { "n" "a positive integer" } { "t" integer } }

View File

@ -4,56 +4,56 @@ IN: math.statistics
HELP: geometric-mean HELP: geometric-mean
{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
{ $description "Computes the geometric mean of all elements in " { $snippet "seq" } ". The geometric mean measures the central tendency of a data set that minimizes the effects of extreme values." } { $description "Computes the geometric mean of all elements in " { $snippet "seq" } ". The geometric mean measures the central tendency of a data set that minimizes the effects of extreme values." }
{ $examples { $example "USE: math.statistics" "{ 1 2 3 } geometric-mean ." "1.81712059283214" } } { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } geometric-mean ." "1.81712059283214" } }
{ $errors "Throws a " { $link signal-error. } " (square-root of 0) if the sequence is empty." } ; { $errors "Throws a " { $link signal-error. } " (square-root of 0) if the sequence is empty." } ;
HELP: harmonic-mean HELP: harmonic-mean
{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
{ $description "Computes the harmonic mean of the elements in " { $snippet "seq" } ". The harmonic mean is appropriate when the average of rates is desired." } { $description "Computes the harmonic mean of the elements in " { $snippet "seq" } ". The harmonic mean is appropriate when the average of rates is desired." }
{ $examples { $example "USE: math.statistics" "{ 1 2 3 } harmonic-mean ." "6/11" } } { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } harmonic-mean ." "6/11" } }
{ $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ; { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
HELP: mean HELP: mean
{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
{ $description "Computes the arithmetic mean of all elements in " { $snippet "seq" } "." } { $description "Computes the arithmetic mean of all elements in " { $snippet "seq" } "." }
{ $examples { $example "USE: math.statistics" "{ 1 2 3 } mean ." "2" } } { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } mean ." "2" } }
{ $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ; { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
HELP: median HELP: median
{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
{ $description "Computes the median of " { $snippet "seq" } " by sorting the sequence from lowest value to highest and outputting the middle one. If there is an even number of elements in the sequence, the median is not unique, so the mean of the two middle values is outputted." } { $description "Computes the median of " { $snippet "seq" } " by sorting the sequence from lowest value to highest and outputting the middle one. If there is an even number of elements in the sequence, the median is not unique, so the mean of the two middle values is outputted." }
{ $examples { $examples
{ $example "USE: math.statistics" "{ 1 2 3 } median ." "2" } { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } median ." "2" }
{ $example "USE: math.statistics" "{ 1 2 3 4 } median ." "5/2" } } { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } median ." "2+1/2" } }
{ $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ; { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
HELP: range HELP: range
{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} } { $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
{ $description "Computes the distance of the maximum and minimum values in " { $snippet "seq" } "." } { $description "Computes the distance of the maximum and minimum values in " { $snippet "seq" } "." }
{ $examples { $examples
{ $example "USE: math.statistics" "{ 1 2 3 } range ." "2" } { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } range ." "2" }
{ $example "USE: math.statistics" "{ 1 2 3 4 } range ." "3" } } ; { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } range ." "3" } } ;
HELP: std HELP: std
{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} } { $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
{ $description "Computes the standard deviation of " { $snippet "seq" } " by squaring the variance of the sequence. It measures how widely spread the values in a sequence are about the mean." } { $description "Computes the standard deviation of " { $snippet "seq" } " by squaring the variance of the sequence. It measures how widely spread the values in a sequence are about the mean." }
{ $examples { $examples
{ $example "USE: math.statistics" "{ 1 2 3 } std ." "1.0" } { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } std ." "1.0" }
{ $example "USE: math.statistics" "{ 1 2 3 4 } std ." "1.290994448735806" } } ; { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } std ." "1.290994448735806" } } ;
HELP: ste HELP: ste
{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} } { $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
{ $description "Computes the standard error of the mean for " { $snippet "seq" } ". It's defined as the standard deviation divided by the square root of the length of the sequence, and measures uncertainty associated with the estimate of the mean." } { $description "Computes the standard error of the mean for " { $snippet "seq" } ". It's defined as the standard deviation divided by the square root of the length of the sequence, and measures uncertainty associated with the estimate of the mean." }
{ $examples { $examples
{ $example "USE: math.statistics" "{ -2 2 } ste ." "2.0" } { $example "USING: math.statistics prettyprint ;" "{ -2 2 } ste ." "2.0" }
{ $example "USE: math.statistics" "{ -2 2 2 } ste ." "1.333333333333333" } } ; { $example "USING: math.statistics prettyprint ;" "{ -2 2 2 } ste ." "1.333333333333333" } } ;
HELP: var HELP: var
{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} } { $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
{ $description "Computes the variance of " { $snippet "seq" } ". It's a measurement of the spread of values in a sequence. The larger the variance, the larger the distance of values from the mean." } { $description "Computes the variance of " { $snippet "seq" } ". It's a measurement of the spread of values in a sequence. The larger the variance, the larger the distance of values from the mean." }
{ $notes "If the number of elements in " { $snippet "seq" } " is 1 or less, it outputs 0." } { $notes "If the number of elements in " { $snippet "seq" } " is 1 or less, it outputs 0." }
{ $examples { $examples
{ $example "USE: math.statistics" "{ 1 } var ." "0" } { $example "USING: math.statistics prettyprint ;" "{ 1 } var ." "0" }
{ $example "USE: math.statistics" "{ 1 2 3 } var ." "1" } { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } var ." "1" }
{ $example "USE: math.statistics" "{ 1 2 3 4 } var ." "5/3" } } ; { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } var ." "1+2/3" } } ;

View File

@ -4,4 +4,4 @@ IN: math.text.english
HELP: number>text HELP: number>text
{ $values { "n" integer } { "str" string } } { $values { "n" integer } { "str" string } }
{ $description "Converts an integer to a text string representation in English, including appropriate punctuation and conjunctions." } { $description "Converts an integer to a text string representation in English, including appropriate punctuation and conjunctions." }
{ $examples { $example "12345 number>text ." "\"Twelve Thousand, Three Hundred and Forty-Five\"" } } ; { $examples { $example "USING: math.text.english prettyprint ;" "12345 number>text ." "\"Twelve Thousand, Three Hundred and Forty-Five\"" } } ;

View File

@ -69,12 +69,12 @@ HELP: v/
HELP: vmax HELP: vmax
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } } { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
{ $description "Creates a sequence where each element is the maximum of the corresponding elements from " { $snippet "u" } " andd " { $snippet "v" } "." } { $description "Creates a sequence where each element is the maximum of the corresponding elements from " { $snippet "u" } " andd " { $snippet "v" } "." }
{ $examples { $example "USE: math.vectors" "{ 1 2 5 } { -7 6 3 } vmax ." "{ 1 6 5 }" } } ; { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmax ." "{ 1 6 5 }" } } ;
HELP: vmin HELP: vmin
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } } { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
{ $description "Creates a sequence where each element is the minimum of the corresponding elements from " { $snippet "u" } " andd " { $snippet "v" } "." } { $description "Creates a sequence where each element is the minimum of the corresponding elements from " { $snippet "u" } " andd " { $snippet "v" } "." }
{ $examples { $example "USE: math.vectors" "{ 1 2 5 } { -7 6 3 } vmin ." "{ -7 2 3 }" } } ; { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmin ." "{ -7 2 3 }" } } ;
HELP: v. HELP: v.
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "x" "a real number" } } { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "x" "a real number" } }
@ -99,7 +99,7 @@ HELP: normalize
HELP: set-axis HELP: set-axis
{ $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "axis" "a sequence of 0/1" } { "w" "a sequence of numbers" } } { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "axis" "a sequence of 0/1" } { "w" "a sequence of numbers" } }
{ $description "Using " { $snippet "w" } " as a template, creates a new sequence containing corresponding elements from " { $snippet "u" } " in place of 0, and corresponding elements from " { $snippet "v" } " in place of 1." } { $description "Using " { $snippet "w" } " as a template, creates a new sequence containing corresponding elements from " { $snippet "u" } " in place of 0, and corresponding elements from " { $snippet "v" } " in place of 1." }
{ $examples { $example "USE: math.vectors" "{ 1 2 3 } { 4 5 6 } { 0 1 0 } set-axis ." "{ 1 5 3 }" } } ; { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 3 } { 4 5 6 } { 0 1 0 } set-axis ." "{ 1 5 3 }" } } ;
{ 2map v+ v- v* v/ } related-words { 2map v+ v- v* v/ } related-words

View File

@ -43,7 +43,7 @@ HELP: has-gl-extensions?
{ $description "Returns true if the set of " { $snippet "extensions" } " is a subset of the implementation-supported extensions returned by " { $link gl-extensions } "." } ; { $description "Returns true if the set of " { $snippet "extensions" } " is a subset of the implementation-supported extensions returned by " { $link gl-extensions } "." } ;
HELP: has-gl-version-or-extensions? HELP: has-gl-version-or-extensions?
{ $values { "version" "A version string" } { "extensions" "A sequence of extension name strings" } } { $values { "version" "A version string" } { "extensions" "A sequence of extension name strings" } { "?" "a boolean" } }
{ $description "Returns true if either " { $link has-gl-version? } " or " { $link has-gl-extensions? } " returns true for " { $snippet "version" } " or " { $snippet "extensions" } ", respectively. Intended for use when required OpenGL functionality can be verified either by a minimum version or a set of equivalent extensions." } ; { $description "Returns true if either " { $link has-gl-version? } " or " { $link has-gl-extensions? } " returns true for " { $snippet "version" } " or " { $snippet "extensions" } ", respectively. Intended for use when required OpenGL functionality can be verified either by a minimum version or a set of equivalent extensions." } ;
HELP: require-gl-extensions HELP: require-gl-extensions

View File

@ -1,5 +1,5 @@
USING: help.markup help.syntax io kernel math quotations USING: help.markup help.syntax io kernel math quotations
opengl.gl multiline assocs ; opengl.gl multiline assocs strings ;
IN: opengl.shaders IN: opengl.shaders
HELP: gl-shader HELP: gl-shader
@ -28,19 +28,19 @@ HELP: fragment-shader
} ; } ;
HELP: <gl-shader> HELP: <gl-shader>
{ $values { "source" "The GLSL source code to compile" } { "kind" "The kind of shader to compile, such as " { $snippet "GL_VERTEX_SHADER" } " or " { $snippet "GL_FRAGMENT_SHADER" } } } { $values { "source" "The GLSL source code to compile" } { "kind" "The kind of shader to compile, such as " { $snippet "GL_VERTEX_SHADER" } " or " { $snippet "GL_FRAGMENT_SHADER" } } { "shader" "a new " { $link gl-shader } } }
{ $description "Tries to compile the given GLSL source into a shader object. The returned object can be checked for validity by " { $link check-gl-shader } " or " { $link gl-shader-ok? } ". Errors and warnings generated by the GLSL compiler will be collected in the info log, available from " { $link gl-shader-info-log } ".\n\nWhen the shader object is no longer needed, it should be deleted using " { $link delete-gl-shader } " or else be attached to a " { $link gl-program } " object deleted using " { $link delete-gl-program } "." } ; { $description "Tries to compile the given GLSL source into a shader object. The returned object can be checked for validity by " { $link check-gl-shader } " or " { $link gl-shader-ok? } ". Errors and warnings generated by the GLSL compiler will be collected in the info log, available from " { $link gl-shader-info-log } ".\n\nWhen the shader object is no longer needed, it should be deleted using " { $link delete-gl-shader } " or else be attached to a " { $link gl-program } " object deleted using " { $link delete-gl-program } "." } ;
HELP: <vertex-shader> HELP: <vertex-shader>
{ $values { "source" "The GLSL source code to compile" } } { $values { "source" "The GLSL source code to compile" } { "vertex-shader" "a new " { $link vertex-shader } } }
{ $description "Tries to compile the given GLSL source into a vertex shader object. Equivalent to " { $snippet "GL_VERTEX_SHADER <gl-shader>" } "." } ; { $description "Tries to compile the given GLSL source into a vertex shader object. Equivalent to " { $snippet "GL_VERTEX_SHADER <gl-shader>" } "." } ;
HELP: <fragment-shader> HELP: <fragment-shader>
{ $values { "source" "The GLSL source code to compile" } } { $values { "source" "The GLSL source code to compile" } { "fragment-shader" "a new " { $link fragment-shader } } }
{ $description "Tries to compile the given GLSL source into a fragment shader object. Equivalent to " { $snippet "GL_FRAGMENT_SHADER <gl-shader>" } "." } ; { $description "Tries to compile the given GLSL source into a fragment shader object. Equivalent to " { $snippet "GL_FRAGMENT_SHADER <gl-shader>" } "." } ;
HELP: gl-shader-ok? HELP: gl-shader-ok?
{ $values { "shader" "A " { $link gl-shader } " object" } } { $values { "shader" "A " { $link gl-shader } " object" } { "?" "a boolean" } }
{ $description "Returns a boolean value indicating whether the given shader object compiled successfully. Compilation errors and warnings are available in the shader's info log, which can be gotten using " { $link gl-shader-info-log } "." } ; { $description "Returns a boolean value indicating whether the given shader object compiled successfully. Compilation errors and warnings are available in the shader's info log, which can be gotten using " { $link gl-shader-info-log } "." } ;
HELP: check-gl-shader HELP: check-gl-shader
@ -52,7 +52,7 @@ HELP: delete-gl-shader
{ $description "Deletes the shader object, invalidating it and releasing any resources allocated for it by the OpenGL implementation." } ; { $description "Deletes the shader object, invalidating it and releasing any resources allocated for it by the OpenGL implementation." } ;
HELP: gl-shader-info-log HELP: gl-shader-info-log
{ $values { "shader" "A " { $link gl-shader } " object" } } { $values { "shader" "A " { $link gl-shader } " object" } { "shader" "a new " { $link gl-shader } } { "log" string } }
{ $description "Retrieves the info log for " { $snippet "shader" } ", including any errors or warnings generated in compiling the shader object." } ; { $description "Retrieves the info log for " { $snippet "shader" } ", including any errors or warnings generated in compiling the shader object." } ;
HELP: gl-program HELP: gl-program
@ -69,17 +69,17 @@ HELP: gl-program
} ; } ;
HELP: <gl-program> HELP: <gl-program>
{ $values { "shaders" "A sequence of " { $link gl-shader } " objects." } } { $values { "shaders" "A sequence of " { $link gl-shader } " objects." } { "program" "a new " { $link gl-program } } }
{ $description "Creates a new GLSL program object, attaches all the shader objects in the " { $snippet "shaders" } " sequence, and attempts to link them. The returned object can be checked for validity by " { $link check-gl-program } " or " { $link gl-program-ok? } ". Errors and warnings generated by the GLSL linker will be collected in the info log, available from " { $link gl-program-info-log } ".\n\nWhen the program object and its attached shaders are no longer needed, it should be deleted using " { $link delete-gl-program } "." } ; { $description "Creates a new GLSL program object, attaches all the shader objects in the " { $snippet "shaders" } " sequence, and attempts to link them. The returned object can be checked for validity by " { $link check-gl-program } " or " { $link gl-program-ok? } ". Errors and warnings generated by the GLSL linker will be collected in the info log, available from " { $link gl-program-info-log } ".\n\nWhen the program object and its attached shaders are no longer needed, it should be deleted using " { $link delete-gl-program } "." } ;
HELP: <simple-gl-program> HELP: <simple-gl-program>
{ $values { "vertex-shader-source" "A string containing GLSL vertex shader source" } { "fragment-shader-source" "A string containing GLSL fragment shader source" } } { $values { "vertex-shader-source" "A string containing GLSL vertex shader source" } { "fragment-shader-source" "A string containing GLSL fragment shader source" } { "program" "a new " { $link gl-program } } }
{ $description "Wrapper for " { $link <gl-program> } " for the simple case of compiling a single vertex shader and fragment shader and linking them into a GLSL program. Throws an exception if compiling or linking fails." } ; { $description "Wrapper for " { $link <gl-program> } " for the simple case of compiling a single vertex shader and fragment shader and linking them into a GLSL program. Throws an exception if compiling or linking fails." } ;
{ <gl-program> <simple-gl-program> } related-words { <gl-program> <simple-gl-program> } related-words
HELP: gl-program-ok? HELP: gl-program-ok?
{ $values { "program" "A " { $link gl-program } " object" } } { $values { "program" "A " { $link gl-program } " object" } { "?" "a boolean" } }
{ $description "Returns a boolean value indicating whether the given program object linked successfully. Link errors and warnings are available in the program's info log, which can be gotten using " { $link gl-program-info-log } "." } ; { $description "Returns a boolean value indicating whether the given program object linked successfully. Link errors and warnings are available in the program's info log, which can be gotten using " { $link gl-program-info-log } "." } ;
HELP: check-gl-program HELP: check-gl-program
@ -87,7 +87,7 @@ HELP: check-gl-program
{ $description "Throws an error containing the " { $link gl-program-info-log } " for the program object if it failed to link. Otherwise, the program object is left on the stack." } ; { $description "Throws an error containing the " { $link gl-program-info-log } " for the program object if it failed to link. Otherwise, the program object is left on the stack." } ;
HELP: gl-program-info-log HELP: gl-program-info-log
{ $values { "program" "A " { $link gl-program } " object" } } { $values { "program" "A " { $link gl-program } " object" } { "log" string } }
{ $description "Retrieves the info log for " { $snippet "program" } ", including any errors or warnings generated in linking the program object." } ; { $description "Retrieves the info log for " { $snippet "program" } ", including any errors or warnings generated in linking the program object." } ;
HELP: delete-gl-program HELP: delete-gl-program

View File

@ -50,7 +50,7 @@ IN: opengl.shaders
alien>char-string alien>char-string
] with-malloc ; ] with-malloc ;
: check-gl-shader ( shader -- shader* ) : check-gl-shader ( shader -- shader )
dup gl-shader-ok? [ dup gl-shader-info-log throw ] unless ; dup gl-shader-ok? [ dup gl-shader-info-log throw ] unless ;
: delete-gl-shader ( shader -- ) glDeleteShader ; inline : delete-gl-shader ( shader -- ) glDeleteShader ; inline
@ -85,7 +85,7 @@ PREDICATE: gl-shader fragment-shader (fragment-shader?) ;
alien>char-string alien>char-string
] with-malloc ; ] with-malloc ;
: check-gl-program ( program -- program* ) : check-gl-program ( program -- program )
dup gl-program-ok? [ dup gl-program-info-log throw ] unless ; dup gl-program-ok? [ dup gl-program-info-log throw ] unless ;
: gl-program-shaders-length ( program -- shaders-length ) : gl-program-shaders-length ( program -- shaders-length )

View File

@ -12,7 +12,7 @@ HELP: list-of
"'items' is a parser that can parse the individual elements. 'separator' " "'items' is a parser that can parse the individual elements. 'separator' "
"is a parser for the symbol that separatest them. The result tree of " "is a parser for the symbol that separatest them. The result tree of "
"the resulting parser is an array of the parsed elements." } "the resulting parser is an array of the parsed elements." }
{ $example "USE: parser-combinators" "\"1,2,3,4\" 'integer' \",\" token list-of parse-1 ." "{ 1 2 3 4 }" } { $example "USING: parser-combinators parser-combinators.simple prettyprint ;" "\"1,2,3,4\" 'integer' \",\" token list-of parse-1 ." "{ 1 2 3 4 }" }
{ $see-also list-of } ; { $see-also list-of } ;
HELP: any-char-parser HELP: any-char-parser
@ -23,4 +23,4 @@ HELP: any-char-parser
"from the input string. The value consumed is the " "from the input string. The value consumed is the "
"result of the parse." } "result of the parse." }
{ $examples { $examples
{ $example "USING: lazy-lists parser-combinators ;" "\"foo\" any-char-parser parse-1 ." "102" } } ; { $example "USING: lazy-lists parser-combinators prettyprint ;" "\"foo\" any-char-parser parse-1 ." "102" } } ;

View File

@ -11,7 +11,7 @@ HELP: 'digit'
"the input string. The numeric value of the digit " "the input string. The numeric value of the digit "
" consumed is the result of the parse." } " consumed is the result of the parse." }
{ $examples { $examples
{ $example "USING: lazy-lists parser-combinators ;" "\"123\" 'digit' parse-1 ." "1" } } ; { $example "USING: lazy-lists parser-combinators parser-combinators.simple prettyprint ;" "\"123\" 'digit' parse-1 ." "1" } } ;
HELP: 'integer' HELP: 'integer'
{ $values { $values
@ -21,7 +21,7 @@ HELP: 'integer'
"the input string. The numeric value of the integer " "the input string. The numeric value of the integer "
" consumed is the result of the parse." } " consumed is the result of the parse." }
{ $examples { $examples
{ $example "USING: lazy-lists parser-combinators ;" "\"123\" 'integer' parse-1 ." "123" } } ; { $example "USING: lazy-lists parser-combinators parser-combinators.simple prettyprint ;" "\"123\" 'integer' parse-1 ." "123" } } ;
HELP: 'string' HELP: 'string'
{ $values { $values
{ "parser" "a parser object" } } { "parser" "a parser object" } }
@ -30,7 +30,8 @@ HELP: 'string'
"quotations from the input string. The string value " "quotations from the input string. The string value "
" consumed is the result of the parse." } " consumed is the result of the parse." }
{ $examples { $examples
{ $example "USING: lazy-lists parser-combinators ;" "\"\\\"foo\\\"\" 'string' parse-1 ." "\"foo\"" } } ; { $example "USING: lazy-lists parser-combinators parser-combinators.simple prettyprint ;" "\"\\\"foo\\\"\" 'string' parse-1 ." "\"foo\"" } } ;
HELP: 'bold' HELP: 'bold'
{ $values { $values
{ "parser" "a parser object" } } { "parser" "a parser object" } }
@ -39,8 +40,9 @@ HELP: 'bold'
"the '*' character from the input string. This is " "the '*' character from the input string. This is "
"commonly used in markup languages to indicate bold " "commonly used in markup languages to indicate bold "
"faced text." } "faced text." }
{ $example "USE: parser-combinators" "\"*foo*\" 'bold' parse-1 ." "\"foo\"" } { $example "USING: parser-combinators parser-combinators.simple prettyprint ;" "\"*foo*\" 'bold' parse-1 ." "\"foo\"" }
{ $example "USE: parser-combinators" "\"*foo*\" 'bold' [ \"<strong>\" swap \"</strong>\" 3append ] <@ parse-1 ." "\"<strong>foo</strong>\"" } ; { $example "USING: kernel parser-combinators parser-combinators.simple prettyprint sequences ;" "\"*foo*\" 'bold' [ \"<strong>\" swap \"</strong>\" 3append ] <@ parse-1 ." "\"<strong>foo</strong>\"" } ;
HELP: 'italic' HELP: 'italic'
{ $values { $values
{ "parser" "a parser object" } } { "parser" "a parser object" } }
@ -50,8 +52,8 @@ HELP: 'italic'
"commonly used in markup languages to indicate italic " "commonly used in markup languages to indicate italic "
"faced text." } "faced text." }
{ $examples { $examples
{ $example "USING: lazy-lists parser-combinators ;" "\"_foo_\" 'italic' parse-1 ." "\"foo\"" } { $example "USING: parser-combinators parser-combinators.simple prettyprint ;" "\"_foo_\" 'italic' parse-1 ." "\"foo\"" }
{ $example "USING: lazy-lists parser-combinators ;" "\"_foo_\" 'italic' [ \"<emphasis>\" swap \"</emphasis>\" 3append ] <@ parse-1 ." "\"<emphasis>foo</emphasis>\"" } } ; { $example "USING: kernel parser-combinators parser-combinators.simple prettyprint sequences ;" "\"_foo_\" 'italic' [ \"<emphasis>\" swap \"</emphasis>\" 3append ] <@ parse-1 ." "\"<emphasis>foo</emphasis>\"" } } ;
HELP: comma-list HELP: comma-list
{ $values { $values
{ "element" "a parser object" } { "parser" "a parser object" } } { "element" "a parser object" } { "parser" "a parser object" } }
@ -60,6 +62,6 @@ HELP: comma-list
"'element' should be a parser that can parse the elements. The " "'element' should be a parser that can parse the elements. The "
"result of the parser is a sequence of the parsed elements." } "result of the parser is a sequence of the parsed elements." }
{ $examples { $examples
{ $example "USING: lazy-lists parser-combinators ;" "\"1,2,3,4\" 'integer' comma-list parse-1 ." "{ 1 2 3 4 }" } } ; { $example "USING: lazy-lists parser-combinators parser-combinators.simple prettyprint ;" "\"1,2,3,4\" 'integer' comma-list parse-1 ." "{ 1 2 3 4 }" } } ;
{ $see-also 'digit' 'integer' 'string' 'bold' 'italic' comma-list } related-words { $see-also 'digit' 'integer' 'string' 'bold' 'italic' comma-list } related-words

View File

@ -18,24 +18,26 @@ HELP: list-of
{ $values { $values
{ "items" "a sequence" } { "items" "a sequence" }
{ "separator" "a parser" } { "separator" "a parser" }
{ "parser" "a parser" }
} { $description } { $description
"Returns a parser that returns a list of items separated by the separator parser. Hides the separators and matches a list of one or more items." "Returns a parser that returns a list of items separated by the separator parser. Hides the separators and matches a list of one or more items."
} { $notes "Use " { $link list-of-many } " to ensure a list contains two or more items." } } { $notes "Use " { $link list-of-many } " to ensure a list contains two or more items." }
{ $examples { $examples
{ $example "\"a\" \"a\" token \",\" token list-of parse parse-result-ast ." "V{ \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"a\" \"a\" token \",\" token list-of parse parse-result-ast ." "V{ \"a\" }" }
{ $example "\"a,a,a,a\" \"a\" token \",\" token list-of parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"a,a,a,a\" \"a\" token \",\" token list-of parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
} { $see-also list-of-many } ; } { $see-also list-of-many } ;
HELP: list-of-many HELP: list-of-many
{ $values { $values
{ "items" "a sequence" } { "items" "a sequence" }
{ "separator" "a parser" } { "separator" "a parser" }
{ "parser" "a parser" }
} { $description } { $description
"Returns a parser that returns a list of items separated by the separator parser. Hides the separators and matches a list of two or more items." "Returns a parser that returns a list of items separated by the separator parser. Hides the separators and matches a list of two or more items."
} { $notes "Use " { $link list-of } " to return a list of only one item." } { $notes "Use " { $link list-of } " to return a list of only one item."
} { $examples } { $examples
{ $example "\"a\" \"a\" token \",\" token list-of-many parse ." "f" } { $example "USING: peg peg.parsers prettyprint ;" "\"a\" \"a\" token \",\" token list-of-many parse ." "f" }
{ $example "\"a,a,a,a\" \"a\" token \",\" token list-of-many parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"a,a,a,a\" \"a\" token \",\" token list-of-many parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
} { $see-also list-of } ; } { $see-also list-of } ;
HELP: epsilon HELP: epsilon
@ -60,8 +62,8 @@ HELP: exactly-n
} { $description } { $description
"Returns a parser that matches an exact repetition of the input parser." "Returns a parser that matches an exact repetition of the input parser."
} { $examples } { $examples
{ $example "\"aaa\" \"a\" token 4 exactly-n parse ." "f" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaa\" \"a\" token 4 exactly-n parse ." "f" }
{ $example "\"aaaa\" \"a\" token 4 exactly-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaaa\" \"a\" token 4 exactly-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
} { $see-also at-least-n at-most-n from-m-to-n } ; } { $see-also at-least-n at-most-n from-m-to-n } ;
HELP: at-least-n HELP: at-least-n
@ -72,9 +74,9 @@ HELP: at-least-n
} { $description } { $description
"Returns a parser that matches n or more repetitions of the input parser." "Returns a parser that matches n or more repetitions of the input parser."
} { $examples } { $examples
{ $example "\"aaa\" \"a\" token 4 at-least-n parse ." "f" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaa\" \"a\" token 4 at-least-n parse ." "f" }
{ $example "\"aaaa\" \"a\" token 4 at-least-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaaa\" \"a\" token 4 at-least-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
{ $example "\"aaaaa\" \"a\" token 4 at-least-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaaaa\" \"a\" token 4 at-least-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" \"a\" }" }
} { $see-also exactly-n at-most-n from-m-to-n } ; } { $see-also exactly-n at-most-n from-m-to-n } ;
HELP: at-most-n HELP: at-most-n
@ -85,8 +87,8 @@ HELP: at-most-n
} { $description } { $description
"Returns a parser that matches n or fewer repetitions of the input parser." "Returns a parser that matches n or fewer repetitions of the input parser."
} { $examples } { $examples
{ $example "\"aaaa\" \"a\" token 4 at-most-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaaa\" \"a\" token 4 at-most-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
{ $example "\"aaaaa\" \"a\" token 4 at-most-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaaaa\" \"a\" token 4 at-most-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
} { $see-also exactly-n at-least-n from-m-to-n } ; } { $see-also exactly-n at-least-n from-m-to-n } ;
HELP: from-m-to-n HELP: from-m-to-n
@ -98,9 +100,9 @@ HELP: from-m-to-n
} { $description } { $description
"Returns a parser that matches between and including m to n repetitions of the input parser." "Returns a parser that matches between and including m to n repetitions of the input parser."
} { $examples } { $examples
{ $example "\"aaa\" \"a\" token 3 4 from-m-to-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaa\" \"a\" token 3 4 from-m-to-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" }" }
{ $example "\"aaaa\" \"a\" token 3 4 from-m-to-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaaa\" \"a\" token 3 4 from-m-to-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
{ $example "\"aaaaa\" \"a\" token 3 4 from-m-to-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" } { $example "USING: peg peg.parsers prettyprint ;" "\"aaaaa\" \"a\" token 3 4 from-m-to-n parse parse-result-ast ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
} { $see-also exactly-n at-most-n at-least-n } ; } { $see-also exactly-n at-most-n at-least-n } ;
HELP: pack HELP: pack
@ -108,11 +110,11 @@ HELP: pack
{ "begin" "a parser" } { "begin" "a parser" }
{ "body" "a parser" } { "body" "a parser" }
{ "end" "a parser" } { "end" "a parser" }
{ "parser'" "a parser" } { "parser" "a parser" }
} { $description } { $description
"Returns a parser that parses the begin, body, and end parsers in order. The begin and end parsers are hidden." "Returns a parser that parses the begin, body, and end parsers in order. The begin and end parsers are hidden."
} { $examples } { $examples
{ $example "\"hi123bye\" \"hi\" token 'integer' \"bye\" token pack parse parse-result-ast ." "123" } { $example "USING: peg peg.parsers prettyprint ;" "\"hi123bye\" \"hi\" token 'integer' \"bye\" token pack parse parse-result-ast ." "123" }
} { $see-also surrounded-by } ; } { $see-also surrounded-by } ;
HELP: surrounded-by HELP: surrounded-by
@ -124,7 +126,7 @@ HELP: surrounded-by
} { $description } { $description
"Calls token on begin and end to make them into string parsers. Returns a parser that parses the begin, body, and end parsers in order. The begin and end parsers are hidden." "Calls token on begin and end to make them into string parsers. Returns a parser that parses the begin, body, and end parsers in order. The begin and end parsers are hidden."
} { $examples } { $examples
{ $example "\"hi123bye\" 'integer' \"hi\" \"bye\" surrounded-by parse parse-result-ast ." "123" } { $example "USING: peg peg.parsers prettyprint ;" "\"hi123bye\" 'integer' \"hi\" \"bye\" surrounded-by parse parse-result-ast ." "123" }
} { $see-also pack } ; } { $see-also pack } ;
HELP: 'digit' HELP: 'digit'

View File

@ -10,7 +10,7 @@ HELP: tree-write
"Write the object to the standard output stream, unless " "Write the object to the standard output stream, unless "
"it is an array, in which case recurse through the array " "it is an array, in which case recurse through the array "
"writing each object to the stream." } "writing each object to the stream." }
{ $example "{ 65 \"bc\" { 68 \"ef\" } } tree-write" "AbcDef" } ; { $example "USE: peg.search" "{ 65 \"bc\" { 68 \"ef\" } } tree-write" "AbcDef" } ;
HELP: search HELP: search
{ $values { $values
@ -24,8 +24,8 @@ HELP: search
"parser." "parser."
} }
{ $example "\"one 123 two 456\" 'integer' search" "V{ 123 456 }" } { $example "USING: peg.parsers peg.search prettyprint ;" "\"one 123 two 456\" 'integer' search ." "V{ 123 456 }" }
{ $example "\"one 123 \\\"hello\\\" two 456\" 'integer' 'string' 2array choice search" "V{ 123 \"hello\" 456 }" } { $example "USING: peg peg.parsers peg.search prettyprint ;" "\"one 123 \\\"hello\\\" two 456\" 'integer' 'string' 2choice search ." "V{ 123 \"hello\" 456 }" }
{ $see-also replace } ; { $see-also replace } ;
HELP: replace HELP: replace
@ -39,6 +39,6 @@ HELP: replace
"successfully parse with the given parser replaced with " "successfully parse with the given parser replaced with "
"the result of that parser." "the result of that parser."
} }
{ $example "\"one 123 two 456\" 'integer' [ 2 * number>string ] action replace" "\"one 246 two 912\"" } { $example "USING: math math.parser peg peg.parsers peg.search prettyprint ;" "\"one 123 two 456\" 'integer' [ 2 * number>string ] action replace ." "\"one 246 two 912\"" }
{ $see-also search } ; { $see-also search } ;

View File

@ -29,6 +29,6 @@ HELP: LAZY:
{ $values { "word" "a new word to define" } { "definition" "a word definition" } } { $values { "word" "a new word to define" } { "definition" "a word definition" } }
{ $description "Creates a lazy word in the current vocabulary. When executed the word will return a " { $link promise } " that when forced, executes the word definition. Any values on the stack that are required by the word definition are captured along with the promise." } { $description "Creates a lazy word in the current vocabulary. When executed the word will return a " { $link promise } " that when forced, executes the word definition. Any values on the stack that are required by the word definition are captured along with the promise." }
{ $examples { $examples
{ $example "IN: promises LAZY: my-add ( a b -- c ) + ;\n1 2 my-add force ." "3" } { $example "USING: math prettyprint promises ;" "LAZY: my-add ( a b -- c ) + ;" "1 2 my-add force ." "3" }
} }
{ $see-also force promise-with promise-with2 } ; { $see-also force promise-with promise-with2 } ;

View File

@ -8,7 +8,7 @@ HELP: map-withn
"passed to the quotation given to map-withn for each element in the sequence." "passed to the quotation given to map-withn for each element in the sequence."
} }
{ $examples { $examples
{ $example "USE: combinators.lib" "1 2 3 4 { 6 7 8 9 10 } [ + + + + ] 4 map-withn .s" "{ 16 17 18 19 20 }" } { $example "USING: math sequences.lib prettyprint ;" "1 2 3 4 { 6 7 8 9 10 } [ + + + + ] 4 map-withn .s" "{ 16 17 18 19 20 }" }
} }
{ $see-also each-withn } ; { $see-also each-withn } ;
@ -24,7 +24,7 @@ HELP: sigma
{ $description "Like map sum, but without creating an intermediate sequence." } { $description "Like map sum, but without creating an intermediate sequence." }
{ $example { $example
"! Find the sum of the squares [0,99]" "! Find the sum of the squares [0,99]"
"USING: math.ranges combinators.lib ;" "USING: math math.ranges sequences.lib prettyprint ;"
"100 [1,b] [ sq ] sigma ." "100 [1,b] [ sq ] sigma ."
"338350" "338350"
} ; } ;
@ -33,7 +33,7 @@ HELP: count
{ $values { "seq" sequence } { "quot" quotation } { "n" integer } } { $values { "seq" sequence } { "quot" quotation } { "n" integer } }
{ $description "Efficiently returns the number of elements that the predicate quotation matches." } { $description "Efficiently returns the number of elements that the predicate quotation matches." }
{ $example { $example
"USING: math.ranges combinators.lib ;" "USING: math math.ranges sequences.lib prettyprint ;"
"100 [1,b] [ even? ] count ." "100 [1,b] [ even? ] count ."
"50" "50"
} ; } ;

View File

@ -8,7 +8,7 @@ HELP: serialize
} }
{ $description "Serializes the object to the current output stream. Object references within the structure being serialized are maintained." } { $description "Serializes the object to the current output stream. Object references within the structure being serialized are maintained." }
{ $examples { $examples
{ $example "USING: serialize io.streams.string ;" "binary [ { 1 2 } serialize ] with-byte-writer\n\nbinary [ deserialize ] with-byte-reader ." "{ 1 2 }" } { $example "USING: serialize io.encodings.binary io.streams.byte-array prettyprint ;" "binary [ { 1 2 } serialize ] with-byte-writer\n\nbinary [ deserialize ] with-byte-reader ." "{ 1 2 }" }
} }
{ $see-also deserialize } ; { $see-also deserialize } ;
@ -17,6 +17,6 @@ HELP: deserialize
} }
{ $description "Deserializes an object by reading from the current input stream. Object references within the structure that was originally serialized are maintained." } { $description "Deserializes an object by reading from the current input stream. Object references within the structure that was originally serialized are maintained." }
{ $examples { $examples
{ $example "USING: serialize io.streams.string ;" "binary [ { 1 2 } serialize ] with-byte-writer\n\nbinary [ deserialize ] with-byte-reader ." "{ 1 2 }" } { $example "USING: serialize io.encodings.binary io.streams.byte-array prettyprint ;" "binary [ { 1 2 } serialize ] with-byte-writer\n\nbinary [ deserialize ] with-byte-reader ." "{ 1 2 }" }
} }
{ $see-also serialize } ; { $see-also serialize } ;

View File

@ -11,7 +11,7 @@ HELP: npick
"placed on the top of the stack." "placed on the top of the stack."
} }
{ $examples { $examples
{ $example "USE: shuffle" "1 2 3 4 4 npick .s" "1\n2\n3\n4\n1" } { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 npick .s" "1\n2\n3\n4\n1" }
} }
{ $see-also dup over pick } ; { $see-also dup over pick } ;
@ -23,7 +23,7 @@ HELP: ndup
"placed on the top of the stack." "placed on the top of the stack."
} }
{ $examples { $examples
{ $example "USE: shuffle" "1 2 3 4 4 ndup .s" "1\n2\n3\n4\n1\n2\n3\n4" } { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 ndup .s" "1\n2\n3\n4\n1\n2\n3\n4" }
} }
{ $see-also dup 2dup 3dup } ; { $see-also dup 2dup 3dup } ;
@ -34,7 +34,7 @@ HELP: nnip
"for any number of items." "for any number of items."
} }
{ $examples { $examples
{ $example "USE: shuffle" "1 2 3 4 3 nnip .s" "4" } { $example "USING: prettyprint shuffle ;" "1 2 3 4 3 nnip .s" "4" }
} }
{ $see-also nip 2nip } ; { $see-also nip 2nip } ;
@ -45,7 +45,7 @@ HELP: ndrop
"for any number of items." "for any number of items."
} }
{ $examples { $examples
{ $example "USE: shuffle" "1 2 3 4 3 ndrop .s" "1" } { $example "USING: prettyprint shuffle ;" "1 2 3 4 3 ndrop .s" "1" }
} }
{ $see-also drop 2drop 3drop } ; { $see-also drop 2drop 3drop } ;
@ -55,7 +55,7 @@ HELP: nrot
"number of items on the stack. " "number of items on the stack. "
} }
{ $examples { $examples
{ $example "USE: shuffle" "1 2 3 4 4 nrot .s" "2\n3\n4\n1" } { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 nrot .s" "2\n3\n4\n1" }
} }
{ $see-also rot -nrot } ; { $see-also rot -nrot } ;
@ -65,7 +65,7 @@ HELP: -nrot
"number of items on the stack. " "number of items on the stack. "
} }
{ $examples { $examples
{ $example "USE: shuffle" "1 2 3 4 4 -nrot .s" "4\n1\n2\n3" } { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 -nrot .s" "4\n1\n2\n3" }
} }
{ $see-also rot nrot } ; { $see-also rot nrot } ;

View File

@ -8,7 +8,7 @@ HELP: SINGLETON:
} { $description } { $description
"Defines a new predicate class whose superclass is " { $link word } ". Only one instance of a singleton may exist because classes are " { $link eq? } " to themselves. Methods may be defined on a singleton." "Defines a new predicate class whose superclass is " { $link word } ". Only one instance of a singleton may exist because classes are " { $link eq? } " to themselves. Methods may be defined on a singleton."
} { $examples } { $examples
{ $example "SINGLETON: foo\nGENERIC: bar ( obj -- )\nM: foo bar drop \"a foo!\" print ;\nfoo bar" "a foo!" } { $example "USING: singleton kernel io ;" "SINGLETON: foo\nGENERIC: bar ( obj -- )\nM: foo bar drop \"a foo!\" print ;\nfoo bar" "a foo!" }
} { $see-also } { $see-also
POSTPONE: PREDICATE: POSTPONE: PREDICATE:
} ; } ;
@ -20,7 +20,7 @@ HELP: SINGLETONS:
} { $description } { $description
"Defines a new singleton for each class in the list." "Defines a new singleton for each class in the list."
} { $examples } { $examples
{ $example "SINGLETONS: foo bar baz ;" "" } { $example "USE: singleton" "SINGLETONS: foo bar baz ;" "" }
} { $see-also } { $see-also
POSTPONE: SINGLETON: POSTPONE: SINGLETON:
} ; } ;

View File

@ -5,5 +5,5 @@ HELP: SYMBOLS:
{ $syntax "SYMBOLS: words... ;" } { $syntax "SYMBOLS: words... ;" }
{ $values { "words" "a sequence of new words to define" } } { $values { "words" "a sequence of new words to define" } }
{ $description "Creates a new word for every token until the ';'." } { $description "Creates a new word for every token until the ';'." }
{ $examples { $example "SYMBOLS: foo bar baz ;\nfoo . bar . baz ." "foo\nbar\nbaz" } } { $examples { $example "USING: prettyprint symbols ;" "SYMBOLS: foo bar baz ;\nfoo . bar . baz ." "foo\nbar\nbaz" } }
{ $see-also POSTPONE: SYMBOL: } ; { $see-also POSTPONE: SYMBOL: } ;

View File

@ -24,7 +24,7 @@ HELP: runs
{ $values { "seq" "a sequence of integers" } { "newseq" "a sequence of sequences of integers" } } { $values { "seq" "a sequence of integers" } { "newseq" "a sequence of sequences of integers" } }
{ $description "Groups subsequences of consecutive integers." } { $description "Groups subsequences of consecutive integers." }
{ $examples { $examples
{ $example "USE: tools.completion" "{ 1 2 3 5 6 9 10 } runs ." "V{ V{ 1 2 3 } V{ 5 6 } V{ 9 10 } }" } { $example "USING: prettyprint tools.completion ;" "{ 1 2 3 5 6 9 10 } runs ." "V{ V{ 1 2 3 } V{ 5 6 } V{ 9 10 } }" }
} ; } ;
HELP: score HELP: score

View File

@ -33,6 +33,6 @@ M: pair make-disassemble-cmd
: tabs>spaces ( str -- str' ) : tabs>spaces ( str -- str' )
{ { CHAR: \t CHAR: \s } } substitute ; { { CHAR: \t CHAR: \s } } substitute ;
: disassemble ( word -- ) : disassemble ( obj -- )
make-disassemble-cmd run-gdb make-disassemble-cmd run-gdb
[ tabs>spaces ] map [ print ] each ; [ tabs>spaces ] map [ print ] each ;

Some files were not shown because too many files have changed in this diff Show More