boltlang / Bolt

A programming language for rapid application development
35 stars 1 forks source link

Add a 'do' keyword #65

Closed samvv closed 2 months ago

samvv commented 2 months ago

The Problem

I was looking for a good way to introduce new local scopes in Bolt. Currently, Bolt does not support this syntax.

The Solution

Syntactically similar to the do keyword in Haskell, this keyword introduces a new indented block. Semantically, it can be viewed as the { ... } syntax from Rust, because each item in the block will get evaluated from top to bottom.

let foo = x * do 
   let y = 2
   y * y

foo 1 # evaluates to 4

This solution requires adjustments to the type checker and code generator.

samvv commented 2 months ago

Fixed during latest refactor.