From: John Benediktsson Date: Fri, 11 Dec 2020 17:58:09 +0000 (-0800) Subject: slots.syntax: moving to basis/ X-Git-Tag: 0.99~2777 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=179e856273c5d12dc42fae50b8019503561ea31f slots.syntax: moving to basis/ --- diff --git a/basis/slots/syntax/authors.txt b/basis/slots/syntax/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/slots/syntax/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/slots/syntax/syntax-docs.factor b/basis/slots/syntax/syntax-docs.factor new file mode 100644 index 0000000000..534b24a2e2 --- /dev/null +++ b/basis/slots/syntax/syntax-docs.factor @@ -0,0 +1,64 @@ +! Copyright (C) 2010 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: help.markup help.syntax ; +IN: slots.syntax + +HELP: slots[ +{ $description "Outputs several slot values to the stack." } +{ $example "USING: kernel prettyprint slots.syntax ;" + "IN: slots.syntax.example" + "TUPLE: rectangle width height ;" + "T{ rectangle { width 3 } { height 5 } } slots[ width height ] [ . ] bi@" + "3 +5" +} ; + +HELP: slots{ +{ $description "Outputs an array of slot values from a tuple." } +{ $example "USING: prettyprint slots.syntax ;" + "IN: slots.syntax.example" + "TUPLE: rectangle width height ;" + "T{ rectangle { width 3 } { height 5 } } slots{ width height } ." + "{ 3 5 }" +} ; + +HELP: set-slots{ +{ $description "Sets slot values in a tuple from an array." } +{ $example "USING: prettyprint slots.syntax kernel ;" + "IN: slots.syntax.example" + "TUPLE: rectangle width height ;" + "rectangle new { 3 5 } set-slots{ width height } ." + "T{ rectangle { width 3 } { height 5 } }" +} ; + +HELP: set-slots[ +{ $description "Sets slot values in a tuple from the stack." } +{ $example "USING: prettyprint slots.syntax kernel ;" + "IN: slots.syntax.example" + "TUPLE: rectangle width height ;" + "rectangle new 3 5 set-slots[ width height ] ." + "T{ rectangle { width 3 } { height 5 } }" +} ; + +HELP: copy-slots{ +{ $description "Copy slots from the first object to the second and return the second object." } +{ $example "USING: prettyprint slots.syntax kernel ;" + "IN: slots.syntax.example" + "TUPLE: thing1 a b ;" + "TUPLE: thing2 a b c ;" + "1 2 thing1 boa 11 22 33 thing2 boa copy-slots{ a b } ." + "T{ thing2 { a 1 } { b 2 } { c 33 } }" +} ; + +ARTICLE: "slots.syntax" "Slots syntax sugar" +"The " { $vocab-link "slots.syntax" } " vocabulary provides an alternative syntax for getting and setting multiple values of a tuple." $nl +"Syntax sugar for cleaving slots to the stack:" +{ $subsections POSTPONE: slots[ POSTPONE: get[ } +"Cleaving slots to an array:" +{ $subsections POSTPONE: slots{ POSTPONE: get{ } +"Setting slots from the stack:" +{ $subsections POSTPONE: set-slots[ POSTPONE: set[ } +"Setting slots from an array:" +{ $subsections POSTPONE: set-slots{ POSTPONE: set{ } ; + +ABOUT: "slots.syntax" diff --git a/basis/slots/syntax/syntax-tests.factor b/basis/slots/syntax/syntax-tests.factor new file mode 100644 index 0000000000..9c3871de83 --- /dev/null +++ b/basis/slots/syntax/syntax-tests.factor @@ -0,0 +1,19 @@ +! Copyright (C) 2010 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel tools.test slots.syntax ; +IN: slots.syntax.tests + +TUPLE: slot-test1 a b c ; + +{ 1 2 3 } [ T{ slot-test1 f 1 2 3 } slots[ a b c ] ] unit-test +{ 3 } [ T{ slot-test1 f 1 2 3 } slots[ c ] ] unit-test +{ } [ T{ slot-test1 f 1 2 3 } slots[ ] ] unit-test + +{ { 1 2 3 } } [ T{ slot-test1 f 1 2 3 } slots{ a b c } ] unit-test +{ { 3 } } [ T{ slot-test1 f 1 2 3 } slots{ c } ] unit-test +{ { } } [ T{ slot-test1 f 1 2 3 } slots{ } ] unit-test + +TUPLE: slot-test2 a b c d ; + +{ T{ slot-test2 f 1 2 33 44 } } +[ 1 2 3 slot-test1 boa 11 22 33 44 slot-test2 boa copy-slots{ a b } ] unit-test diff --git a/basis/slots/syntax/syntax.factor b/basis/slots/syntax/syntax.factor new file mode 100644 index 0000000000..a17bee4c19 --- /dev/null +++ b/basis/slots/syntax/syntax.factor @@ -0,0 +1,40 @@ +! Copyright (C) 2010 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: combinators combinators.smart fry kernel lexer quotations +sequences sequences.generalizations slots words ; +IN: slots.syntax + +SYNTAX: slots[ + "]" [ reader-word 1quotation ] map-tokens + '[ _ cleave ] append! ; + +SYNTAX: slots{ + "}" [ reader-word 1quotation ] map-tokens + '[ [ _ cleave ] output>array ] append! ; + +: >>writer-word ( name -- word ) + ">>" prepend "accessors" lookup-word ; + +: writer-word<< ( name -- word ) + ">>" prepend "accessors" lookup-word ; + +SYNTAX: set-slots[ + "]" [ >>writer-word 1quotation ] map-tokens + '[ _ spread ] append! ; + +SYNTAX: set-slots{ + "}" [ >>writer-word 1quotation ] map-tokens + [ length ] [ ] bi + '[ _ firstn _ spread ] append! ; + +SYNTAX: copy-slots{ + "}" [ + [ reader-word 1quotation ] + [ writer-word<< 1quotation ] bi append + ] map-tokens + '[ swap _ cleave ] append! ; + +SYNTAX: get[ POSTPONE: slots[ ; +SYNTAX: get{ POSTPONE: slots{ ; +SYNTAX: set[ POSTPONE: set-slots[ ; +SYNTAX: set{ POSTPONE: set-slots{ ; diff --git a/extra/slots/syntax/authors.txt b/extra/slots/syntax/authors.txt deleted file mode 100644 index 7c1b2f2279..0000000000 --- a/extra/slots/syntax/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Doug Coleman diff --git a/extra/slots/syntax/syntax-docs.factor b/extra/slots/syntax/syntax-docs.factor deleted file mode 100644 index 534b24a2e2..0000000000 --- a/extra/slots/syntax/syntax-docs.factor +++ /dev/null @@ -1,64 +0,0 @@ -! Copyright (C) 2010 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: help.markup help.syntax ; -IN: slots.syntax - -HELP: slots[ -{ $description "Outputs several slot values to the stack." } -{ $example "USING: kernel prettyprint slots.syntax ;" - "IN: slots.syntax.example" - "TUPLE: rectangle width height ;" - "T{ rectangle { width 3 } { height 5 } } slots[ width height ] [ . ] bi@" - "3 -5" -} ; - -HELP: slots{ -{ $description "Outputs an array of slot values from a tuple." } -{ $example "USING: prettyprint slots.syntax ;" - "IN: slots.syntax.example" - "TUPLE: rectangle width height ;" - "T{ rectangle { width 3 } { height 5 } } slots{ width height } ." - "{ 3 5 }" -} ; - -HELP: set-slots{ -{ $description "Sets slot values in a tuple from an array." } -{ $example "USING: prettyprint slots.syntax kernel ;" - "IN: slots.syntax.example" - "TUPLE: rectangle width height ;" - "rectangle new { 3 5 } set-slots{ width height } ." - "T{ rectangle { width 3 } { height 5 } }" -} ; - -HELP: set-slots[ -{ $description "Sets slot values in a tuple from the stack." } -{ $example "USING: prettyprint slots.syntax kernel ;" - "IN: slots.syntax.example" - "TUPLE: rectangle width height ;" - "rectangle new 3 5 set-slots[ width height ] ." - "T{ rectangle { width 3 } { height 5 } }" -} ; - -HELP: copy-slots{ -{ $description "Copy slots from the first object to the second and return the second object." } -{ $example "USING: prettyprint slots.syntax kernel ;" - "IN: slots.syntax.example" - "TUPLE: thing1 a b ;" - "TUPLE: thing2 a b c ;" - "1 2 thing1 boa 11 22 33 thing2 boa copy-slots{ a b } ." - "T{ thing2 { a 1 } { b 2 } { c 33 } }" -} ; - -ARTICLE: "slots.syntax" "Slots syntax sugar" -"The " { $vocab-link "slots.syntax" } " vocabulary provides an alternative syntax for getting and setting multiple values of a tuple." $nl -"Syntax sugar for cleaving slots to the stack:" -{ $subsections POSTPONE: slots[ POSTPONE: get[ } -"Cleaving slots to an array:" -{ $subsections POSTPONE: slots{ POSTPONE: get{ } -"Setting slots from the stack:" -{ $subsections POSTPONE: set-slots[ POSTPONE: set[ } -"Setting slots from an array:" -{ $subsections POSTPONE: set-slots{ POSTPONE: set{ } ; - -ABOUT: "slots.syntax" diff --git a/extra/slots/syntax/syntax-tests.factor b/extra/slots/syntax/syntax-tests.factor deleted file mode 100644 index 9c3871de83..0000000000 --- a/extra/slots/syntax/syntax-tests.factor +++ /dev/null @@ -1,19 +0,0 @@ -! Copyright (C) 2010 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: kernel tools.test slots.syntax ; -IN: slots.syntax.tests - -TUPLE: slot-test1 a b c ; - -{ 1 2 3 } [ T{ slot-test1 f 1 2 3 } slots[ a b c ] ] unit-test -{ 3 } [ T{ slot-test1 f 1 2 3 } slots[ c ] ] unit-test -{ } [ T{ slot-test1 f 1 2 3 } slots[ ] ] unit-test - -{ { 1 2 3 } } [ T{ slot-test1 f 1 2 3 } slots{ a b c } ] unit-test -{ { 3 } } [ T{ slot-test1 f 1 2 3 } slots{ c } ] unit-test -{ { } } [ T{ slot-test1 f 1 2 3 } slots{ } ] unit-test - -TUPLE: slot-test2 a b c d ; - -{ T{ slot-test2 f 1 2 33 44 } } -[ 1 2 3 slot-test1 boa 11 22 33 44 slot-test2 boa copy-slots{ a b } ] unit-test diff --git a/extra/slots/syntax/syntax.factor b/extra/slots/syntax/syntax.factor deleted file mode 100644 index a17bee4c19..0000000000 --- a/extra/slots/syntax/syntax.factor +++ /dev/null @@ -1,40 +0,0 @@ -! Copyright (C) 2010 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: combinators combinators.smart fry kernel lexer quotations -sequences sequences.generalizations slots words ; -IN: slots.syntax - -SYNTAX: slots[ - "]" [ reader-word 1quotation ] map-tokens - '[ _ cleave ] append! ; - -SYNTAX: slots{ - "}" [ reader-word 1quotation ] map-tokens - '[ [ _ cleave ] output>array ] append! ; - -: >>writer-word ( name -- word ) - ">>" prepend "accessors" lookup-word ; - -: writer-word<< ( name -- word ) - ">>" prepend "accessors" lookup-word ; - -SYNTAX: set-slots[ - "]" [ >>writer-word 1quotation ] map-tokens - '[ _ spread ] append! ; - -SYNTAX: set-slots{ - "}" [ >>writer-word 1quotation ] map-tokens - [ length ] [ ] bi - '[ _ firstn _ spread ] append! ; - -SYNTAX: copy-slots{ - "}" [ - [ reader-word 1quotation ] - [ writer-word<< 1quotation ] bi append - ] map-tokens - '[ swap _ cleave ] append! ; - -SYNTAX: get[ POSTPONE: slots[ ; -SYNTAX: get{ POSTPONE: slots{ ; -SYNTAX: set[ POSTPONE: set-slots[ ; -SYNTAX: set{ POSTPONE: set-slots{ ;