arturo-lang / arturo

Simple, expressive & portable programming language for efficient scripting
http://arturo-lang.io
MIT License
718 stars 32 forks source link

REPL on Windows MSYS2 not allow multiline string #384

Closed celtic-coder closed 2 years ago

celtic-coder commented 2 years ago

Hi Yanis (@drkameleon),

I installed "arturo v/0.9.78" on MSYS2 on Windows. I am going through the In A Nutshell quick-start and came across the following problem with multiline strings:

unterminated-curly-string

Is this a particular problem because I am on Windows?

architecture-version

Is there perhaps something in my setup that might be causing the issue? The reason that I'm using the MSYS2 version on Windows is that the binary is giving the following screen output:

windows-binary-ansi-codes-output

It seems the ANSI escape sequences are not being interpreted correctly. I did some checking and found the article How-to: Use ANSI colors in the terminal. When I ran the listed EchoANSI.CMD, the colours come out correctly:

ANSI-colours

So, I am puzzled on what is causing the problem.

For completeness, I ran the first set of examples in the Windows binary screen but got the same issue with the multiline example:

multiline-error-in-Windows-binary

Further, the Up-Arrow recalls the history in the Windows binary, but just moves up the screen in MSYS2.

Any ideas on what might be happening?

Kind Regards, Liam

github-actions[bot] commented 2 years ago

Thank you for submitting an issue! :)

celtic-coder commented 2 years ago

By the way, I could only find the string "unterminated curly string" in the syntax.UnterminatedString.1.res test case result.

I am curious: where is the code that generates these errors?

drkameleon commented 2 years ago

Liam (@celtic-coder ), Hi!

Let's see...

It seems the ANSI escape sequences are not being interpreted correctly. I did some checking and found the article How-to: Use ANSI colors in the terminal.

Looks like that's exactly the case. That's why I've implemented a little flag (--no-color), especially for Windows terminal (or non fully Unix-compliant ones), which does what you would expect: show all output as before, but without any colors (so as to avoid all this visual clutter).

This is what arturo --no-color looks like on my Mac:

Screenshot 2021-12-02 at 12 52 19

installed "arturo v/0.9.78" on MSYS2 on Windows. I am going through the In A Nutshell quick-start and came across the following problem with multiline strings:

Using the Arturo REPL, you can definitely (at least on Linux & macOS) have multi-line input. The trick is:

# For multi-line input, just add a blank space at the end of a line

So, yes, that way you should be able to enter any multi-line input without problem (if not, just let me know).

E.g.:

Screenshot 2021-12-02 at 12 55 48

Now, regarding multi-line strings specifically, there seems to be an issue with the REPL itself. It's not that you cannot write them, it's that they are interpreted a bit... erroneously.

E.g.

Screenshot 2021-12-02 at 12 57 47

As you can see, using the space-at-the-end-of-the-line trick above, I can surely define a multi-line string as well. The only problem being that, given that the REPL strips the spaces (and apparently newlines) from the end of each input line, the output (multi-line string) seems to be completely omitting the aforementioned newlines.

By the way, I could only find the string "unterminated curly string" in the syntax.UnterminatedString.1.res test case result.

I am curious: where is the code that generates these errors?

You can find everything related to the lexer and parser here:

https://github.com/arturo-lang/arturo/blob/master/src/vm/parse.nim (not too overwhelming, I think/hope 😄 )

Regarding that particular error:

Thanks a lot for all the points - any suggestions/issues you have, feel free to let me know! ✋

celtic-coder commented 2 years ago

Hi Yanis (@drkameleon),

Thank you for looking into this!

I had come across the --no-color option previously in issue #382 (switch to turn off terminal color), where @retsyo had mentioned installing Arturo under MSYS2 (+MinGW64). This is what gave me the idea of trying this kind of install in Windows as an alternative to using the Windows binary.

The multiline string works correctly using the --no-color option in the Windows binary, but as you noted in #386, it does not reproduce the string correctly in the REPL:

multiline-no-color-windows

By the way, when I first tried the --no-color option on the command line, I mistakenly used the non-American spelling of --no-colour, but Arturo did not give an error to show that --no-colour was an invalid command-line option.

I can reproduce your addThemUp function in the Windows binary, so this works correctly. Also, thank you for pointing to the Nim code for the error messages. It was not too overwhelming!

Nim is on my "sometime in the far future" to-do list. The only time previously that I had looked at Nim was checking Fabio Cevasco's (@h3rald) "min" concatenative programming language where I had made some small contributions to the website and the documentation.

Since the Windows binary is essentially working for me using the --no-color option, I will use this going forward.

Thanks again for your prompt response!

Kind Regards, Liam

drkameleon commented 2 years ago

By the way, when I first tried the --no-color option on the command line, I mistakenly used the non-American spelling of --no-colour, but Arturo did not give an error to show that --no-colour was an invalid command-line option.

That's a very good catch. I will look into it.

The multiline string works correctly using the --no-color option in the Windows binary

I can reproduce your addThemUp function in the Windows binary, so this works correctly. Also, thank you for pointing to the Nim code for the error messages. It was not too overwhelming!

Haha. Awesome! Glad that we got it to work! 😃

Nim is on my "sometime in the far future" to-do list. The only time previously that I had looked at Nim was checking Fabio Cevasco's (@h3rald) "min" concatenative programming language where I had made some small contributions to the website and the documentation.

All I can say about Nim is that it is a very good language. Obviously, depending on what you're looking for. I myself wanted a systems programming language. Initially, I start coding Arturo in C. Then, I switched to D (another very interesting one, with very high-level coders behind it) - my main issues against being its speed, bulky binaries and not the easiest installation process of the required components anywhere AFAIK.

Then, I tried Nim. Then, I switched back to C. And finally, as you can see, I settled for Nim. And in the meantime, needless to mention, I went through most of them: Go, Haskell, Zig, V, Crystal, you name it. Many are interesting, but I still settled for Nim. Why? Because it's super performant, pretty much like C or even better in some cases, you still have fine, low-level control of anything you need, but still without having to be too alert about weird things popping up as when writing pure C (especially, regarding Memory management). And on top of it, it does produce ANSI C code (and JavaScript - yep, you can even run Arturo in your browser), so it's flexible and portable. I admit, I'm totally not a fan of its Python-type indentation rules, but I guess I've grown used to it. If I had to mention one slightly negative aspect, that would definitely be the community: they are very good and helpful and all, but there is a certain StackOverflow-ish air to it (meaning some members being a bit over-the-top aggressive or arrogant, at times).

In a few words: if you want to play with it (or contribute to Arturo - which you're more than welcome to! :)), I think you'll find it very - very - easy to start with and you'll be totally at ease in no time. (Despite the obvious similarities, you don't even need to have a Python background - I don't; as a matter of fact, I've never liked it to be perfectly honest)

Re: Min, I've contributed to the project as well. Fabio has done a great job and it's one of the projects that I've been watching too.

Btw, Arturo has more stack-based, concatenative, Factor/Min-style features than it appears to. Ok, of course with some important differences: the syntax is clearly REBOL-ish - although not directly influenced (I discovered its existence and syntax, after designing Arturo), and there is a very strong influence of languages like Ruby (which I love) and Haskell (which I totally admire and respect, not that I've ever managed to write a complete production-level program in it - ever lol)

Have a nice day! 😃

celtic-coder commented 2 years ago

Then, I tried Nim. Then, I switched back to C. And finally, as you can see, I settled for Nim. And in the meantime, needless to mention, I went through most of them: Go, Haskell, Zig, V, Crystal, you name it.

That's quite an eclectic array of languages. I admire your tenacity - well done! 😄

(Despite the obvious similarities, you don't even need to have a Python background - I don't; as a matter of fact, I've never liked it to be perfectly honest)

Ron Aaron, the author of one of the Forth's that I looked into ("8th"), has a similar view of Python. He only tolerates it when he has to do client work in the language. I have an interest in SEO / keyword research and many utilities are written in Python - this is my only reason for pursuing the language.

Btw, Arturo has more stack-based, concatenative, Factor/Min-style features than it appears to.

That is really interesting - I am looking forward to learning more!

Kind Regards, Liam

drkameleon commented 2 years ago

Then, I tried Nim. Then, I switched back to C. And finally, as you can see, I settled for Nim. And in the meantime, needless to mention, I went through most of them: Go, Haskell, Zig, V, Crystal, you name it.

That's quite an eclectic array of languages. I admire your tenacity - well done! 😄

(Despite the obvious similarities, you don't even need to have a Python background - I don't; as a matter of fact, I've never liked it to be perfectly honest)

Ron Aaron, the author of one of the Forth's that I looked into ("8th"), has a similar view of Python. He only tolerates it when he has to do client work in the language. I have an interest in SEO / keyword research and many utilities are written in Python - this is my only reason for pursuing the language.

Well, I guess every programmer has had to write in many, many different languages and mostly we're expected to. Not that it's sooo... difficult, between us. I may have written code in over 50 languages at one point or another, and I guess I could write a program in a language I have never heard of until now in a matter of hours (along with some good reference ofc) - Now, all this, provided that it's not something too outside the mainstream, e.g. Prolog. haha. Then, we'd be talking about something completely different.

Btw, Arturo has more stack-based, concatenative, Factor/Min-style features than it appears to.

That is really interesting - I am looking forward to learning more!

Not that it's recommended (at all), but what you see below obviously works:

Screenshot 2021-12-06 at 10 18 36

This would work too (with a slight twist):

Screenshot 2021-12-06 at 10 20 17

Basically, when you see something like print add 2 3 what happens is:

The whole mechanism behind Arturo is a totally Stack-based bytecode VM.

And let's not forget that we have... ArtSembly too (lol): https://github.com/arturo-lang/artsembly-module

Basically, what you see is nothing but a closer-to-the-metal interpreter of Arturo bytecode, in Arturo, with Arturo syntax. But ultimately it converts to the same thing - only in a more direct way. :)

celtic-coder commented 2 years ago

Basically, when you see something like print add 2 3 what happens is:

* push 3 to the stack

* push 2 to the stack

* perform an add: that is, pop 2 elements from the stack and push back the result

* perform a print: that is pop 1 element from the stack and... print it

This stack-based metaphor is so different -- but I have enjoyed learning about it! I had looked at 8th as the next language to learn, but Arturo caught my attention not just for the Forth aspects, the Rebol syntax, but also that I could use SQLite databases in the background. I have used different types of databases my entire working life (I'm recently retired) -- so, this is something I'm looking forward to learning more about.

Thanks for your committent to this language and its ecosystem! I trust that you will enjoy the fruits of your labour in this endeavour.

Kind Regards, Liam

drkameleon commented 2 years ago

Basically, when you see something like print add 2 3 what happens is:

* push 3 to the stack

* push 2 to the stack

* perform an add: that is, pop 2 elements from the stack and push back the result

* perform a print: that is pop 1 element from the stack and... print it

This stack-based metaphor is so different -- but I have enjoyed learning about it! I had looked at 8th as the next language to learn, but Arturo caught my attention not just for the Forth aspects, the Rebol syntax, but also that I could use SQLite databases in the background. I have used different types of databases my entire working life (I'm recently retired) -- so, this is something I'm looking forward to learning more about.

Thanks for your committent to this language and its ecosystem! I trust that you will enjoy the fruits of your labour in this endeavour.

Kind Regards, Liam

Speaking of databases, my number 1 priority for Arturo (and one of my personal interests at this point) are Graph databases. And that's exactly why Grafito came into existence. I see a lot of potential in graph engines and I most definitely don't think there are optimal solutions yet.

As an example, I've been planning a... mega-project involving linguistics and graphs and decided to go for Neo4j. I loved the infrastructure and their language (Cypher), but when I wanted to experiment with it and setting up a tiny test project on DigitalOcean, I quickly realized you have to have a super-powerful machine (especially, memory-wise) in order to even contemplate setting up a graph db. Hence, I went for an over-simplified experiment with Sqlite in the background (which I'm very fond of, to be perfectly honest) and Arturo's clean syntax. And... it worked, without any extreme system requirements on the most basic and cheapest Droplet you can find on DO.

The result is by no means complete (I doubt whether it currently works 100%), but it will be. Let's see where/how I'll manage to find all the time needed for so many projects! haha

Have a great day!