Closed causal-agent closed 12 years ago
Bytecode generation shouldn't be copied exactly from Rubinius::AST::DynamicString
... As it says in a comment above the bytecode method for that class it explains how most of the complicated logic in it is purely for optimizing contrived edge cases like "#{foo}"
, "foo#{}"
, and the like. We don't need to do those optimizations (rbx really doesn't either) but you can read that method to get the gist of what we need to do, at least.
As for syntax, I'm somewhat a fan of #form
, e.g. "foo #(+ a b) bar"
or (let [foo 42] "the answer: #foo")
. One problem, though, is that #(+ a b)
resembles the anonymous function syntax proposed in #2, and another is that #foo
can't work if you want to put legal identifier chars after it in the string. For the first problem, we could just use a different character than #
, but I don't know what to do about the second problem. We might just have to use something that encloses the form like #{}
does.
On the other hand, (str "foo " (+ a b) " bar")
isn't so bad. Plus, with the optimization system from #6 we could make that generate as efficient of bytecode as string interpolation would have.
I think this would be quite easy to implement, if only we had a good syntax decided upon. So, do we really want to have this? What syntax should we use?
Since a nice-looking syntax hasn't been thought of yet, I'm going to close this. str
makes this nice enough already:
(str "1 + 2 = " (+ 1 2))
Ruby has the following syntax for string interpolation:
Clojure does not have interpolation.
Bytecode generation can be copied from
Rubinius::AST::DynamicString
.A syntax will need to be decided on. Since one is likely to have a function call inside the interpolation, Ruby's syntax would be awkward in Apricot:
The syntax needs to work for interpolating simple values as well as function calls, preferably without looking awkward.