Merge branch 'master' of git://factorcode.org/git/factor
Conflicts: core/sequences/sequences-docs.factordb4
commit
4e6a5a772f
|
@ -70,4 +70,7 @@ IN: math.complex.tests
|
|||
[ ] [ C{ 1 4 } coth drop ] unit-test
|
||||
[ ] [ C{ 1 4 } cot drop ] unit-test
|
||||
|
||||
[ t ] [ 0.0 pi rect> exp C{ -1 0 } 1.0e-7 ~ ] unit-test
|
||||
[ t ] [ 0 pi rect> exp C{ -1 0 } 1.0e-7 ~ ] unit-test
|
||||
|
||||
[ "C{ 1/2 2/3 }" ] [ C{ 1/2 2/3 } unparse ] unit-test
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||
! Copyright (C) 2004, 2010 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: math kernel math.constants math.private math.bits
|
||||
math.libm combinators math.order sequences ;
|
||||
|
@ -62,7 +62,7 @@ M: float exp fexp ; inline
|
|||
|
||||
M: real exp >float exp ; inline
|
||||
|
||||
M: complex exp >rect swap fexp swap polar> ; inline
|
||||
M: complex exp >rect swap exp swap polar> ; inline
|
||||
|
||||
<PRIVATE
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ test_program_installed() {
|
|||
|
||||
exit_script() {
|
||||
if [[ $FIND_MAKE_TARGET -eq true ]] ; then
|
||||
echo $MAKE_TARGET;
|
||||
fi
|
||||
exit $1
|
||||
echo $MAKE_TARGET;
|
||||
fi
|
||||
exit $1
|
||||
}
|
||||
|
||||
ensure_program_installed() {
|
||||
|
@ -347,7 +347,7 @@ update_script_name() {
|
|||
|
||||
update_script() {
|
||||
update_script=`update_script_name`
|
||||
bash_path=`which bash`
|
||||
bash_path=`which bash`
|
||||
echo "#!$bash_path" >"$update_script"
|
||||
echo "git pull \"$GIT_URL\" master" >>"$update_script"
|
||||
echo "if [[ \$? -eq 0 ]]; then exec \"$0\" $SCRIPT_ARGS; else echo \"git pull failed\"; exit 2; fi" \
|
||||
|
@ -433,7 +433,7 @@ make_factor() {
|
|||
update_boot_images() {
|
||||
echo "Deleting old images..."
|
||||
$DELETE checksums.txt* > /dev/null 2>&1
|
||||
# delete boot images with one or two characters after the dot
|
||||
# delete boot images with one or two characters after the dot
|
||||
$DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1
|
||||
$DELETE temp/staging.*.image > /dev/null 2>&1
|
||||
if [[ -f $BOOT_IMAGE ]] ; then
|
||||
|
|
|
@ -11,15 +11,13 @@ $nl
|
|||
{ $code
|
||||
"GENERIC: explain ( object -- )"
|
||||
"M: object explain drop \"an object\" print ;"
|
||||
"M: number explain drop \"a number\" print ;"
|
||||
"M: sequence explain drop \"a sequence\" print ;"
|
||||
"M: generic explain drop \"a class word\" print ;"
|
||||
"M: class explain drop \"a generic word\" print ;"
|
||||
}
|
||||
"The linear order is the following, from least-specific to most-specific:"
|
||||
{ $code "{ object sequence number }" }
|
||||
"Neither " { $link number } " nor " { $link sequence } " are subclasses of each other, yet their intersection is the non-empty " { $link integer } " class. Calling " { $snippet "explain" } " with an integer on the stack will print " { $snippet "a number" } " because " { $link number } " precedes " { $link sequence } " in the class linearization order. If this was not the desired outcome, define a method on the intersection:"
|
||||
{ $code "M: integer explain drop \"an integer\" print ;" }
|
||||
"Now, the linear order is the following, from least-specific to most-specific:"
|
||||
{ $code "{ object sequence number integer }" }
|
||||
{ $code "{ object generic class }" }
|
||||
"Neither " { $link class } " nor " { $link generic } " are subclasses of each other, and their intersection is non-empty. Calling " { $snippet "explain" } " with a word on the stack that is both a class and a generic word will print " { $snippet "a generic word" } " because " { $link class } " precedes " { $link generic } " in the class linearization order. (One example of a word which is both a class and a generic word is the class of classes, " { $link class } ", which is also a word to get the class of an object.)"
|
||||
$nl
|
||||
"The " { $link order } " word can be useful to clarify method dispatch order:"
|
||||
{ $subsections order } ;
|
||||
|
||||
|
|
|
@ -29,12 +29,12 @@ $nl
|
|||
ABOUT: "number-strings"
|
||||
|
||||
HELP: digits>integer
|
||||
{ $values { "seq" "a sequence of integers" } { "radix" "an integer between 2 and 36" } { "n/f" { $maybe integer } } }
|
||||
{ $values { "seq" "a sequence of integers" } { "radix" "an integer between 2 and 16" } { "n/f" { $maybe integer } } }
|
||||
{ $description "Converts a sequence of digits (with most significant digit first) into an integer." }
|
||||
{ $notes "This is one of the factors of " { $link string>number } "." } ;
|
||||
|
||||
HELP: >digit
|
||||
{ $values { "n" "an integer between 0 and 35" } { "ch" "a character" } }
|
||||
{ $values { "n" "an integer between 0 and 15" } { "ch" "a character" } }
|
||||
{ $description "Outputs a character representation of a digit." }
|
||||
{ $notes "This is one of the factors of " { $link number>string } "." } ;
|
||||
|
||||
|
@ -44,7 +44,7 @@ HELP: digit>
|
|||
{ $notes "This is one of the factors of " { $link string>number } "." } ;
|
||||
|
||||
HELP: base>
|
||||
{ $values { "str" string } { "radix" "an integer between 2 and 36" } { "n/f" "a real number or " { $link f } } }
|
||||
{ $values { "str" string } { "radix" "an integer between 2 and 16" } { "n/f" "a real number or " { $link f } } }
|
||||
{ $description "Creates a real number from a string representation with the given radix. The radix is ignored for floating point literals; they are always taken to be in base 10."
|
||||
$nl
|
||||
"Outputs " { $link f } " if the string does not represent a number." } ;
|
||||
|
@ -84,7 +84,7 @@ $nl
|
|||
{ >hex POSTPONE: HEX: hex> .h } related-words
|
||||
|
||||
HELP: >base
|
||||
{ $values { "n" real } { "radix" "an integer between 2 and 36" } { "str" string } }
|
||||
{ $values { "n" real } { "radix" "an integer between 2 and 16" } { "str" string } }
|
||||
{ $description "Converts a real number into a string representation using the given radix. If the number is a float, the radix is ignored and the output is always in base 10." } ;
|
||||
|
||||
HELP: >bin
|
||||
|
|
|
@ -55,8 +55,11 @@ ERROR: staging-violation word ;
|
|||
execute( accum -- accum ) ;
|
||||
|
||||
: scan-object ( -- object )
|
||||
scan-word dup parsing-word?
|
||||
[ V{ } clone swap execute-parsing first ] when ;
|
||||
scan-word {
|
||||
{ [ dup not ] [ unexpected-eof ] }
|
||||
{ [ dup parsing-word? ] [ V{ } clone swap execute-parsing first ] }
|
||||
[ ]
|
||||
} cond ;
|
||||
|
||||
: parse-step ( accum end -- accum ? )
|
||||
scan-word {
|
||||
|
|
|
@ -1409,16 +1409,21 @@ ARTICLE: "virtual-sequences" "Virtual sequences"
|
|||
"A virtual sequence is an implementation of the " { $link "sequence-protocol" } " which does not store its own elements, and instead computes them, either from scratch or by retrieving them from another sequence."
|
||||
$nl
|
||||
"Implementations include the following:"
|
||||
{ $subsections reversed slice iota }
|
||||
"Virtual sequences can be implemented with the " { $link "virtual-sequences-protocol" } ", by translating an index in the virtual sequence into an index in another sequence." ;
|
||||
{ $subsections reversed slice }
|
||||
"Virtual sequences can be implemented with the " { $link "virtual-sequences-protocol" } ", by translating an index in the virtual sequence into an index in another sequence."
|
||||
{ $see-also "sequences-integers" } ;
|
||||
|
||||
ARTICLE: "sequences-integers" "Counted loops"
|
||||
"Integers do not support the sequence protocol, but can be turned into virtual sequences using the " { $link iota } " word. For example, the integer 3, when wrapped in an " { $link iota } ", contains the elements 0, 1, and 2. This is very useful for performing counted loops. Note that since this is a virtual sequence, the elements of the sequence are not actually stored, but calculated on demand."
|
||||
"A virtual sequence is defined for iterating over integers from zero."
|
||||
{ $subsection iota }
|
||||
"For example, calling " { $link iota } " on the integer 3 produces a sequence containing the elements 0, 1, and 2. This is very useful for performing counted loops."
|
||||
$nl
|
||||
"As another example, the " { $link each } " combinator, given a sequence, simply calls a quotation on each element of the sequence, ranging from 0 up to the integer wrapped by iota:"
|
||||
"This means the " { $link each } " combinator, given an integer, simply calls a quotation that number of times, pushing a counter on each iteration that ranges from 0 up to that integer:"
|
||||
{ $example "3 iota [ . ] each" "0\n1\n2" }
|
||||
"A common idiom is to iterate over a sequence, while also maintaining a loop counter. This can be done using " { $link each-index } ", " { $link map-index } " and " { $link reduce-index } "."
|
||||
$nl
|
||||
"Combinators that produce new sequences, such as " { $link map } ", will output an array if the input is an instance of " { $link iota } "."
|
||||
$nl
|
||||
"More elaborate counted loops can be performed with " { $link "math.ranges" } "." ;
|
||||
|
||||
ARTICLE: "sequences-if" "Control flow with sequences"
|
||||
|
|
|
@ -30,6 +30,7 @@ M: windows really-delete-tree
|
|||
M: unix really-delete-tree delete-tree ;
|
||||
|
||||
: retry ( n quot -- )
|
||||
[ iota ] dip
|
||||
'[ drop @ f ] attempt-all drop ; inline
|
||||
|
||||
:: upload-safely ( local username host remote -- )
|
||||
|
|
Loading…
Reference in New Issue