diff --git a/basis/html/templates/fhtml/fhtml.factor b/basis/html/templates/fhtml/fhtml.factor index 34783a0b4a..6c5e78e917 100644 --- a/basis/html/templates/fhtml/fhtml.factor +++ b/basis/html/templates/fhtml/fhtml.factor @@ -3,7 +3,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: continuations sequences kernel namespaces debugger combinators math quotations generic strings splitting accessors -assocs fry vocabs.parser parser lexer io io.files +assocs fry vocabs.parser parser parser.notes lexer io io.files io.streams.string io.encodings.utf8 html.templates ; IN: html.templates.fhtml diff --git a/basis/lists/lazy/examples/examples.factor b/basis/lists/lazy/examples/examples.factor index 1d5bb49f35..11047f3e7c 100644 --- a/basis/lists/lazy/examples/examples.factor +++ b/basis/lists/lazy/examples/examples.factor @@ -2,7 +2,7 @@ ! Copyright (C) 2004 Chris Double. ! See http://factorcode.org/license.txt for BSD license. -USING: lists.lazy math kernel sequences quotations ; +USING: lists lists.lazy math kernel sequences quotations ; IN: lists.lazy.examples : naturals ( -- list ) 0 lfrom ; diff --git a/basis/lists/lazy/lazy-docs.factor b/basis/lists/lazy/lazy-docs.factor index 706431d0a2..0b1bfe2d02 100644 --- a/basis/lists/lazy/lazy-docs.factor +++ b/basis/lists/lazy/lazy-docs.factor @@ -14,7 +14,7 @@ ARTICLE: "lists.lazy" "Lazy lists" ARTICLE: { "lists.lazy" "combinators" } "Combinators for manipulating lazy lists" "The following combinators create lazy lists from other lazy lists:" -{ $subsection lmap } +{ $subsection lazy-map } { $subsection lfilter } { $subsection luntil } { $subsection lwhile } diff --git a/basis/lists/lists-docs.factor b/basis/lists/lists-docs.factor index 3fac05affe..1fdce5d51d 100644 --- a/basis/lists/lists-docs.factor +++ b/basis/lists/lists-docs.factor @@ -14,7 +14,7 @@ ARTICLE: "lists" "Lists" { $vocab-subsection "Lazy lists" "lists.lazy" } ; ARTICLE: { "lists" "protocol" } "The list protocol" -"Lists are instances of a mixin class" +"Lists are instances of a mixin class:" { $subsection list } "Instances of the mixin must implement the following words:" { $subsection car } @@ -25,8 +25,7 @@ ARTICLE: { "lists" "strict" } "Constructing strict lists" "Strict lists are simply cons cells where the car and cdr have already been evaluated. These are the lists of Lisp. To construct a strict list, the following words are provided:" { $subsection cons } { $subsection swons } -{ $subsection sequence>cons } -{ $subsection deep-sequence>cons } +{ $subsection sequence>list } { $subsection 1list } { $subsection 2list } { $subsection 3list } ; @@ -38,7 +37,6 @@ ARTICLE: { "lists" "combinators" } "Combinators for lists" { $subsection foldl } { $subsection foldr } { $subsection lmap>array } -{ $subsection lmap-as } { $subsection traverse } ; ARTICLE: { "lists" "manipulation" } "Manipulating lists" @@ -141,10 +139,6 @@ HELP: list>array { $values { "list" list } { "array" array } } { $description "Convert a list into an array." } ; -HELP: deep-list>array -{ $values { "list" list } { "array" array } } -{ $description "Recursively turns the given cons object into an array, maintaining order and also converting nested lists." } ; - HELP: traverse { $values { "list" list } { "pred" { $quotation "( list/elt -- ? )" } } { "quot" { $quotation "( list/elt -- result)" } } { "result" "a new cons object" } } @@ -170,6 +164,3 @@ HELP: lmap>array { $values { "list" list } { "quot" quotation } { "array" array } } { $description "Executes the quotation on each element of the list, collecting the results in an array." } ; -HELP: lmap-as -{ $values { "list" list } { "quot" quotation } { "exemplar" sequence } { "sequence" sequence } } -{ $description "Executes the quotation on each element of the list, collecting the results in a sequence of the type given by the exemplar." } ; diff --git a/basis/lists/lists-tests.factor b/basis/lists/lists-tests.factor index 69daa39e41..e34a719c57 100644 --- a/basis/lists/lists-tests.factor +++ b/basis/lists/lists-tests.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2008 James Cash ! See http://factorcode.org/license.txt for BSD license. -USING: tools.test lists lists.lazy math kernel ; +USING: tools.test lists math kernel ; IN: lists.tests { { 3 4 5 6 7 } } [ - { 1 2 3 4 5 } sequence>cons [ 2 + ] lmap list>array + { 1 2 3 4 5 } sequence>list [ 2 + ] lmap list>array ] unit-test { { 3 4 5 6 } } [ @@ -24,23 +24,23 @@ IN: lists.tests ] unit-test { T{ cons f 2 T{ cons f 3 T{ cons f 4 T{ cons f 5 +nil+ } } } } } [ - { 1 2 3 4 } seq>list [ 1+ ] lmap + { 1 2 3 4 } sequence>list [ 1+ ] lmap ] unit-test { 15 } [ - { 1 2 3 4 5 } seq>list 0 [ + ] foldr + { 1 2 3 4 5 } sequence>list 0 [ + ] foldr ] unit-test { { 5 4 3 2 1 } } [ - { 1 2 3 4 5 } seq>list lreverse list>array + { 1 2 3 4 5 } sequence>list lreverse list>array ] unit-test { 5 } [ - { 1 2 3 4 5 } seq>list llength + { 1 2 3 4 5 } sequence>list llength ] unit-test { { 1 2 3 4 5 6 } } [ - { 1 2 3 } seq>list { 4 5 6 } seq>list lappend list>array + { 1 2 3 } sequence>list { 4 5 6 } sequence>list lappend list>array ] unit-test -[ { 1 } { 2 } ] [ { 1 2 } seq>list 1 lcut [ list>array ] bi@ ] unit-test +[ { 1 } { 2 } ] [ { 1 2 } sequence>list 1 lcut [ list>array ] bi@ ] unit-test diff --git a/basis/lists/lists.factor b/basis/lists/lists.factor index fecb76f1c0..0eedb80889 100644 --- a/basis/lists/lists.factor +++ b/basis/lists/lists.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2008 James Cash +! Copyright (C) 2008 James Cash, Daniel Ehrenberg, Chris Double. ! See http://factorcode.org/license.txt for BSD license. USING: kernel sequences accessors math arrays vectors classes words combinators.short-circuit combinators locals ; @@ -14,57 +14,45 @@ TUPLE: cons { car read-only } { cdr read-only } ; C: cons cons -M: cons car ( cons -- car ) - car>> ; +M: cons car ( cons -- car ) car>> ; -M: cons cdr ( cons -- cdr ) - cdr>> ; +M: cons cdr ( cons -- cdr ) cdr>> ; SINGLETON: +nil+ M: +nil+ nil? drop t ; M: object nil? drop f ; -: atom? ( obj -- ? ) - list? not ; +: atom? ( obj -- ? ) list? not ; inline -: nil ( -- symbol ) +nil+ ; +: nil ( -- symbol ) +nil+ ; inline -: uncons ( cons -- car cdr ) - [ car ] [ cdr ] bi ; +: uncons ( cons -- car cdr ) [ car ] [ cdr ] bi ; inline -: swons ( cdr car -- cons ) - swap cons ; +: swons ( cdr car -- cons ) swap cons ; inline -: unswons ( cons -- cdr car ) - uncons swap ; +: unswons ( cons -- cdr car ) uncons swap ; inline -: 1list ( obj -- cons ) - nil cons ; +: 1list ( obj -- cons ) nil cons ; inline -: 1list? ( list -- ? ) - { [ nil? not ] [ cdr nil? ] } 1&& ; +: 1list? ( list -- ? ) { [ nil? not ] [ cdr nil? ] } 1&& ; inline -: 2list ( a b -- cons ) - nil cons cons ; +: 2list ( a b -- cons ) nil cons cons ; inline -: 3list ( a b c -- cons ) - nil cons cons cons ; +: 3list ( a b c -- cons ) nil cons cons cons ; inline -: cadr ( list -- elt ) - cdr car ; +: cadr ( list -- elt ) cdr car ; inline -: 2car ( list -- car caar ) - [ car ] [ cdr car ] bi ; +: 2car ( list -- car caar ) [ car ] [ cdr car ] bi ; inline -: 3car ( list -- car cadr caddr ) - [ car ] [ cdr car ] [ cdr cdr car ] tri ; +: 3car ( list -- car cadr caddr ) [ car ] [ cdr car ] [ cdr cdr car ] tri ; inline -: lnth ( n list -- elt ) - swap [ cdr ] times car ; +: lnth ( n list -- elt ) swap [ cdr ] times car ; inline : leach ( list quot: ( elt -- ) -- ) @@ -93,49 +81,16 @@ PRIVATE> : lcut ( list index -- before after ) [ nil ] dip - [ [ [ cdr ] [ car ] bi ] dip cons ] times + [ [ unswons ] dip cons ] times lreverse swap ; -: sequence>cons ( sequence -- list ) - nil [ swap cons ] reduce ; - - - -: deep-sequence>cons ( sequence -- cons ) - [ ] keep nil - [ [ nip ] [ same? ] 2bi [ deep-sequence>cons ] when swons ] - with reduce ; - -vector) ( acc list quot: ( elt -- elt' ) -- acc ) - list nil? [ acc ] [ - list car quot call acc push - acc list cdr quot (lmap>vector) - ] if ; inline recursive - -: lmap>vector ( list quot -- array ) - [ V{ } clone ] 2dip (lmap>vector) ; inline -PRIVATE> - -: lmap-as ( list quot exemplar -- sequence ) - [ lmap>vector ] dip like ; inline +: sequence>list ( sequence -- list ) + nil [ swons ] reduce ; : lmap>array ( list quot -- array ) - { } lmap-as ; inline + accumulator [ leach ] dip { } like ; inline -: deep-list>array ( list -- array ) - [ - { - { [ dup nil? ] [ drop { } ] } - { [ dup list? ] [ deep-list>array ] } - [ ] - } cond - ] lmap>array ; - -: list>array ( list -- array ) +: list>array ( list -- array ) [ ] lmap>array ; :: traverse ( list pred quot: ( list/elt -- result ) -- result ) diff --git a/basis/wrap/wrap.factor b/basis/wrap/wrap.factor index 482d50ab5f..c648f6bd61 100644 --- a/basis/wrap/wrap.factor +++ b/basis/wrap/wrap.factor @@ -68,8 +68,7 @@ SYMBOL: line-ideal 0 ; : post-process ( paragraph -- array ) - lines>> deep-list>array - [ [ contents>> ] map ] map ; + lines>> [ [ contents>> ] lmap>array ] lmap>array ; : initialize ( elements -- elements paragraph ) unclip-slice 1paragraph 1array ; diff --git a/core/classes/tuple/tuple-tests.factor b/core/classes/tuple/tuple-tests.factor index 466b221877..e3452194c6 100644 --- a/core/classes/tuple/tuple-tests.factor +++ b/core/classes/tuple/tuple-tests.factor @@ -5,7 +5,7 @@ generic.standard effects classes.tuple classes.tuple.private arrays vectors strings compiler.units accessors classes.algebra calendar prettyprint io.streams.string splitting summary columns math.order classes.private slots slots.private eval see words.symbol -compiler.errors ; +compiler.errors parser.notes ; IN: classes.tuple.tests TUPLE: rect x y w h ; diff --git a/core/parser/notes/notes-tests.factor b/core/parser/notes/notes-tests.factor new file mode 100644 index 0000000000..78fa9e2b73 --- /dev/null +++ b/core/parser/notes/notes-tests.factor @@ -0,0 +1,4 @@ +USING: lexer namespaces parser.notes source-files tools.test ; +IN: parser.notes.tests + +[ ] [ f lexer set f file set "Hello world" note. ] unit-test \ No newline at end of file diff --git a/core/parser/parser-tests.factor b/core/parser/parser-tests.factor index 5cbcc14184..a9e0bd08ab 100644 --- a/core/parser/parser-tests.factor +++ b/core/parser/parser-tests.factor @@ -481,8 +481,6 @@ DEFER: blahy [ "IN: parser.tests USE: kernel TUPLE: blahy < tuple ; : blahy ( -- ) ; TUPLE: blahy < tuple ; : blahy ( -- ) ;" eval( -- ) ] [ error>> error>> def>> \ blahy eq? ] must-fail-with -[ ] [ f lexer set f file set "Hello world" note. ] unit-test - [ "CHAR: \\u9999999999999" eval( -- n ) ] must-fail SYMBOLS: a b c ; diff --git a/extra/parser-combinators/parser-combinators-tests.factor b/extra/parser-combinators/parser-combinators-tests.factor index 70698daa0b..062277ec4d 100755 --- a/extra/parser-combinators/parser-combinators-tests.factor +++ b/extra/parser-combinators/parser-combinators-tests.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2005 Chris Double. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel lists.lazy tools.test strings math +USING: kernel lists lists.lazy tools.test strings math sequences parser-combinators arrays math.parser unicode.categories ; IN: parser-combinators.tests