Languages in broad use today have convenient shortcuts for a lot of things that programmers had to make by hand in the past.
With JavaScript's objects, a developer never has to create an associative array. Associative arrays were such a broadly useful data structure that it just made sense to weave them into language itself. No need to weigh the pros and cons of various hashing algorithms!
What makes Rye different?
When I started Rye, I asked myself what parts of functional programming were so ubiquitous that it would make sense to weave them into the language itself.
Most functional languages focus on the more arcane aspects of FP. ML-family languages, like Haskell or F#, incorporate currying and partially-applied functions, for instance.
I think it's better to start small. Rye has a few features that are accessible even to FP novices:
- Syntactic sugar for short functions
square := _ * _ abs := _ if _ > 0 else -_
- Immutability by default
x := 42 x = "something else" // Error!
map
andfilter
as keywordsnumbers := 1..5 // [1,2,3,4] evens := numbers where _ % 2 == 0 // [2, 4] doubled := numbers map _ * 2 // [2,4,6,8]
then
keyword (pipe operator)vowels := {"a", "e", "i", "o", "u"} s := "functional programming" then split(_, "") where !(_ in vowels) then join(_, "") // "fnctnl prgrmmng"
How it's made
The project began as a way to better understand parsing and interpreters. I was especially interested in parser combinators, a functional approach to parsing, and so rather than use a library like parsec I built my own.
Rye's implementation language is Go, since it has the right balance of low-level control (like pointers and binary executables) and high-level utilities (like garbage collection), as well as a strong type system.
After a front-end of parser combinators, the back-end of the interpreter uses the tree-walk method. Tree-walk interpreters are among the simplest to implement, and are rarely used for production-grade languages, though there have been exceptions.
Try it for yourself
You can view the full documentation and source code, as well as instructions for building the interpreter, on GitHub.
Keep in mind that Rye is a hobby project, not a production-ready interpreter. Someday I may swap the tree-walk back-end for a bytecode one, or maybe even LLVM, but for now it's only for fun.