interpolate: adding generalized numbered string interpolate.
parent
094e405713
commit
6ca2fec6cd
|
@ -0,0 +1,10 @@
|
|||
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 } ;
|
|
@ -1,7 +1,8 @@
|
|||
! 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
|
||||
|
@ -41,3 +42,9 @@ MACRO: interpolate ( string -- )
|
|||
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
|
||||
] ;
|
||||
|
|
Loading…
Reference in New Issue