Inspired by conversation last night at the virtual meetup, I wrote a blog post to introduce the toy language I’ve been working on.
Inspired by conversation at a recent Future of Coding event, I decided I’d write up a little something about the programming language I’ve been
didn’t mention in the post that the language is called baba yaga just so that I can have .baba
or .yaga
files
This is lovely!
Did you consider some sort of separator like |
between guards/clauses? I've been reading Dijkstra's Discipline , and love the symmetry between his if ... | ... | ... fi
and do ... | ... | ... od
constructs. But your one liner conditionals are much harder to read than his. Particularly when (when!) you get to more than 2 cases on a line. (With 2 cases the _
kinda saves your bacon.)
Then again, Dijkstra is designing for mutation. Maybe you won't need one liners with more than 2 branches..
Do you support curried functions with return types? Some potential for ambiguity there..
A copy pasta from baba yaga’s docs (which you of course haven’t seen because they’re just on my computer)
### Curried Typed Functions
Curried functions take one parameter at a time and return functions for partial application:
```baba
// Curried function with typed first parameter and function return type
mul : (x: Float) -> (Float -> Float) -> y -> x * y;
double : mul 2.0; // Partial application: double : (Float -> Float)
result : double 3.5; // 7.0
// Three-parameter curried function
add3 : (x: Int) -> (Int -> (Int -> Int)) -> y -> z -> x + y + z;
add5 : add3 5; // add5 : (Int -> (Int -> Int))
add5and3 : add5 3; // add5and3 : (Int -> Int)
result : add5and3 2; // 10
Function Type Syntax
Function types use the syntax (ParamType -> ReturnType)
:
// Simple function type
transform : (x: Int) -> (Int -> Int) -> y -> x + y;
// Function that returns another function
makeAdder : (x: Int) -> (Int -> Int) -> y -> x + y;
add5 : makeAdder 5; // add5 : (Int -> Int)
result : add5 3; // 8
Heads up! Complex nested parameter types like (f: (Int -> Int)) aren't implemented. The first parameter must use simple types like Int, Float, String, or Bool. ```
as for the |
— I hadn’t considered it, mostly because I wanted to see how far I could get without having to add extra stuff like that, but I agree, especially for deeply nested when
statements it can get kinda gnarly — I have a sort of functional fmt
command, a la Go’s fmt
that mostly resolves the issues by enforcing some strict, more legible formatting, but I likely will need to noodle on it further
Kartik Agaram — this doesn’t include the fmt
command because I found it to be buggier than I realized, but, I’ve cobbled together a playground where you can actually evaluate code!
Chicken-Legged House; Baba Yaga Playground