factor/core/generic/math/math-docs.factor

46 lines
2.6 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
USING: kernel generic help.markup help.syntax math classes
2008-03-11 20:51:58 -04:00
sequences quotations ;
IN: generic.math
2007-09-20 18:09:08 -04:00
HELP: math-upgrade
2008-03-11 20:51:58 -04:00
{ $values { "class1" class } { "class2" class } { "quot" "a quotation with stack effect " { $snippet "( n n -- n n )" } } }
2007-09-20 18:09:08 -04:00
{ $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." }
2008-03-11 20:51:58 -04:00
{ $examples { $example "USING: generic.math math kernel prettyprint ;" "fixnum bignum math-upgrade ." "[ [ >bignum ] dip ]" } } ;
2007-09-20 18:09:08 -04:00
HELP: no-math-method
2008-03-11 20:51:58 -04:00
{ $values { "left" "an object" } { "right" "an object" } { "generic" generic } }
2007-09-20 18:09:08 -04:00
{ $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." } ;
HELP: math-method
2008-03-11 20:51:58 -04:00
{ $values { "word" generic } { "class1" class } { "class2" class } { "quot" quotation } }
2007-09-20 18:09:08 -04:00
{ $description "Generates a definition for " { $snippet "word" } " when the two inputs are instances of " { $snippet "class1" } " and " { $snippet "class2" } ", respectively." }
2008-03-20 20:56:30 -04:00
{ $examples { $example "USING: generic.math math prettyprint ;" "\\ + fixnum float math-method ." "[ [ >float ] dip +/float ]" } } ;
2007-09-20 18:09:08 -04:00
HELP: math-class
{ $class-description "The class of subtypes of " { $link number } " which are not " { $link null } "." } ;
HELP: math-combination
2008-03-11 20:51:58 -04:00
{ $values { "word" generic } { "quot" quotation } }
2007-09-20 18:09:08 -04:00
{ $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
"The math method combination is used for binary operators such as " { $link + } " and " { $link * } "."
$nl
"A method can only be added to a generic word using the math combination if the method specializes on one of the below classes, or a union defined over one or more of the below classes:"
{ $code
"fixnum"
"bignum"
"ratio"
"float"
"complex"
"object"
}
"The math combination performs numerical upgrading as described in " { $link "number-protocol" } "." } ;
HELP: math-generic
{ $class-description "The class of generic words using " { $link math-combination } "." } ;
HELP: last/first
2008-03-11 20:51:58 -04:00
{ $values { "seq" sequence } { "pair" "a two-element array" } }
2007-09-20 18:09:08 -04:00
{ $description "Creates an array holding the first and last element of the sequence." } ;