Move remaining sequence operations from generalizations to sequences.generalizations where they belong
parent
2dde83767c
commit
ea726f5680
|
@ -1,11 +1,12 @@
|
|||
! (c) 2009 Joe Groff, see BSD license
|
||||
USING: accessors alien alien.c-types alien.complex alien.data alien.parser
|
||||
grouping alien.strings alien.syntax arrays ascii assocs
|
||||
byte-arrays combinators combinators.short-circuit fry generalizations
|
||||
kernel lexer macros math math.parser namespaces parser sequences
|
||||
splitting stack-checker vectors vocabs.parser words locals
|
||||
io.encodings.ascii io.encodings.string shuffle effects math.ranges
|
||||
math.order sorting strings system alien.libraries ;
|
||||
USING: accessors alien alien.c-types alien.complex alien.data
|
||||
alien.parser grouping alien.strings alien.syntax arrays ascii
|
||||
assocs byte-arrays combinators combinators.short-circuit fry
|
||||
generalizations kernel lexer macros math math.parser namespaces
|
||||
parser sequences sequences.generalizations splitting
|
||||
stack-checker vectors vocabs.parser words locals
|
||||
io.encodings.ascii io.encodings.string shuffle effects
|
||||
math.ranges math.order sorting strings system alien.libraries ;
|
||||
QUALIFIED-WITH: alien.c-types c
|
||||
IN: alien.fortran
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
USING: alien alien.strings arrays byte-arrays generic hashtables
|
||||
hashtables.private io io.binary io.files io.encodings.binary
|
||||
io.pathnames kernel kernel.private math namespaces make parser
|
||||
prettyprint sequences strings sbufs vectors words quotations
|
||||
assocs system layouts splitting grouping growable classes
|
||||
classes.private classes.builtin classes.tuple
|
||||
classes.tuple.private vocabs vocabs.loader source-files
|
||||
definitions debugger quotations.private combinators
|
||||
prettyprint sequences sequences.generalizations strings sbufs
|
||||
vectors words quotations assocs system layouts splitting
|
||||
grouping growable classes classes.private classes.builtin
|
||||
classes.tuple classes.tuple.private vocabs vocabs.loader
|
||||
source-files definitions debugger quotations.private combinators
|
||||
combinators.short-circuit math.order math.private accessors
|
||||
slots.private generic.single.private compiler.units
|
||||
compiler.constants fry locals bootstrap.image.syntax
|
||||
|
|
|
@ -4,7 +4,7 @@ USING: accessors checksums checksums.common checksums.stream
|
|||
combinators combinators.smart fry generalizations grouping
|
||||
io.binary kernel literals locals make math math.bitwise
|
||||
math.ranges multiline namespaces sbufs sequences
|
||||
sequences.private splitting strings ;
|
||||
sequences.generalizations sequences.private splitting strings ;
|
||||
IN: checksums.sha
|
||||
|
||||
SINGLETON: sha1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2009 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors fry generalizations kernel macros math.order
|
||||
stack-checker math sequences ;
|
||||
USING: accessors fry generalizations sequences.generalizations
|
||||
kernel macros math.order stack-checker math sequences ;
|
||||
IN: combinators.smart
|
||||
|
||||
MACRO: drop-outputs ( quot -- quot' )
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
! Copyright (C) 2008, 2010 Slava Pestov, Daniel Ehrenberg.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors assocs arrays classes combinators
|
||||
compiler.units fry generalizations generic kernel locals
|
||||
namespaces quotations sequences sets slots words
|
||||
compiler.cfg.instructions compiler.cfg.instructions.syntax
|
||||
compiler.units fry generalizations sequences.generalizations
|
||||
generic kernel locals namespaces quotations sequences sets slots
|
||||
words compiler.cfg.instructions compiler.cfg.instructions.syntax
|
||||
compiler.cfg.rpo ;
|
||||
FROM: namespaces => set ;
|
||||
FROM: sets => members ;
|
||||
|
|
|
@ -6,7 +6,7 @@ compiler.cfg.stacks.local compiler.tree.propagation.info
|
|||
compiler.cfg.instructions
|
||||
cpu.architecture effects fry generalizations
|
||||
kernel locals macros make math namespaces quotations sequences
|
||||
splitting stack-checker words ;
|
||||
sequences.generalizations splitting stack-checker words ;
|
||||
IN: compiler.cfg.intrinsics.simd.backend
|
||||
|
||||
! Selection of implementation based on available CPU instructions
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
! Copyright (C) 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel accessors sequences arrays fry namespaces generic
|
||||
words sets combinators generalizations cpu.architecture compiler.units
|
||||
compiler.cfg.utilities compiler.cfg compiler.cfg.rpo
|
||||
compiler.cfg.instructions compiler.cfg.def-use ;
|
||||
words sets combinators generalizations sequences.generalizations
|
||||
cpu.architecture compiler.units compiler.cfg.utilities
|
||||
compiler.cfg compiler.cfg.rpo compiler.cfg.instructions
|
||||
compiler.cfg.def-use ;
|
||||
FROM: compiler.cfg.instructions.syntax => insn-def-slot insn-use-slots insn-temp-slots scalar-rep ;
|
||||
FROM: namespaces => set ;
|
||||
IN: compiler.cfg.representations.preferred
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
USING: arrays byte-arrays byte-vectors generic assocs hashtables
|
||||
io.binary kernel kernel.private math namespaces make sequences
|
||||
words quotations strings alien.accessors alien.strings layouts
|
||||
system combinators math.bitwise math.order generalizations
|
||||
system combinators math.bitwise math.order combinators.smart
|
||||
accessors growable fry compiler.constants memoize ;
|
||||
IN: compiler.codegen.fixup
|
||||
|
||||
|
@ -138,12 +138,14 @@ MEMO: cached-string>symbol ( symbol -- obj ) string>symbol ;
|
|||
|
||||
: with-fixup ( quot -- code )
|
||||
'[
|
||||
init-fixup
|
||||
@
|
||||
emit-binary-literals
|
||||
label-table [ compute-labels ] change
|
||||
parameter-table get >array
|
||||
literal-table get >array
|
||||
relocation-table get >byte-array
|
||||
label-table get
|
||||
] B{ } make 5 narray ; inline
|
||||
[
|
||||
init-fixup
|
||||
@
|
||||
emit-binary-literals
|
||||
label-table [ compute-labels ] change
|
||||
parameter-table get >array
|
||||
literal-table get >array
|
||||
relocation-table get >byte-array
|
||||
label-table get
|
||||
] B{ } make
|
||||
] output>array ; inline
|
||||
|
|
|
@ -6,9 +6,10 @@ definitions stack-checker.dependencies quotations
|
|||
classes.tuple.private math math.partial-dispatch math.private
|
||||
math.intervals sets.private math.floats.private
|
||||
math.integers.private layouts math.order vectors hashtables
|
||||
combinators effects generalizations assocs sets
|
||||
combinators.short-circuit sequences.private locals growable
|
||||
stack-checker namespaces compiler.tree.propagation.info ;
|
||||
combinators effects generalizations sequences.generalizations
|
||||
assocs sets combinators.short-circuit sequences.private locals
|
||||
growable stack-checker namespaces compiler.tree.propagation.info
|
||||
;
|
||||
FROM: math => float ;
|
||||
FROM: sets => set ;
|
||||
IN: compiler.tree.propagation.transforms
|
||||
|
|
|
@ -2,59 +2,10 @@ USING: help.syntax help.markup kernel sequences quotations
|
|||
math arrays combinators ;
|
||||
IN: generalizations
|
||||
|
||||
HELP: nsequence
|
||||
{ $values { "n" integer } { "seq" "an exemplar" } }
|
||||
{ $description "A generalization of " { $link 2sequence } ", "
|
||||
{ $link 3sequence } ", and " { $link 4sequence } " "
|
||||
"that constructs a sequence from the top " { $snippet "n" } " elements of the stack."
|
||||
}
|
||||
{ $examples
|
||||
{ $example "USING: generalizations prettyprint ;" "CHAR: f CHAR: i CHAR: s CHAR: h 4 \"\" nsequence ." "\"fish\"" }
|
||||
} ;
|
||||
|
||||
HELP: narray
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link 1array } ", "
|
||||
{ $link 2array } ", " { $link 3array } " and " { $link 4array } " "
|
||||
"that constructs an array from the top " { $snippet "n" } " elements of the stack."
|
||||
}
|
||||
{ $examples
|
||||
"Some core words expressed in terms of " { $link narray } ":"
|
||||
{ $table
|
||||
{ { $link 1array } { $snippet "1 narray" } }
|
||||
{ { $link 2array } { $snippet "2 narray" } }
|
||||
{ { $link 3array } { $snippet "3 narray" } }
|
||||
{ { $link 4array } { $snippet "4 narray" } }
|
||||
}
|
||||
} ;
|
||||
|
||||
{ nsequence narray } related-words
|
||||
|
||||
HELP: nsum
|
||||
{ $values { "n" integer } }
|
||||
{ $description "Adds the top " { $snippet "n" } " stack values." } ;
|
||||
|
||||
HELP: firstn
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link first } ", "
|
||||
{ $link first2 } ", " { $link first3 } " and " { $link first4 } " "
|
||||
"that pushes the first " { $snippet "n" } " elements of a sequence on the stack."
|
||||
}
|
||||
{ $examples
|
||||
"Some core words expressed in terms of " { $link firstn } ":"
|
||||
{ $table
|
||||
{ { $link first } { $snippet "1 firstn" } }
|
||||
{ { $link first2 } { $snippet "2 firstn" } }
|
||||
{ { $link first3 } { $snippet "3 firstn" } }
|
||||
{ { $link first4 } { $snippet "4 firstn" } }
|
||||
}
|
||||
} ;
|
||||
|
||||
HELP: set-firstn
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link set-first } " "
|
||||
"that sets the first " { $snippet "n" } " elements of a sequence from the top " { $snippet "n" } " elements of the stack." } ;
|
||||
|
||||
HELP: npick
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link dup } ", "
|
||||
|
@ -302,46 +253,6 @@ HELP: n*quot
|
|||
}
|
||||
{ $description "Construct a quotation containing the contents of " { $snippet "seq" } " repeated " { $snippet "n"} " times." } ;
|
||||
|
||||
HELP: nappend
|
||||
{ $values
|
||||
{ "n" integer }
|
||||
{ "seq" sequence }
|
||||
}
|
||||
{ $description "Outputs a new sequence consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }
|
||||
{ $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }
|
||||
{ $examples
|
||||
{ $example "USING: generalizations prettyprint math ;"
|
||||
"{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 nappend ."
|
||||
"{ 1 2 3 4 5 6 7 8 }"
|
||||
}
|
||||
} ;
|
||||
|
||||
HELP: nappend-as
|
||||
{ $values
|
||||
{ "n" integer } { "exemplar" sequence }
|
||||
{ "seq" sequence }
|
||||
}
|
||||
{ $description "Outputs a new sequence of type " { $snippet "exemplar" } " consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }
|
||||
{ $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }
|
||||
{ $examples
|
||||
{ $example "USING: generalizations prettyprint math ;"
|
||||
"{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 V{ } nappend-as ."
|
||||
"V{ 1 2 3 4 5 6 7 8 }"
|
||||
}
|
||||
} ;
|
||||
|
||||
{ nappend nappend-as } related-words
|
||||
|
||||
ARTICLE: "sequence-generalizations" "Generalized sequence operations"
|
||||
{ $subsections
|
||||
narray
|
||||
nsequence
|
||||
firstn
|
||||
set-firstn
|
||||
nappend
|
||||
nappend-as
|
||||
} ;
|
||||
|
||||
ARTICLE: "shuffle-generalizations" "Generalized shuffle words"
|
||||
{ $subsections
|
||||
ndup
|
||||
|
@ -381,11 +292,10 @@ ARTICLE: "generalizations" "Generalized shuffle words and combinators"
|
|||
"macros where the arity of the input quotations depends on an "
|
||||
"input parameter."
|
||||
{ $subsections
|
||||
"sequence-generalizations"
|
||||
"shuffle-generalizations"
|
||||
"combinator-generalizations"
|
||||
"other-generalizations"
|
||||
}
|
||||
"Also see the " { $vocab-link "sequences.generalizations" } " vocabulary for generalized sequence iteration combinators." ;
|
||||
"Also see the " { $vocab-link "sequences.generalizations" } " vocabulary for generalized sequence operations." ;
|
||||
|
||||
ABOUT: "generalizations"
|
||||
|
|
|
@ -39,24 +39,10 @@ IN: generalizations.tests
|
|||
|
||||
[ { "xyc" "xyd" } ] [ "x" "y" { "c" "d" } [ 3append ] 2 nwith map ] unit-test
|
||||
|
||||
[ 1 2 3 4 ] [ { 1 2 3 4 } 4 firstn ] unit-test
|
||||
[ { 1 2 3 4 } ] [ 1 2 3 4 { f f f f } [ 4 set-firstn ] keep ] unit-test
|
||||
[ 1 2 3 4 { f f f } [ 4 set-firstn ] keep ] must-fail
|
||||
[ ] [ { } 0 firstn ] unit-test
|
||||
[ "a" ] [ { "a" } 1 firstn ] unit-test
|
||||
|
||||
[ [ 1 2 ] ] [ 1 2 2 [ ] nsequence ] unit-test
|
||||
|
||||
[ 4 5 1 2 3 ] [ 1 2 3 4 5 2 3 mnswap ] unit-test
|
||||
|
||||
[ 1 2 3 4 5 6 ] [ 1 2 3 4 5 6 2 4 mnswap 4 2 mnswap ] unit-test
|
||||
|
||||
[ { 1 2 3 4 } ] [ { 1 } { 2 } { 3 } { 4 } 4 nappend ] unit-test
|
||||
[ V{ 1 2 3 4 } ] [ { 1 } { 2 } { 3 } { 4 } 4 V{ } nappend-as ] unit-test
|
||||
|
||||
[ 4 nappend ] must-infer
|
||||
[ 4 { } nappend-as ] must-infer
|
||||
|
||||
[ 17 ] [ 3 1 3 3 7 5 nsum ] unit-test
|
||||
{ 4 1 } [ 4 nsum ] must-infer-as
|
||||
|
||||
|
|
|
@ -14,26 +14,9 @@ ALIAS: n*quot (n*quot)
|
|||
|
||||
>>
|
||||
|
||||
MACRO: nsequence ( n seq -- )
|
||||
[ [nsequence] ] keep
|
||||
'[ @ _ like ] ;
|
||||
|
||||
MACRO: narray ( n -- )
|
||||
'[ _ { } nsequence ] ;
|
||||
|
||||
MACRO: nsum ( n -- )
|
||||
1 - [ + ] n*quot ;
|
||||
|
||||
MACRO: firstn-unsafe ( n -- )
|
||||
[firstn] ;
|
||||
|
||||
MACRO: firstn ( n -- )
|
||||
dup zero? [ drop [ drop ] ] [
|
||||
[ 1 - swap bounds-check 2drop ]
|
||||
[ firstn-unsafe ]
|
||||
bi-curry '[ _ _ bi ]
|
||||
] if ;
|
||||
|
||||
MACRO: npick ( n -- )
|
||||
1 - [ dup ] [ '[ _ dip swap ] ] repeat ;
|
||||
|
||||
|
@ -53,18 +36,6 @@ MACRO: nrot ( n -- )
|
|||
MACRO: -nrot ( n -- )
|
||||
1 - [ ] [ '[ swap _ dip ] ] repeat ;
|
||||
|
||||
MACRO: set-firstn-unsafe ( n -- )
|
||||
[ 1 + ]
|
||||
[ iota [ '[ _ rot [ set-nth-unsafe ] keep ] ] map ] bi
|
||||
'[ _ -nrot _ spread drop ] ;
|
||||
|
||||
MACRO: set-firstn ( n -- )
|
||||
dup zero? [ drop [ drop ] ] [
|
||||
[ 1 - swap bounds-check 2drop ]
|
||||
[ set-firstn-unsafe ]
|
||||
bi-curry '[ _ _ bi ]
|
||||
] if ;
|
||||
|
||||
MACRO: ndrop ( n -- )
|
||||
[ drop ] n*quot ;
|
||||
|
||||
|
@ -143,9 +114,3 @@ MACRO: nweave ( n -- )
|
|||
|
||||
MACRO: nbi-curry ( n -- )
|
||||
[ bi-curry ] n*quot ;
|
||||
|
||||
: nappend-as ( n exemplar -- seq )
|
||||
[ narray concat ] dip like ; inline
|
||||
|
||||
: nappend ( n -- seq ) narray concat ; inline
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ classes.tuple namespaces make vectors bit-arrays byte-arrays
|
|||
strings sbufs math.functions macros sequences.private
|
||||
combinators mirrors splitting combinators.smart
|
||||
combinators.short-circuit fry words.symbol generalizations
|
||||
classes ;
|
||||
sequences.generalizations classes ;
|
||||
IN: inverse
|
||||
|
||||
ERROR: fail ;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays assocs classes classes.tuple fry
|
||||
generalizations hashtables kernel locals locals.backend
|
||||
sequences.generalizations hashtables kernel locals locals.backend
|
||||
locals.errors locals.types make quotations sequences vectors
|
||||
words ;
|
||||
IN: locals.rewrite.sugar
|
||||
|
|
|
@ -4,7 +4,8 @@ USING: logging.server sequences namespaces concurrency.messaging
|
|||
words kernel arrays shuffle tools.annotations
|
||||
prettyprint.config prettyprint debugger io.streams.string
|
||||
splitting continuations effects generalizations parser strings
|
||||
quotations fry accessors math assocs math.order ;
|
||||
quotations fry accessors math assocs math.order
|
||||
sequences.generalizations ;
|
||||
IN: logging
|
||||
|
||||
SYMBOLS: DEBUG NOTICE WARNING ERROR CRITICAL ;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
USING: accessors alien alien.c-types alien.data combinators
|
||||
sequences.cords cpu.architecture fry generalizations grouping
|
||||
kernel libc locals math math.libm math.order math.ranges
|
||||
math.vectors sequences sequences.private specialized-arrays
|
||||
vocabs.loader ;
|
||||
math.vectors sequences sequences.generalizations
|
||||
sequences.private specialized-arrays vocabs.loader ;
|
||||
QUALIFIED-WITH: alien.c-types c
|
||||
SPECIALIZED-ARRAYS:
|
||||
c:char c:short c:int c:longlong
|
||||
|
|
|
@ -3,7 +3,8 @@ cpu.architecture effects fry functors generalizations generic
|
|||
generic.parser kernel lexer literals locals macros math math.functions
|
||||
math.vectors math.vectors.private math.vectors.simd.intrinsics
|
||||
namespaces parser prettyprint.custom quotations sequences
|
||||
sequences.private vocabs vocabs.loader words ;
|
||||
sequences.generalizations sequences.private vocabs vocabs.loader
|
||||
words ;
|
||||
QUALIFIED-WITH: alien.c-types c
|
||||
IN: math.vectors.simd
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
! Copyright (C) 2009, 2010 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: models.arrow models.product stack-checker accessors fry
|
||||
generalizations combinators.smart macros kernel ;
|
||||
generalizations sequences.generalizations combinators.smart
|
||||
macros kernel ;
|
||||
IN: models.arrow.smart
|
||||
|
||||
MACRO: <smart-arrow> ( quot -- quot' )
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors kernel models arrays sequences math math.order
|
||||
models.product generalizations math.functions ;
|
||||
models.product generalizations sequences.generalizations
|
||||
math.functions ;
|
||||
FROM: models.product => product ;
|
||||
IN: models.range
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2008 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: namespaces sequences math.parser kernel macros
|
||||
generalizations locals ;
|
||||
generalizations sequences.generalizations locals ;
|
||||
IN: nmake
|
||||
|
||||
SYMBOL: building-seq
|
||||
|
|
|
@ -6,8 +6,8 @@ USING: alien alien.c-types ascii calendar combinators.short-circuit
|
|||
continuations kernel libc math macros namespaces math.vectors
|
||||
math.parser opengl.gl combinators combinators.smart arrays
|
||||
sequences splitting words byte-arrays assocs vocabs
|
||||
colors colors.constants accessors generalizations locals fry
|
||||
specialized-arrays ;
|
||||
colors colors.constants accessors generalizations
|
||||
sequences.generalizations locals fry specialized-arrays ;
|
||||
FROM: alien.c-types => float ;
|
||||
SPECIALIZED-ARRAY: float
|
||||
SPECIALIZED-ARRAY: uint
|
||||
|
|
|
@ -3,6 +3,85 @@ USING: help.syntax help.markup kernel sequences quotations
|
|||
math arrays combinators ;
|
||||
IN: sequences.generalizations
|
||||
|
||||
HELP: nsequence
|
||||
{ $values { "n" integer } { "seq" "an exemplar" } }
|
||||
{ $description "A generalization of " { $link 2sequence } ", "
|
||||
{ $link 3sequence } ", and " { $link 4sequence } " "
|
||||
"that constructs a sequence from the top " { $snippet "n" } " elements of the stack."
|
||||
}
|
||||
{ $examples
|
||||
{ $example "USING: generalizations prettyprint ;" "CHAR: f CHAR: i CHAR: s CHAR: h 4 \"\" nsequence ." "\"fish\"" }
|
||||
} ;
|
||||
|
||||
HELP: narray
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link 1array } ", "
|
||||
{ $link 2array } ", " { $link 3array } " and " { $link 4array } " "
|
||||
"that constructs an array from the top " { $snippet "n" } " elements of the stack."
|
||||
}
|
||||
{ $examples
|
||||
"Some core words expressed in terms of " { $link narray } ":"
|
||||
{ $table
|
||||
{ { $link 1array } { $snippet "1 narray" } }
|
||||
{ { $link 2array } { $snippet "2 narray" } }
|
||||
{ { $link 3array } { $snippet "3 narray" } }
|
||||
{ { $link 4array } { $snippet "4 narray" } }
|
||||
}
|
||||
} ;
|
||||
|
||||
{ nsequence narray } related-words
|
||||
|
||||
HELP: firstn
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link first } ", "
|
||||
{ $link first2 } ", " { $link first3 } " and " { $link first4 } " "
|
||||
"that pushes the first " { $snippet "n" } " elements of a sequence on the stack."
|
||||
}
|
||||
{ $examples
|
||||
"Some core words expressed in terms of " { $link firstn } ":"
|
||||
{ $table
|
||||
{ { $link first } { $snippet "1 firstn" } }
|
||||
{ { $link first2 } { $snippet "2 firstn" } }
|
||||
{ { $link first3 } { $snippet "3 firstn" } }
|
||||
{ { $link first4 } { $snippet "4 firstn" } }
|
||||
}
|
||||
} ;
|
||||
|
||||
HELP: set-firstn
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link set-first } " "
|
||||
"that sets the first " { $snippet "n" } " elements of a sequence from the top " { $snippet "n" } " elements of the stack." } ;
|
||||
|
||||
HELP: nappend
|
||||
{ $values
|
||||
{ "n" integer }
|
||||
{ "seq" sequence }
|
||||
}
|
||||
{ $description "Outputs a new sequence consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }
|
||||
{ $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }
|
||||
{ $examples
|
||||
{ $example "USING: generalizations prettyprint math ;"
|
||||
"{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 nappend ."
|
||||
"{ 1 2 3 4 5 6 7 8 }"
|
||||
}
|
||||
} ;
|
||||
|
||||
HELP: nappend-as
|
||||
{ $values
|
||||
{ "n" integer } { "exemplar" sequence }
|
||||
{ "seq" sequence }
|
||||
}
|
||||
{ $description "Outputs a new sequence of type " { $snippet "exemplar" } " consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }
|
||||
{ $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }
|
||||
{ $examples
|
||||
{ $example "USING: generalizations prettyprint math ;"
|
||||
"{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 V{ } nappend-as ."
|
||||
"V{ 1 2 3 4 5 6 7 8 }"
|
||||
}
|
||||
} ;
|
||||
|
||||
{ nappend nappend-as } related-words
|
||||
|
||||
HELP: neach
|
||||
{ $values { "seq..." { $snippet "n" } " sequences on the datastack" } { "quot" "a quotation with stack effect " { $snippet "( element... -- )" } } { "n" integer } }
|
||||
{ $description "A generalization of " { $link each } ", " { $link 2each } ", and " { $link 3each } " that can iterate over any number of sequences in parallel." } ;
|
||||
|
@ -31,8 +110,17 @@ HELP: nproduce-as
|
|||
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj1 obj2 ... objn )" } } { "exemplar..." { $snippet "n" } " sequences on the datastack" } { "n" integer } { "seq..." { $snippet "n" } " sequences on the datastack of the same types as the " { $snippet "exemplar" } "s" } }
|
||||
{ $description "A generalization of " { $link produce-as } " that generates " { $snippet "n" } " sequences in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
|
||||
|
||||
ARTICLE: "sequences.generalizations" "Generalized sequence iteration combinators"
|
||||
"The " { $vocab-link "sequences.generalizations" } " vocabulary defines generalized versions of the iteration " { $link "sequences-combinators" } "."
|
||||
ARTICLE: "sequences.generalizations" "Generalized sequence words"
|
||||
"The " { $vocab-link "sequences.generalizations" } " vocabulary defines generalized versions of various sequence operations."
|
||||
{ $subsections
|
||||
narray
|
||||
nsequence
|
||||
firstn
|
||||
set-firstn
|
||||
nappend
|
||||
nappend-as
|
||||
}
|
||||
"Generalized " { $link "sequences-combinators" } ":"
|
||||
{ $subsections
|
||||
neach
|
||||
nmap
|
||||
|
|
|
@ -3,6 +3,20 @@ USING: tools.test generalizations kernel math arrays sequences
|
|||
sequences.generalizations ascii fry math.parser io io.streams.string ;
|
||||
IN: sequences.generalizations.tests
|
||||
|
||||
[ 1 2 3 4 ] [ { 1 2 3 4 } 4 firstn ] unit-test
|
||||
[ { 1 2 3 4 } ] [ 1 2 3 4 { f f f f } [ 4 set-firstn ] keep ] unit-test
|
||||
[ 1 2 3 4 { f f f } [ 4 set-firstn ] keep ] must-fail
|
||||
[ ] [ { } 0 firstn ] unit-test
|
||||
[ "a" ] [ { "a" } 1 firstn ] unit-test
|
||||
|
||||
[ [ 1 2 ] ] [ 1 2 2 [ ] nsequence ] unit-test
|
||||
|
||||
[ { 1 2 3 4 } ] [ { 1 } { 2 } { 3 } { 4 } 4 nappend ] unit-test
|
||||
[ V{ 1 2 3 4 } ] [ { 1 } { 2 } { 3 } { 4 } 4 V{ } nappend-as ] unit-test
|
||||
|
||||
[ 4 nappend ] must-infer
|
||||
[ 4 { } nappend-as ] must-infer
|
||||
|
||||
: neach-test ( a b c d -- )
|
||||
[ 4 nappend print ] 4 neach ;
|
||||
: nmap-test ( a b c d -- e )
|
||||
|
|
|
@ -4,12 +4,47 @@ combinators macros math.order math.ranges quotations fry effects
|
|||
memoize.private generalizations ;
|
||||
IN: sequences.generalizations
|
||||
|
||||
MACRO: nsequence ( n seq -- )
|
||||
[ [nsequence] ] keep
|
||||
'[ @ _ like ] ;
|
||||
|
||||
MACRO: narray ( n -- )
|
||||
'[ _ { } nsequence ] ;
|
||||
|
||||
MACRO: firstn-unsafe ( n -- )
|
||||
[firstn] ;
|
||||
|
||||
MACRO: firstn ( n -- )
|
||||
dup zero? [ drop [ drop ] ] [
|
||||
[ 1 - swap bounds-check 2drop ]
|
||||
[ firstn-unsafe ]
|
||||
bi-curry '[ _ _ bi ]
|
||||
] if ;
|
||||
|
||||
MACRO: set-firstn-unsafe ( n -- )
|
||||
[ 1 + ]
|
||||
[ iota [ '[ _ rot [ set-nth-unsafe ] keep ] ] map ] bi
|
||||
'[ _ -nrot _ spread drop ] ;
|
||||
|
||||
MACRO: set-firstn ( n -- )
|
||||
dup zero? [ drop [ drop ] ] [
|
||||
[ 1 - swap bounds-check 2drop ]
|
||||
[ set-firstn-unsafe ]
|
||||
bi-curry '[ _ _ bi ]
|
||||
] if ;
|
||||
|
||||
: nappend-as ( n exemplar -- seq )
|
||||
[ narray concat ] dip like ; inline
|
||||
|
||||
: nappend ( n -- seq ) narray concat ; inline
|
||||
|
||||
MACRO: nmin-length ( n -- )
|
||||
dup 1 - [ min ] n*quot
|
||||
'[ [ length ] _ napply @ ] ;
|
||||
|
||||
: nnth-unsafe ( n seq... n -- )
|
||||
[ nth-unsafe ] swap [ apply-curry ] [ cleave* ] bi ; inline
|
||||
|
||||
MACRO: nset-nth-unsafe ( n -- )
|
||||
[ [ drop ] ]
|
||||
[ '[ [ set-nth-unsafe ] _ [ apply-curry ] [ cleave-curry ] [ spread* ] tri ] ]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
! Copyright (C) 2007 Chris Double, Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors assocs combinators effects.parser generalizations
|
||||
hashtables kernel locals locals.backend macros make math
|
||||
parser sequences ;
|
||||
USING: accessors assocs combinators effects.parser
|
||||
generalizations sequences.generalizations hashtables kernel
|
||||
locals locals.backend macros make math parser sequences ;
|
||||
IN: shuffle
|
||||
|
||||
<PRIVATE
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
! Copyright (C) 2005, 2010 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors kernel math sorting words parser io summary
|
||||
quotations sequences prettyprint continuations effects
|
||||
definitions compiler.units namespaces assocs tools.time generic
|
||||
inspector fry locals generalizations macros ;
|
||||
quotations sequences sequences.generalizations prettyprint
|
||||
continuations effects definitions compiler.units namespaces
|
||||
assocs tools.time generic inspector fry locals generalizations
|
||||
macros ;
|
||||
IN: tools.annotations
|
||||
|
||||
<PRIVATE
|
||||
|
|
|
@ -4,8 +4,9 @@ USING: accessors arrays assocs binary-search classes
|
|||
classes.struct combinators combinators.smart continuations fry
|
||||
generalizations generic grouping io io.styles kernel make math
|
||||
math.order math.parser math.statistics memory memory.private
|
||||
layouts namespaces parser prettyprint sequences sorting
|
||||
splitting strings system vm words hints hashtables ;
|
||||
layouts namespaces parser prettyprint sequences
|
||||
sequences.generalizations sorting splitting strings system vm
|
||||
words hints hashtables ;
|
||||
IN: tools.memory
|
||||
|
||||
<PRIVATE
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
! Copyright (C) 2003, 2010 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays assocs combinators compiler.units
|
||||
continuations debugger effects fry generalizations io io.files
|
||||
io.styles kernel lexer locals macros math.parser namespaces
|
||||
parser vocabs.parser prettyprint quotations sequences
|
||||
source-files splitting stack-checker summary unicode.case
|
||||
vectors vocabs vocabs.loader vocabs.files vocabs.metadata words
|
||||
tools.errors source-files.errors io.streams.string make
|
||||
compiler.errors ;
|
||||
continuations debugger effects fry generalizations
|
||||
sequences.generalizations io io.files io.styles kernel lexer
|
||||
locals macros math.parser namespaces parser vocabs.parser
|
||||
prettyprint quotations sequences source-files splitting
|
||||
stack-checker summary unicode.case vectors vocabs vocabs.loader
|
||||
vocabs.files vocabs.metadata words tools.errors
|
||||
source-files.errors io.streams.string make compiler.errors ;
|
||||
IN: tools.test
|
||||
|
||||
TUPLE: test-failure < source-file-error continuation ;
|
||||
|
|
|
@ -5,8 +5,8 @@ USING: accessors alien alien.c-types alien.libraries
|
|||
alien.syntax byte-arrays classes.struct combinators
|
||||
combinators.short-circuit combinators.smart continuations
|
||||
generalizations io kernel libc locals macros math namespaces
|
||||
sequences stack-checker strings system unix.time unix.types
|
||||
vocabs vocabs.loader unix.ffi ;
|
||||
sequences sequences.generalizations stack-checker strings system
|
||||
unix.time unix.types vocabs vocabs.loader unix.ffi ;
|
||||
IN: unix
|
||||
|
||||
ERROR: unix-error errno message ;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays assocs combinators
|
||||
combinators.short-circuit fry generalizations inverse kernel
|
||||
namespaces sequences sorting strings unicode.categories
|
||||
xml.data xml.syntax xml.syntax.private ;
|
||||
namespaces sequences sequences.generalizations sorting strings
|
||||
unicode.categories xml.data xml.syntax xml.syntax.private ;
|
||||
IN: xml.syntax.inverse
|
||||
|
||||
: remove-blanks ( seq -- newseq )
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
! Copyright (C) 2005, 2009 Daniel Ehrenberg
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: words assocs kernel accessors parser vocabs.parser effects.parser
|
||||
sequences summary lexer splitting combinators locals
|
||||
memoize sequences.deep xml.data xml.state xml namespaces present
|
||||
arrays generalizations strings make math macros multiline
|
||||
combinators.short-circuit sorting fry unicode.categories
|
||||
effects ;
|
||||
USING: words assocs kernel accessors parser vocabs.parser
|
||||
effects.parser sequences summary lexer splitting combinators
|
||||
locals memoize sequences.deep xml.data xml.state xml namespaces
|
||||
present arrays generalizations sequences.generalizations strings
|
||||
make math macros multiline combinators.short-circuit sorting fry
|
||||
unicode.categories effects ;
|
||||
IN: xml.syntax
|
||||
|
||||
<PRIVATE
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
! (c)2009 Joe Groff bsd license
|
||||
USING: accessors alien audio classes.struct fry calendar alarms
|
||||
combinators combinators.short-circuit destructors generalizations
|
||||
kernel literals locals math openal sequences specialized-arrays strings ;
|
||||
kernel literals locals math openal sequences
|
||||
sequences.generalizations specialized-arrays strings ;
|
||||
QUALIFIED-WITH: alien.c-types c
|
||||
SPECIALIZED-ARRAYS: c:float c:uchar c:uint ;
|
||||
IN: audio.engine
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors combinators combinators.short-circuit
|
||||
generalizations kernel locals math.order math.ranges
|
||||
sequences.parser sequences sorting.functor sorting.slots
|
||||
unicode.categories ;
|
||||
sequences.parser sequences sequences.generalizations
|
||||
sorting.functor sorting.slots unicode.categories ;
|
||||
IN: c.lexer
|
||||
|
||||
: take-c-comment ( sequence-parser -- seq/f )
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
! Copyright (C) 2009 Slava Pestov, Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays assocs classes classes.tuple
|
||||
effects.parser fry generalizations generic.standard kernel
|
||||
lexer locals macros parser sequences sets slots vocabs words ;
|
||||
effects.parser fry generalizations sequences.generalizations
|
||||
generic.standard kernel lexer locals macros parser sequences
|
||||
sets slots vocabs words ;
|
||||
IN: constructors
|
||||
|
||||
! An experiment
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
USING: accessors sequences generalizations io.encodings.utf8 db.postgresql parser combinators vocabs.parser db.sqlite
|
||||
io.files ;
|
||||
IN: db.info
|
||||
! having sensative (and likely to change) information directly in source code seems a bad idea
|
||||
: get-info ( -- lines ) current-vocab name>> "vocab:" "/dbinfo.txt" surround utf8 file-lines ;
|
||||
SYNTAX: get-psql-info <postgresql-db> get-info 5 firstn
|
||||
{
|
||||
[ >>host ]
|
||||
[ >>port ]
|
||||
[ >>username ]
|
||||
[ [ f ] [ ] if-empty >>password ]
|
||||
[ >>database ]
|
||||
} spread suffix! ;
|
||||
|
||||
SYNTAX: get-sqlite-info get-info first <sqlite-db> suffix! ;
|
|
@ -1,9 +1,9 @@
|
|||
! Copyright (c) 2008 Daniel Ehrenberg.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: words kernel sequences locals locals.parser fry
|
||||
locals.definitions accessors parser namespaces continuations
|
||||
summary definitions generalizations arrays prettyprint debugger io
|
||||
effects tools.annotations effects.parser ;
|
||||
USING: words kernel sequences sequences.generalizations locals
|
||||
locals.parser fry locals.definitions accessors parser namespaces
|
||||
continuations summary definitions generalizations arrays
|
||||
prettyprint debugger io effects tools.annotations effects.parser ;
|
||||
IN: descriptive
|
||||
|
||||
ERROR: descriptive-error args underlying word ;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
! (c)Joe Groff bsd license
|
||||
USING: accessors classes.struct fry generalizations kernel locals
|
||||
math math.combinatorics math.functions math.matrices.simd math.vectors
|
||||
math.vectors.simd math.quaternions sequences sequences.private specialized-arrays
|
||||
USING: accessors classes.struct fry generalizations kernel
|
||||
locals math math.combinatorics math.functions math.matrices.simd
|
||||
math.vectors math.vectors.simd math.quaternions sequences
|
||||
sequences.generalizations sequences.private specialized-arrays
|
||||
typed ;
|
||||
FROM: sequences.private => nth-unsafe ;
|
||||
FROM: math.quaternions.private => (q*sign) ;
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
USING: kernel math sequences vectors classes classes.algebra
|
||||
combinators arrays words assocs parser namespaces make
|
||||
definitions prettyprint prettyprint.backend prettyprint.custom
|
||||
quotations generalizations debugger io compiler.units
|
||||
kernel.private effects accessors hashtables sorting shuffle
|
||||
math.order sets see effects.parser ;
|
||||
quotations generalizations sequences.generalizations debugger io
|
||||
compiler.units kernel.private effects accessors hashtables
|
||||
sorting shuffle math.order sets see effects.parser ;
|
||||
FROM: namespaces => set ;
|
||||
IN: multi-methods
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays assocs combinators.short-circuit
|
||||
continuations fry kernel namespaces quotations sequences sets
|
||||
generalizations slots locals.types splitting math
|
||||
locals.rewrite.closures generic words combinators locals smalltalk.ast
|
||||
smalltalk.compiler.lexenv smalltalk.compiler.assignment
|
||||
smalltalk.compiler.return smalltalk.selectors smalltalk.classes ;
|
||||
generalizations sequences.generalizations slots locals.types
|
||||
splitting math locals.rewrite.closures generic words combinators
|
||||
locals smalltalk.ast smalltalk.compiler.lexenv
|
||||
smalltalk.compiler.assignment smalltalk.compiler.return
|
||||
smalltalk.selectors smalltalk.classes ;
|
||||
IN: smalltalk.compiler
|
||||
|
||||
GENERIC: compile-ast ( lexenv ast -- quot )
|
||||
|
|
Loading…
Reference in New Issue