]> gitweb.factorcode.org Git - factor.git/commitdiff
interpolate: number stack arguments from top of stack.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 20 Apr 2015 20:02:09 +0000 (13:02 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 20 Apr 2015 20:02:09 +0000 (13:02 -0700)
basis/interpolate/interpolate-docs.factor
basis/interpolate/interpolate-tests.factor
basis/interpolate/interpolate.factor

index 768b2e9025e78b9f059d560fdba98ddff1b94aec..1f731ec05805a01b9d9a7234840521b5faa7589e 100644 (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
index d456ce0a5c98454889499b96a22ad9d2add8f848..b694878427c8b979f22027690a1583122012d67e 100644 (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
index ccfcf6c7f27ff4439858656b74d9840019bbc633..d8c7c965891f3b7a8987ccfeb71192f3e16c8d55 100644 (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