IN: make
-USING: help.markup help.syntax quotations sequences math.parser
-kernel ;
+USING: assocs help.markup help.syntax kernel math.parser
+quotations sequences ;
ARTICLE: "make-philosophy" "Make philosophy"
{ $heading "When to use make" }
HELP: %
{ $values { "seq" sequence } }
{ $description "Appends a sequence to the end of the sequence being constructed by " { $link make } "." } ;
+
+HELP: ,,
+{ $values { "value" object } { "key" object } }
+{ $description "Stores the key/value pair into the assoc being constructed by " { $link make } "." } ;
+
+HELP: %%
+{ $values { "assoc" assoc } }
+{ $description "Adds all entries from " { $snippet "assoc" } " to the assoc being constructed by " { $link make } "." } ;
--- /dev/null
+
+USING: make sequences tools.test ;
+IN: make
+
+{ "ABCD" } [ [ "ABCD" [ , ] each ] "" make ] unit-test
+
+{ H{ { "key" "value" } } }
+[ [ "value" "key" ,, ] H{ } make ] unit-test
+
+{ { { 1 2 } } } [ [ 2 1 ,, ] { } make ] unit-test
! Copyright (C) 2003, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel sequences namespaces ;
+USING: assocs kernel sequences namespaces ;
IN: make
SYMBOL: building
-: make ( quot exemplar -- seq )
+<PRIVATE
+
+: make-sequence ( quot exemplar -- seq )
[
[
32 swap new-resizable [
] keep like
] with-scope ; inline
+: make-assoc ( quot exemplar -- assoc )
+ [
+ 20 swap new-assoc [
+ building set call
+ ] keep
+ ] with-scope ; inline
+
+PRIVATE>
+
+: make ( quot exemplar -- seq )
+ dup sequence? [ make-sequence ] [ make-assoc ] if ; inline
+
: , ( elt -- ) building get push ;
: % ( seq -- ) building get push-all ;
+
+: ,, ( value key -- ) building get set-at ;
+
+: %% ( assoc -- ) building get swap assoc-union! drop ;