diff --git a/basis/fry/fry-docs.factor b/basis/fry/fry-docs.factor index 286dbb469e..8f402f2e8c 100644 --- a/basis/fry/fry-docs.factor +++ b/basis/fry/fry-docs.factor @@ -15,7 +15,7 @@ HELP: fry } ; HELP: '[ -{ $syntax "code... ]" } +{ $syntax "'[ code... ]" } { $description "Literal fried quotation. Expands into code which takes values from the stack and substitutes them in place of the fry specifiers " { $link _ } " and " { $link @ } "." } { $examples "See " { $link "fry.examples" } "." } ; @@ -49,6 +49,8 @@ $nl "{ 8 13 14 27 } [ even? ] 5 [ dup ] swap [ ? ] curry 3compose map" "{ 8 13 14 27 } [ even? dup 5 ? ] map" } +"The following is a no-op:" +{ $code "'[ @ ]" } "Here are some built-in combinators rewritten in terms of fried quotations:" { $table { { $link literalize } { $snippet ": literalize '[ _ ] ;" } } @@ -74,18 +76,21 @@ ARTICLE: "fry.limitations" "Fried quotation limitations" "As with " { $vocab-link "locals" } ", fried quotations cannot contain " { $link >r } " and " { $link r> } ". This is not a real limitation in practice, since " { $link dip } " can be used instead." ; ARTICLE: "fry" "Fried quotations" -"A " { $emphasis "fried quotation" } " differs from a literal quotation in that when it is evaluated, instead of just pushing itself on the stack, it consumes zero or more stack values and inserts them into the quotation." +"The " { $vocab-link "fry" } " vocabulary implements " { $emphasis "fried quotation" } ". Conceptually, fried quotations are quotations with ``holes'' (more formally, " { $emphasis "fry specifiers" } "), and the holes are filled in when the fried quotation is pushed on the stack." $nl -"Fried quotations are denoted with a special parsing word:" +"Fried quotations are started by a special parsing word:" { $subsection POSTPONE: '[ } -"Fried quotations contain zero or more " { $emphasis "fry specifiers" } ":" +"There are two types of fry specifiers; the first can hold a value, and the second ``splices'' a quotation, as if it were inserted without surrounding brackets:" { $subsection _ } { $subsection @ } -"When a fried quotation is being evaluated, values are consumed from the stack and spliced into the quotation from right to left." +"The holes are filled in with the top of stack going in the rightmost hole, the second item on the stack going in the second hole from the right, and so on." { $subsection "fry.examples" } { $subsection "fry.philosophy" } { $subsection "fry.limitations" } -"Quotations can also be fried without using a parsing word:" -{ $subsection fry } ; +"Fry is implemented as a parsing word which reads a quotation and scans for occurrences of " { $link _ } " and " { $link @ } "; these words are not actually executed, and doing so raises an error (this can happen if they're accidentally used outside of a fry)." +$nl +"Fried quotations can also be constructed without using a parsing word; this is useful when meta-programming:" +{ $subsection fry } +"Fried quotations are an abstraction on top of the " { $link "compositional-combinators" } "; their use is encouraged over the combinators, because often the fry form is shorter and clearer than the combinator form." ; ABOUT: "fry" diff --git a/basis/help/cookbook/cookbook.factor b/basis/help/cookbook/cookbook.factor index 9fb837a873..6e27bd9256 100644 --- a/basis/help/cookbook/cookbook.factor +++ b/basis/help/cookbook/cookbook.factor @@ -1,5 +1,6 @@ USING: help.markup help.syntax io kernel math namespaces parser -prettyprint sequences vocabs.loader namespaces stack-checker ; +prettyprint sequences vocabs.loader namespaces stack-checker +help ; IN: help.cookbook ARTICLE: "cookbook-syntax" "Basic syntax cookbook" @@ -324,6 +325,19 @@ ARTICLE: "cookbook-pitfalls" "Pitfalls to avoid" { "If " { $link run-file } " throws a stack depth assertion, it means that the top-level form in the file left behind values on the stack. The stack depth is compared before and after loading a source file, since this type of situation is almost always an error. If you have a legitimate need to load a source file which returns data in some manner, define a word in the source file which produces this data on the stack and call the word after loading the file." } } ; +ARTICLE: "cookbook-next" "Next steps" +"Once you have read through " { $link "first-program" } " and " { $link "cookbook" } ", the best way to keep learning Factor is to start looking at some simple example programs. Here are a few particularly nice vocabularies which should keep you busy for a little while:" +{ $list + { $vocab-link "base64" } + { $vocab-link "roman" } + { $vocab-link "rot13" } + { $vocab-link "smtp" } + { $vocab-link "time-server" } + { $vocab-link "tools.hexdump" } + { $vocab-link "webapps.counter" } +} +"If you see code in there that you do not understand, use " { $link see } " and " { $link help } " to explore." ; + ARTICLE: "cookbook" "Factor cookbook" "The Factor cookbook is a high-level overview of the most important concepts required to program in Factor." { $subsection "cookbook-syntax" } @@ -336,6 +350,7 @@ ARTICLE: "cookbook" "Factor cookbook" { $subsection "cookbook-scripts" } { $subsection "cookbook-compiler" } { $subsection "cookbook-philosophy" } -{ $subsection "cookbook-pitfalls" } ; +{ $subsection "cookbook-pitfalls" } +{ $subsection "cookbook-next" } ; ABOUT: "cookbook" diff --git a/basis/help/handbook/handbook.factor b/basis/help/handbook/handbook.factor index d1d9ca049a..2ed86a0a19 100644 --- a/basis/help/handbook/handbook.factor +++ b/basis/help/handbook/handbook.factor @@ -65,6 +65,11 @@ $nl { "word" { "the basic unit of code, analogous to a function or procedure in other programming languages. See " { $link "words" } } } } ; +ARTICLE: "tail-call-opt" "Tail-call optimization" +"If the last action performed is the execution of a word, the current quotation is not saved on the call stack; this is known as " { $emphasis "tail-call optimization" } " and the Factor implementation guarantees that it will be performed." +$nl +"Tail-call optimization allows iterative algorithms to be implemented in an efficient manner using recursion, without the need for any kind of primitive looping construct in the language. However, in practice, most iteration is performed via combinators such as " { $link while } ", " { $link each } ", " { $link map } ", " { $link assoc-each } ", and so on. The definitions of these combinators do bottom-out in recursive words, however." ; + ARTICLE: "evaluator" "Evaluation semantics" { $link "quotations" } " are evaluated sequentially from beginning to end. When the end is reached, the quotation returns to its caller. As each object in the quotation is evaluated in turn, an action is taken based on its type:" { $list @@ -72,7 +77,7 @@ ARTICLE: "evaluator" "Evaluation semantics" { "a " { $link wrapper } " - the wrapped object is pushed on the data stack. Wrappers are used to push word objects directly on the stack when they would otherwise execute. See the " { $link POSTPONE: \ } " parsing word." } { "All other types of objects are pushed on the data stack." } } -"If the last action performed is the execution of a word, the current quotation is not saved on the call stack; this is known as " { $snippet "tail-recursion" } " and allows iterative algorithms to execute without incurring unbounded call stack usage." +{ $subsection "tail-call-opt" } { $see-also "compiler" } ; ARTICLE: "objects" "Objects" diff --git a/basis/math/bitwise/bitwise-docs.factor b/basis/math/bitwise/bitwise-docs.factor index 4f2606bda0..9ed164330b 100644 --- a/basis/math/bitwise/bitwise-docs.factor +++ b/basis/math/bitwise/bitwise-docs.factor @@ -310,8 +310,9 @@ ARTICLE: "math-bitfields" "Constructing bit fields" "Some applications, such as binary communication protocols and assemblers, need to construct integers from elaborate bit field specifications. Hand-coding this using " { $link shift } " and " { $link bitor } " results in repetitive code. A higher-level facility exists to factor out this repetition:" { $subsection bitfield } ; -ARTICLE: "math.bitwise" "Bitwise arithmetic" -"The " { $vocab-link "math.bitwise" } " vocabulary can implements bitwise arithmetic words that are useful for efficiency, low-level programming, and interfacing with C libraries." $nl +ARTICLE: "math.bitwise" "Additional bitwise arithmetic" +"The " { $vocab-link "math.bitwise" } " vocabulary provides bitwise arithmetic words extending " { $link "bitwise-arithmetic" } ". They are useful for efficiency, low-level programming, and interfacing with C libraries." +$nl "Setting and clearing bits:" { $subsection set-bit } { $subsection clear-bit } diff --git a/basis/math/geometry/rect/rect-docs.factor b/basis/math/geometry/rect/rect-docs.factor index a892940363..31c9e44b1d 100644 --- a/basis/math/geometry/rect/rect-docs.factor +++ b/basis/math/geometry/rect/rect-docs.factor @@ -47,3 +47,21 @@ HELP: { $values { "rect" "a new " { $link rect } } } { $description "Creates a rectangle located at the origin with zero dimensions." } ; +ARTICLE: "math.geometry.rect" "Rectangles" +"The " { $vocab-link "math.geometry.rect" } " vocabulary defines a rectangle data type and operations on them." +{ $subsection rect } +"Rectangles can be taken apart:" +{ $subsection rect-loc } +{ $subsection rect-dim } +{ $subsection rect-bounds } +{ $subsection rect-extent } +"New rectangles can be created:" +{ $subsection } +{ $subsection } +{ $subsection } +"More utility words for working with rectangles:" +{ $subsection offset-rect } +{ $subsection rect-intersect } +{ $subsection intersects? } ; + +ABOUT: "math.geometry.rect" diff --git a/basis/prettyprint/backend/backend.factor b/basis/prettyprint/backend/backend.factor index 31b6ba3f26..2af0224e32 100644 --- a/basis/prettyprint/backend/backend.factor +++ b/basis/prettyprint/backend/backend.factor @@ -217,14 +217,24 @@ M: vector pprint* pprint-object ; M: byte-vector pprint* pprint-object ; M: hashtable pprint* pprint-object ; +GENERIC: valid-callable? ( obj -- ? ) + +M: object valid-callable? drop f ; + +M: quotation valid-callable? drop t ; + +M: curry valid-callable? quot>> valid-callable? ; + +M: compose valid-callable? + [ first>> ] [ second>> ] bi [ valid-callable? ] both? ; + M: curry pprint* - dup quot>> callable? [ pprint-object ] [ + dup valid-callable? [ pprint-object ] [ "( invalid curry )" swap present-text ] if ; M: compose pprint* - dup [ first>> callable? ] [ second>> callable? ] bi and - [ pprint-object ] [ + dup valid-callable? [ pprint-object ] [ "( invalid compose )" swap present-text ] if ; diff --git a/basis/prettyprint/prettyprint-tests.factor b/basis/prettyprint/prettyprint-tests.factor index 8eaaab3c1d..7fa3c5a1a3 100644 --- a/basis/prettyprint/prettyprint-tests.factor +++ b/basis/prettyprint/prettyprint-tests.factor @@ -365,3 +365,8 @@ M: started-out-hustlin' ended-up-ballin' ; inline [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [ [ { started-out-hustlin' ended-up-ballin' } see ] with-string-writer ] unit-test + +[ "( invalid curry )" ] [ 1 2 curry unparse ] unit-test +[ "( invalid curry )" ] [ 1 2 3 curry curry unparse ] unit-test +[ "( invalid compose )" ] [ 1 2 compose unparse ] unit-test +[ "( invalid compose )" ] [ [ 1 ] 2 3 curry compose unparse ] unit-test diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index f8f9680c16..1992dbcda3 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -267,6 +267,7 @@ IN: tools.deploy.shaker layouts:type-numbers lexer-factory listener:listener-hook + parser:print-use-hook root-cache vocab-roots vocabs:dictionary diff --git a/basis/ui/gadgets/editors/editors.factor b/basis/ui/gadgets/editors/editors.factor index 2cf6d24154..a1c4f3d04e 100644 --- a/basis/ui/gadgets/editors/editors.factor +++ b/basis/ui/gadgets/editors/editors.factor @@ -120,9 +120,10 @@ M: editor ungraft* : scroll>caret ( editor -- ) dup graft-state>> second [ - dup caret-loc over caret-dim - over scroll>rect - ] when drop ; + [ + [ caret-loc ] [ caret-dim { 1 0 } v+ ] bi + ] keep scroll>rect + ] [ drop ] if ; : draw-caret ( -- ) editor get focused?>> [ @@ -452,7 +453,7 @@ editor "caret-motion" f { T{ doc-elt } editor-select-next ; editor "selection" f { - { T{ button-down f { S+ } } extend-selection } + { T{ button-down f { S+ } 1 } extend-selection } { T{ drag } drag-selection } { T{ gain-focus } focus-editor } { T{ lose-focus } unfocus-editor } diff --git a/basis/ui/gadgets/frames/frames.factor b/basis/ui/gadgets/frames/frames.factor index c210d1b7e2..b5c3736896 100644 --- a/basis/ui/gadgets/frames/frames.factor +++ b/basis/ui/gadgets/frames/frames.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2005, 2007 Slava Pestov. +! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays generic kernel math namespaces sequences words splitting grouping math.vectors ui.gadgets.grids ui.gadgets @@ -11,16 +11,16 @@ TUPLE: frame < grid ; : ( -- grid ) 9 [ ] replicate 3 group ; -: @center 1 1 ; -: @left 0 1 ; -: @right 2 1 ; -: @top 1 0 ; -: @bottom 1 2 ; +: @center 1 1 ; inline +: @left 0 1 ; inline +: @right 2 1 ; inline +: @top 1 0 ; inline +: @bottom 1 2 ; inline -: @top-left 0 0 ; -: @top-right 2 0 ; -: @bottom-left 0 2 ; -: @bottom-right 2 2 ; +: @top-left 0 0 ; inline +: @top-right 2 0 ; inline +: @bottom-left 0 2 ; inline +: @bottom-right 2 2 ; inline : new-frame ( class -- frame ) swap new-grid ; inline @@ -28,13 +28,12 @@ TUPLE: frame < grid ; : ( -- frame ) frame new-frame ; -: (fill-center) ( vec n -- ) - over first pick third v+ [v-] 1 rot set-nth ; +: (fill-center) ( n vec -- ) + [ [ first ] [ third ] bi v+ [v-] ] keep set-second ; -: fill-center ( horiz vert dim -- ) - tuck (fill-center) (fill-center) ; +: fill-center ( dim horiz vert -- ) + [ over ] dip [ (fill-center) ] 2bi@ ; M: frame layout* dup compute-grid - [ rot rect-dim fill-center ] 3keep - grid-layout ; + [ [ rect-dim ] 2dip fill-center ] [ grid-layout ] 3bi ; diff --git a/basis/ui/gadgets/labels/labels-tests.factor b/basis/ui/gadgets/labels/labels-tests.factor new file mode 100644 index 0000000000..a9b5074e4c --- /dev/null +++ b/basis/ui/gadgets/labels/labels-tests.factor @@ -0,0 +1,9 @@ +USING: accessors tools.test ui.gadgets ui.gadgets.labels ; +IN: ui.gadgets.labels.tests + +[ { 119 14 } ] [ + { 100 14 } >>dim + { 14 14 } >>dim + label-on-right { 5 5 } >>gap + pref-dim +] unit-test diff --git a/basis/ui/gadgets/panes/panes.factor b/basis/ui/gadgets/panes/panes.factor index ef5745809e..c1b3df3857 100644 --- a/basis/ui/gadgets/panes/panes.factor +++ b/basis/ui/gadgets/panes/panes.factor @@ -363,7 +363,11 @@ M: f sloppy-pick-up* dup hand-rel over sloppy-pick-up >>caret dup relayout-1 ; -: begin-selection ( pane -- ) move-caret f >>mark drop ; +: begin-selection ( pane -- ) + f >>selecting? + move-caret + f >>mark + drop ; : extend-selection ( pane -- ) hand-moved? [ @@ -389,6 +393,7 @@ M: f sloppy-pick-up* ] if ; : select-to-caret ( pane -- ) + t >>selecting? dup mark>> [ caret>mark ] unless move-caret dup request-focus diff --git a/basis/ui/gadgets/scrollers/scrollers-tests.factor b/basis/ui/gadgets/scrollers/scrollers-tests.factor index 625bfd7880..d6792abd49 100644 --- a/basis/ui/gadgets/scrollers/scrollers-tests.factor +++ b/basis/ui/gadgets/scrollers/scrollers-tests.factor @@ -2,7 +2,8 @@ USING: ui.gadgets ui.gadgets.scrollers namespaces tools.test kernel models models.compose models.range ui.gadgets.viewports ui.gadgets.labels ui.gadgets.grids ui.gadgets.frames ui.gadgets.sliders math math.vectors arrays sequences -tools.test.ui math.geometry.rect accessors ; +tools.test.ui math.geometry.rect accessors ui.gadgets.buttons +ui.gadgets.packs ; IN: ui.gadgets.scrollers.tests [ ] [ @@ -74,7 +75,7 @@ dup layout "g2" get scroll>gadget "s" get layout "s" get scroller-value - ] map [ { 3 0 } = ] all? + ] map [ { 2 0 } = ] all? ] unit-test [ ] [ "Hi"