--- /dev/null
+USING: help.markup help.syntax math strings ;
+IN: interpolate
+
+HELP: ninterpolate
+{ $values { "str" string } { "n" integer } }
+{ $description "Assigns stack arguments to numbered variables for string interpolation." }
+{ $examples
+ { $example "USING: interpolate ;" "\"Bob\" \"Alice\" \"Hi ${0}, it's ${1}.\" 2 ninterpolate" "Hi Bob, it's Alice." }
+}
+{ $see-also interpolate } ;
! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: io kernel macros make multiline namespaces vocabs.parser
-present sequences strings splitting fry accessors ;
+USING: accessors arrays fry hashtables io kernel macros make
+math.parser multiline namespaces present sequences
+sequences.generalizations splitting strings vocabs.parser ;
IN: interpolate
<PRIVATE
SYNTAX: I[
"]I" parse-multiline-string
interpolate-locals append! ;
+
+MACRO: ninterpolate ( str n -- quot )
+ swap '[
+ _ narray [ number>string swap 2array ] map-index
+ >hashtable [ _ interpolate ] with-variables
+ ] ;