interpolate: number stack arguments from top of stack.

db4
John Benediktsson 2015-04-20 13:02:09 -07:00
parent 5726f4e207
commit 5251d7c9bc
3 changed files with 8 additions and 6 deletions

View File

@ -4,10 +4,11 @@ IN: interpolate
HELP: interpolate
{ $values { "str" string } }
{ $description "String interpolation using named variables and/or stack arguments, writing to the " { $link output-stream } "." }
{ $notes "Stack arguments are numbered from the top of the stack." }
{ $examples
{ $example
"USING: interpolate ;"
"\"Bob\" \"Alice\" \"Hi ${0}, it's ${1}.\" interpolate"
"\"Bob\" \"Alice\" \"Hi ${1}, it's ${0}.\" interpolate"
"Hi Bob, it's Alice."
}
{ $example
@ -19,6 +20,7 @@ HELP: interpolate
HELP: interpolate>string
{ $values { "str" string } { "newstr" string } }
{ $description "String interpolation using named variables and/or stack arguments, captured as a " { $link string } "." } ;
{ $description "String interpolation using named variables and/or stack arguments, captured as a " { $link string } "." }
{ $notes "Stack arguments are numbered from the top of the stack." } ;
{ interpolate interpolate>string } related-words

View File

@ -3,9 +3,9 @@
USING: interpolate io.streams.string namespaces tools.test locals ;
IN: interpolate.tests
{ "A B" } [ "A" "B" "${0} ${1}" interpolate>string ] unit-test
{ "B A" } [ "A" "B" "${1} ${0}" interpolate>string ] unit-test
{ "C A" } [ "A" "B" "C" "${2} ${0}" interpolate>string ] unit-test
{ "A B" } [ "A" "B" "${1} ${0}" interpolate>string ] unit-test
{ "B A" } [ "A" "B" "${0} ${1}" interpolate>string ] unit-test
{ "C A" } [ "A" "B" "C" "${0} ${2}" interpolate>string ] unit-test
{ "Hello, Jane." } [
"Jane" "name" set

View File

@ -44,7 +44,7 @@ TUPLE: stack-var n ;
name>> quot call '[ _ @ present write ]
] [
dup stack-var? [
n>> vars swap - 1 + '[ _ npick present write ]
n>> 1 + '[ _ npick present write ]
] [
'[ _ write ]
] if