]> gitweb.factorcode.org Git - factor.git/blob - extra/slots/syntax/syntax-docs.factor
factor: Make source files/resources 644 instead of 755.
[factor.git] / extra / slots / syntax / syntax-docs.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax ;
4 IN: slots.syntax
5
6 HELP: slots[
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@"
12            "3
13 5"
14 } ;
15
16 HELP: slots{
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 } ."
22            "{ 3 5 }"
23 } ;
24
25 HELP: set-slots{
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 } }"
32 } ;
33
34 HELP: set-slots[
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 } }"
41 } ;
42
43 HELP: copy-slots{
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"
47            "TUPLE: thing1 a b ;"
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 } }"
51 } ;
52
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{ } ;
63
64 ABOUT: "slots.syntax"