From 63a1e604aea683cf852c8b589ed6c4cbf8705332 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 10 Sep 2008 20:07:07 -0500 Subject: [PATCH] make vocabulary --- core/make/make-docs.factor | 30 ++++++++++++++++++++++++++++++ core/make/make.factor | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 core/make/make-docs.factor create mode 100644 core/make/make.factor diff --git a/core/make/make-docs.factor b/core/make/make-docs.factor new file mode 100644 index 0000000000..162d1fc8b6 --- /dev/null +++ b/core/make/make-docs.factor @@ -0,0 +1,30 @@ +IN: make +USING: help.markup help.syntax quotations sequences math.parser +kernel ; + +ARTICLE: "namespaces-make" "Constructing sequences" +"The " { $vocab-link "make" } " vocabulary implements a facility for constructing sequences by holding an accumulator sequence in a variable. Storing the accumulator sequence in a variable rather than the stack may allow code to be written with less stack manipulation." +{ $subsection make } +{ $subsection , } +{ $subsection % } +{ $subsection # } +"The accumulator sequence can be accessed directly:" +{ $subsection building } ; + +ABOUT: "namespaces-make" + +HELP: building +{ $var-description "Temporary mutable growable sequence holding elements accumulated so far by " { $link make } "." } ; + +HELP: make +{ $values { "quot" quotation } { "exemplar" sequence } { "seq" "a new sequence" } } +{ $description "Calls the quotation in a new " { $emphasis "dynamic scope" } ". The quotation and any words it calls can execute the " { $link , } " and " { $link % } " words to accumulate elements. When the quotation returns, all accumulated elements are collected into a sequence with the same type as " { $snippet "exemplar" } "." } +{ $examples { $example "USING: namespaces prettyprint ;" "[ 1 , 2 , 3 , ] { } make ." "{ 1 2 3 }" } } ; + +HELP: , +{ $values { "elt" object } } +{ $description "Adds an element to the end of the sequence being constructed by " { $link make } "." } ; + +HELP: % +{ $values { "seq" sequence } } +{ $description "Appends a sequence to the end of the sequence being constructed by " { $link make } "." } ; diff --git a/core/make/make.factor b/core/make/make.factor new file mode 100644 index 0000000000..f8bdaa1dbb --- /dev/null +++ b/core/make/make.factor @@ -0,0 +1,19 @@ +! Copyright (C) 2003, 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel sequences namespaces ; +IN: make + +SYMBOL: building + +: make ( quot exemplar -- seq ) + [ + [ + 1024 swap new-resizable [ + building set call + ] keep + ] keep like + ] with-scope ; inline + +: , ( elt -- ) building get push ; + +: % ( seq -- ) building get push-all ;