h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
311 stars 23 forks source link

% Interpolation % #95

Closed ghost closed 3 years ago

ghost commented 3 years ago

"$1 puts" ("a") % eval min code throws an error:

(!) <eval>(1,1) [a]: Undefined symbol 'a'
    <eval>(1,1) in symbol: a
    <repl>(1,22) in symbol: eval
    <repl>(1,23) in symbol: eval
    <repl>(1,23) in symbol: eval

But i expected that it will prints "a" on screen. What is wrong?

h3rald commented 3 years ago

That's correct...

Let's see:

 "$1 puts" ("a") % ; outputs: "a puts"

therefore:

 "a puts" eval

...it's like running: a puts, and in this case of course the symbol a is undefined!

If you want to print the string "a", then you'd have to write "a":

 "$1 puts" ("\"a\"") % eval
ghost commented 3 years ago

I did as like as you and 👍 Good, it puts: "a". However now it focused to format everything that gived in, as string: "$1 puts" (" \"1\" ") % eval ; "1" It puts "1" not 1.

Is there a formatting option which adapted for this thing?

h3rald commented 3 years ago

Well... that's perfectly normal behavior for an eval function, even in other languages: if you want to evaluate strings you have to put them in double quotes, and because you are evaluating a string, you have to escape them.

Honestly I am providing evalfor completeness only, typically you'd want to use load or require, or at any rate evaluate string that is provided from outside, not written as a string literal...

ghost commented 3 years ago

The difference of string formatting, made duplication at whole my code. Probably there is a no real solution for this.