danilopedraza / komodo

The Komodo programming language code repository
https://komodo-lang.org/
GNU General Public License v3.0
7 stars 0 forks source link

Code blocks #60

Closed danilopedraza closed 2 months ago

danilopedraza commented 3 months ago

Previously, I implemented anonymous functions. Their syntax makes one capable of writing sequences of steps, which was previously impossible outside the first level. I don't think this is a good solution.

Right now, Symstatic for-loops are written like this:

for value in iterable:
    doThing(value)
    println(somethingElse) # outside the loop

The thing is that you can only put one expression into the loop, which is weird, considering the syntax. I think it is a good thing to add indented blocks, because the alternative is to put several expressions in a loop with an anonymous function called in place, like this:

for value in iterable: (value -> (
    doThing(value),
    println(somethingElse)
))(value)

and it is kinda ugly.

danilopedraza commented 2 months ago

I've been thinking of something: Not using whitespace to define blocks, but semicolons. For example:

let f(x) :=
    let y := x + 1;
    y*y

let printAndReturn(x) := println(x); x

The last expression within the succession of expression is the result. It will be easier to code and I won't have to worry about formatting and consistency problems, but it can lead to errors. For example:

let f(x) :=
    let y := x + 1;
    y*y;

let printAndReturn(x):= println(x); x

The only difference between this example and the first is the semicolon after y*y. However, this example defines a single function, which returns the printAndReturn function.

danilopedraza commented 2 months ago

I did it the semicolon way.

danilopedraza commented 2 months ago

That didn't work out at all. I will go with indentation.

danilopedraza commented 2 months ago

I naively implemented the emition of Indent and Dedent tokens. I'll go with the syntax and evaluation now.