Currently, Rice is under heavy development and brainstorm stage. Not usable yet.
The objective is to maintain total interoperability between Rice and Erlang, and do not miss the functional paradigm.
- Variables are immutable (single-assignment)
- No imperative loops (for, while, etc)
- No global scope
Three words in my mind
- Powerful
- Elegant
- Clean
“Hello world” and ‘Hello world’ are same.
>>> "Hello world" === 'Hello world' true >>> "foo".str? true
>>> 1.int? true >>> 1.float? false
>>> 1.0.float? true >>> (2 * 0.5).int? false
Erlang atoms, like Ruby symbols.
:keyword or :‘this is an atom’ are valid atoms.
>>> :keyword.atom? true >>> :'this is an atom'.atom? true >>> 1.atom? false
>>> L = [1, 2, 3] [1, 2, 3] >>> L[1] 2
Like Python, slice notation is also supported:
>>> L = [2, 4, 6, 8] [2, 4, 6, 8] >>> L[0:2] [2, 4] >>> L[:3] [2, 4, 6] >>> L[-1:] [8]
true, false and undefined are considered special atoms.
>>> true == :true true >>> false == :false true >>> undefined == :undefined true
Just a syntatic sugar here.
>>> true and true true >>> true or false true >>> not true false >>> not (not true) true >>> 1 == 1.0 true >>> 1 === 1.0 false
>>> 1 & 1 # and 1 >>> 0 | 0 # or 0 >>> 1 ^ 1 # xor 0 >>> ~2 # negation -3 >>> 6 >> 1 # shift right 4 >>> 6 << 4 # shift left 96
def fib (0) 0 def fib (1) 1 def fib (n) when n > 0 fib(n - 1) + fib(n - 2) end
>>> 1.to_s "1" >>> 1.puts 1 >>> "hello world".puts "hello world" >>> [1, 2, 3, 4].filter(fun x: x.even?) [2, 4] >>> [1, 2, 3, 4].filter(fun x: x.even? and x < 4) [2] >>> foo = undefined >>> foo.to_s "undefined"
>>> my_function = fun x x + 1 end >>> my_function(2) 3
>>> test = fun 1 true fun 0 false end >>> test(1) true >>> test(0) false
x = 1 #x = "foobar" #x = 1.0 if x.int? puts "integer" elif x.str? puts "string" else puts "anything else" end
def debug fn fun x, y puts "called function %s" % fn.name fn.call x, y end end @debug def sum x, y x + y end
Example of permutation using two generators
>>> [x + y for x in "ab", y in "ab"] ["aa", "ab", "ba", "bb"]
>>> double = 2 * ? >>> double(2) 3 >>> cube = ?1 * ?1 * ?1 >>> cube(3) 27 >>> [10, 20, 30].map(2 * ?) [20, 40, 60]
All functions with name terminating in “?” are evaluated to true or false
>>> def foo? "bar" end >>> foo? true >>> def bar? 0 end >>> bar? false