Newsletter
Sed ut perspiciatis unde.
Subscribe
class Rect(left, top, right, bottom)
fun area(r):
let w = r.right - r.left
let h = r.bottom - r.top
w*h
area(Rect(0, 0, 10, 5))
class Rect(left, top, right, bottom)
fun rect_like_to_rect(v):
match v
| Rect(_, _, _, _): v
| {"LT": [l, t], "RB": [r, b]}: Rect(l, t, r, b)
| {"TL": [t, l], "RB": [b, r]}: Rect(l, t, r, b)
rect_like_to_rect({"TL": [0, 2], "RB": [10, 5]})
rect_like_to_rect({"LT": [0, 2], "RB": [10, 5]})
fun all_same([str0, str, ...]):
all(str0 == str, ...)
all_same(["hello", "hello", "hello"])
all_same(["hello", "goodbye", "hello"])
class Posn(x, y)
fun flip_all([Posn(x, y), ...]):
[Posn(y, x), ...]
flip_all([Posn(1, 2), Posn(3, 4)])
flip_all([Posn(5, 6)])
class Tree(val, children :: List.of(Tree)):
method flatten():
for fold(lst = [val]) (child in children):
lst ++ child.flatten()
Tree(1, [Tree(2, [Tree(4, [])]),
Tree(3, [Tree(5, [])])])
.flatten()
class Rect(left, top, right, bottom)
bind.macro 'OriginRect($right, $bottom)':
'Rect(0, 0, $right, $bottom)'
fun area(r):
match r
| OriginRect(r, b): r*b
| Rect(l, t, r, b): (r-l)*(b-t)
area(Rect(0, 0, 10, 5))
6 Comments
rednafi
The syntax looks clean, akin to Python, but with terser record types. This would make a nice config or an embedded language like Lua.
One thing I’d appreciate here is a “Why Rhombus?” page, even if the rationale is simply that it’s fun.
Edit: Turns out there’s a goals[1] page. Rhombus is trying to replace Lisp’s parenthesis-heavy syntax with something cleaner while keeping Racket’s powerful macro support.
[1]: https://rhombus-lang.org/goal.html
lygaret
This is racket's [rhombus], which might be an interesting second link here; it's a scheme, underneath, with the full power of Racket libs available.
[`shrubbery`], the replacement for s-exprs, is pretty interesting, expanding s-expr simply with grouping, and then a separate infix-pass on top. I've been playing with using it as the basis for a separate language; it's in an interesting place in the AST space, especially given the forethought put into macros.
[rhombus]: https://docs.racket-lang.org/rhombus/index.html
[shrubbery]: https://docs.racket-lang.org/shrubbery/index.html
wavemode
From the 2nd example:
class Rect(left, top, right, bottom)
fun rect_like_to_rect(v):
match v
| Rect(_, _, _, _): v
| {"LT": [l, t], "RB": [r, b]}: Rect(l, t, r, b)
| {"TL": [t, l], "RB": [b, r]}: Rect(l, t, r, b)
rect_like_to_rect({"TL": [0, 2], "RB": [10, 5]})
// ⇒ Rect(0, 2, 10, 5)
Isn't this wrong? I'd expect to see Rect(2, 0, 5, 10) instead.
It also seems like "RB" was meant to be "BR".
coolio1232
This actually looks good. It's like a less-obtuse Haskell. At a glance the features seem to be just the right mix of functional programming paradigms and standard imperative programming.
fithisux
Is this a reincarnation of Pyret?
pmontra
The examples on the home page are a nice way to quickly show the features of a language. I'll check the documentation to see how to work with files, make HTTP calls, parse JSON.
It's the first time in more than 10 years that I actually feel like trying a new language. The last time was Elixir. Since then I had to use Lua (hobby project) and Python (work) but I don't enjoy them much. I would have skipped them if I hadn't have to use them. Before Elixir I enjoyed Ruby, before that it's been Perl 5 in the 90s. Everything else I used in that period and before was because I had to (C, Java, PHP, JavaScript/Node) and I skipped many other mainstream languages because they didn't look nice to work with (Go, Rust, TypeScript.) I still have to see what's writing and running a Rhombus programs looks like so I might discover that it's not so nice after all. I'm hopeful.