Hacker News new | ask | show | jobs
by cameronkknight 4723 days ago
I never claimed for GorillaScript to be a C-like language, because at its core, stripped of syntax, JavaScript is not a C-like language.

It more resembles LISP with its macros and closures with nice syntax built around those concepts.

I tried to make all the operators match their closest arithmetic, mathematical equivalents. Thus using `^` for exponent and `+` for addition. Since JavaScript does not support bitwise operators cleanly, needing to cast to int32 and generally being disued, I felt they could be better aliased with `bit`, freeing up those operators. Since string concatenation needed some operator as a building block for string interpolation, the freed-up `&` was a ripe candidate for it.

That all said, string interpolation is the typical use case for creating strings, so feel free to just use that if possible. Anything more than that and you might need a templating engine.

2 comments

What do you think about not using any operator (but space+"") for concatenation and using a syntax like this:

    var 1   = 5+5 // I would expect: Error 0-9 cannot be used as a variable
    var foo = "Hello " "Bob!" "\nAre you there?"
    var bar = "Hello " 1

    console.info(1) // throw error and refer to var 1

    console.info(foo)
    "Hello Bob!
    Are you there?"

    console.info(bar)
    "Hello 1"
Juxtaposition as an operator is already used by function invocation, e.g.

    f "Hello"
If f were a string, how would I know I wanted to concat it instead of calling?
By not making () optional. Honestly I get why people hate curly braces, but parenthesis are important, removing them makes a new language hard to understand, making it optional makes the language (horrible or) simply weird and non-deterministic.

There is ZERO technological or efficiency related benefit in making () optional, it just makes your grammar parser more complex and slows down compile/interpretation time.

If I would have time and no specs given, then I would write a compiler for Sanskrit. It's one of the oldest languages and as accurate as AI Agent languages. Really accurate. Just google for "Sanskrit Artificial Intelligence" and you will find very interesting publications. Here's something by NASA: http://www.vedicsciences.net/articles/sanskrit-nasa.html

Btw. I've written a simple language+vm in C already using bison,flex etc. Our Prof and other students made a custom CPU that runs on a custom OS made for this language called Ninja. A friend of mine extended it by Object Orientation later.

I realize you probably also wanted to answer OP, but let me just state that there was no real judgement intended. I am not a C-programmer, it was meant as an explanation.

> Thus using `^` for exponent and `+` for addition

That is good in my eyes.