25 points · by dsego · 3y ago · 11 comments
(let ((max-stars 5)
(min-stars 0))
...)I for one thinks code-as-s-expressions is almost as bad as code-as-XML.
fn calc :: (x: int) => x
fn calc :: tidy (x: str)
open(str).read()
fn calc :: tidy heap (x: int)
let data: api many(int) = new array.fill(x)(x)
repeat d <- data
print(d)
fn compiletime($i, $T) :: temp (xs: $T*$i)
let data: api many(int) = new array.from(xs)
let sum = xs.reduce(op(+))
sum
fn lotsofparam($i, $T) :: pure (
num: f32,
xs: $T*$i,
ys: api many(str),
zs: api numeric
)
let sum = xs.reduce(op(+))
return sum`heap` is a semantics of `new`: allocate to the global heap `temp` likewise means allocate to a smaller temporary arena `pure` means no allocations and no resources
$vars are compile-time where $lowercase are integers, $UPPERCASE are types.
The type int*10 is a static array, so $T*$i is a compile-time variable but run-time static array.
The `api` keyword is for interface types, it's a syntax transform to a compile-time variable, ie., `fn($T) generic(x: $T)` with a compile-time constraint on $T
I dislike that I can't instantly see which parameter has which type, but I suppose it's the only way to support currying and point-free.
I was going to protest about maintainability - if nobody can read your syntax, they can't maintain your code. But if they can just convert it to their syntax, then they can maintain it.
Even better, certain things may be easier to represent in one syntax than in another. You could write each part in the syntax that works best for it, if that simplifies things, and then convert them into any of the other syntaxes.
One thing that would be essential, though, is that the syntax A -> syntax B -> syntax A round trip gives you back the original code in syntax A (or better - but it can't be worse). If you get back, say, twice as much code when you do the round trip, then you can't convert back and forth for different people and still maintain a workable code base.