r/github • • Jul 15 '20

I made a scripting language for C++ projects, ArkScript

Hey everyone!

I wanted to talk about a project I'm very proud of, ArkScript. I started writing it for a contest, only with an interpreter and not the actual compiler + VM. That's how a (maybe too big) project was born, even after the results came in, I wanted to continue to work on it, to improve it. Performances weren't the first thing I wanted to work on, I wanted to make a language allowing the developper to be productive, and not lost them in a pool of 50+ different keywords, each for a very specific situation, thus we have only 10 of them, the bare minimum in such a language according to me.
I forgot to say that to work on the productivity side, I chose to make a lisp like. Those kind of languages are very easy to understand and use if you know two rules:

  1. everything after a left paren is a function name, and everything after are the arguments

  2. the only exception is when writing the list of arguments of a function, (a b c) isn't "call the function a with arguments b and c"

Starting from there, I had (according to me, thus this isn't objective at all) a quite nice language, allowing me to be more productive than in C++ or Python (again, this is my personnal preference).
Now, why would people chose this language over Lua? Some people would trade productivity for their habits with a "classic language", with {} or begin/end blocks because they see ((((())))) everywhere in lisp like codes. That's true, but I would argue that when you get to understand the power of lisp like languages, you don't see them anymore, and with good plugins in your favourite editor, you can match parens easily and avoid getting lost.

Compared to other languages:

  • compared to lua, we don't have OOP (but a nicer way (imo) to mimick it with closure and closure field's reading) ; also the arrays start at 0 and 1, which is (imo) counter intuitive ; no need for lengthy code using metatables to achieve something, functions and closures are your friends

  • compared to Ruby, we don't use the begin/end syntax for blocks (quite strange to read, but hey, everyone do as they want)

  • compared to Python, we don't use indentation to delimit blocks, avoiding the usual burden of mismatching indentation (tabs vs spaces), but we introduce something else, mismatching parens. Not really a problem, just something I wanted to point out

Thus, here we are: ArkScript-lang/Ark

TL;DR I made a Lisp like programming language to fit my needs and I hope others will find it useful or even come and help making it grow

159 Upvotes

20 comments sorted by

17

u/[deleted] Jul 15 '20

Honestly dude...making your own language is insane and incredible. The work you've done and what you've produced deserve far more upvotes than you're going to receive. Know that. Know it!

2

u/Folaefolc Jul 16 '20

Thanks man, it's really heartwarming to know that people care and find this interesting!

6

u/CommanderHR Jul 16 '20

Finally, a well-documented open source project. Well done man!

2

u/Folaefolc Jul 16 '20

We're still working hard on this part, creating our own doxygen to document the library of the language! Thanks a lot!

4

u/nascarsc Jul 16 '20

And the instructions on forking to contribute. I rarely see that.

4

u/Tagina_Vickler Jul 16 '20

Great work my dude

4

u/daredevildas Jul 16 '20

You might want to post this in r/ProgrammingLanguages ;)

3

u/Folaefolc Jul 16 '20

I did for the first big update, but they weren't so kind...

"Oh you copied lisp because you're lazy, it's an easy work" were the kind of thing some people said

2

u/MrSaltz Jul 16 '20

For some people, belittling and criticizing the work of others is the only way they can feel good about their own work.

3

u/Mr-WINson Jul 16 '20

Best README I’ve seen in a while! Awesome job man!

1

u/Folaefolc Jul 16 '20

Thank you! I really wanted to have something which will make people want to have a look at it, try it, or even just understand the whole structure without downloading it

2

u/hernytan Jul 16 '20

Really nice! I'm always amazed by people who make their own languages

One question though: How is this different from Common Lisp, or Racket? What part of your language explicitly is targeted towards C++ scripting? I think this could be clearer in your README.

1

u/Folaefolc Jul 16 '20

Thanks!

The language uses the standard structure of a program, parens, prefix notation for functions, dynamic typing, but we don't have homoiconicity alas (this is really hard to achieve, but maybe when we'll get to adding macros we'll find a way for this).

Actually all the language is C++ targeted on a way, but that's explained in the embedding documentation, you can very easily create what I call a module, in C++, and import it in ArkScript to use C++ functions from it. Also, I designed the interface (creating a state, a VM) in a way that you won't need to write 100 lines to have something working (I'm looking at you Python (I know pybind exists but Python itself has an interface to be used in C/C++, but it's quite hard to get it to work quickly)). Just create a state, give it some code or a file or a bytecode, and give the state (which has compiled the code for you if needed) to the VM, then call run(). In less than 4 lines of code (assuming your ArkScript code is in a file) it's done, and then you can very easily use the VM (after having ran the code at least once in persistance mode to save the global scope variables values) to retrieve variables, call functions...

I will definitely mark it on my to-do list to add a few more words about that on the readme!

1

u/hernytan Jul 16 '20

I see. Don't really get the gist of it from what you say, probably easier to see the code

Also, you should X-post it to r/programminglanguages who will have more ideas on design

1

u/Folaefolc Jul 16 '20

In term of code, it looks like this: https://arkscript-lang.github.io/tutorials/embedding.html

Thanks for the idea!

2

u/chevian Jul 16 '20

Great work OP! Saving this post for later.

2

u/Folaefolc Jul 16 '20

Thanks! I'm glad you like it

1

u/[deleted] Jul 16 '20

Is this auto-formattable in some way? I'm very lazy. If it's so simple, any lisp-like fmt tools 'just work' right?

Gonna try this soon, it scores high on my personal coolness rating! Nice work!

1

u/Folaefolc Jul 16 '20

In a way yes, in VSC with a few plugins the parens are automatically coloured, and adding a ( adds its ). If we're talking about automatic formatting like putting a function body on a new line and all, we didn't develop anything for that but I'm sure many IDE / editor have this feature somewhere, and yes a lisp like formatting tool would work on ArkScript.

Thanks dude!