JamesBoer / Jinx

Embeddable scripting language for real-time applications
https://jamesboer.github.io/Jinx/
MIT License
313 stars 11 forks source link

Question: Working with strings #12

Closed Gundolf68 closed 3 years ago

Gundolf68 commented 3 years ago

Hi,

first of all my congratulations for this really cool scripting language - especially the function declarations and the multi word variables: I have never seen anything like this before.

My question is: How to access the content of a string? Something like this:

set s to "Hello"
set c to s[1]
loop x over s
    write line "key = ", x key, ", value = ", x value
end
JamesBoer commented 3 years ago

Thanks for the compliments!

If I recall, I believe it was mostly because I didn't want to have to add a char type, and perhaps partly because Jinx is a fairly high level language, and I didn't see a real demand for it. Thinking a bit more about it, I could support this sort of operation by having the index operator returns a string containing a single character, which would still satisfy the intent of the operation.

If you feel it would be useful to you, let me know, and I'll consider adding support. I don't foresee it being difficult to do.

Gundolf68 commented 3 years ago

If you feel it would be useful to you, let me know, and I'll consider adding support. I don't foresee it being difficult to do.

Many thanks for the offer: I myself don't need this feature at the moment, but I think this would make Jinx a bit more complete and consistent.

Gundolf68 commented 3 years ago

One more question: If I run this code

import core

function the sum of {a} and {b}
    return a + b
end

set x to the sum of 4 and 5
write line x

I get "Error at line 8, column 1: Expected operand". It seems that the "and" in the function signature doesn't work as expected. Shouldn't the precedence of the function call be higher than that of the "and" operator?

JamesBoer commented 3 years ago

Issue has been fixed in development branch. I've also added index operator support for strings.

Gundolf68 commented 3 years ago

Thank you very much!

I am so excited about Jinx that I have started writing a Jinx2Lua-Transpiler : )

JamesBoer commented 3 years ago

Interesting. Best of luck with that. Although a very different language, Jinx definitely has taken some inspiration from Lua.