1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax ;
7 { $description "Outputs several slot values to the stack." }
8 { $example "USING: kernel prettyprint slots.syntax ;"
9 "IN: slots.syntax.example"
10 "TUPLE: rectangle width height ;"
11 "T{ rectangle { width 3 } { height 5 } } slots[ width height ] [ . ] bi@"
17 { $description "Outputs an array of slot values from a tuple." }
18 { $example "USING: prettyprint slots.syntax ;"
19 "IN: slots.syntax.example"
20 "TUPLE: rectangle width height ;"
21 "T{ rectangle { width 3 } { height 5 } } slots{ width height } ."
26 { $description "Sets slot values in a tuple from an array." }
27 { $example "USING: prettyprint slots.syntax kernel ;"
28 "IN: slots.syntax.example"
29 "TUPLE: rectangle width height ;"
30 "rectangle new { 3 5 } set-slots{ width height } ."
31 "T{ rectangle { width 3 } { height 5 } }"
35 { $description "Sets slot values in a tuple from the stack." }
36 { $example "USING: prettyprint slots.syntax kernel ;"
37 "IN: slots.syntax.example"
38 "TUPLE: rectangle width height ;"
39 "rectangle new 3 5 set-slots[ width height ] ."
40 "T{ rectangle { width 3 } { height 5 } }"
44 { $description "Copy slots from the first object to the second and return the second object." }
45 { $example "USING: prettyprint slots.syntax kernel ;"
46 "IN: slots.syntax.example"
48 "TUPLE: thing2 a b c ;"
49 "1 2 thing1 boa 11 22 33 thing2 boa copy-slots{ a b } ."
50 "T{ thing2 { a 1 } { b 2 } { c 33 } }"
53 ARTICLE: "slots.syntax" "Slots syntax sugar"
54 "The " { $vocab-link "slots.syntax" } " vocabulary provides an alternative syntax for getting and setting multiple values of a tuple." $nl
55 "Syntax sugar for cleaving slots to the stack:"
56 { $subsections POSTPONE: slots[ POSTPONE: get[ }
57 "Cleaving slots to an array:"
58 { $subsections POSTPONE: slots{ POSTPONE: get{ }
59 "Setting slots from the stack:"
60 { $subsections POSTPONE: set-slots[ POSTPONE: set[ }
61 "Setting slots from an array:"
62 { $subsections POSTPONE: set-slots{ POSTPONE: set{ } ;