P-Lang¶ ↑
P is a small (‘pequena’ in portuguese) functional programming language.
fib = [1| 1]; [2| 1]; [n| fib(n-1) + fib(n-2)] fib(10)
Features¶ ↑
Functions:
fib = [1| 1]; [2| 1]; [n| fib(n-1) + fib(n-2)] fib(10) # => 55 # or fib = [1|1] fib = [2|1] fib = [n|fib(n-1)+fib(n-2)] fib(10) # => 55
And more functions:
f = [x| x*pi] : (pi = 3.14) f(1) # => 3.14
Wildcards
f = [1, _, x| x*2] f(1,'aaaaa', 10) # => 20
Lists:
x = '(1,2,3,4) x->head() # => 1 x->tail() # => '(2,3,4)
Objects:
{rectangle: 10, 30}
Pattern:
{rectangle: x, y} = {rectangle: 10, 30} # => x = 10 # => y = 30
Messages:
{integer: x} -> plus2 = [x+2] 3->plus2() # => 5
IO:
x = read() # <= 123 print(x) # => 123
Requirements¶ ↑
-
Ruby 1.9
Install¶ ↑
$ sudo gem install p-lang
Running¶ ↑
$ p-lang your-program.p
Interactive P Shell¶ ↑
$ p-lang
Note on Patches/Pull Requests¶ ↑
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright¶ ↑
Copyright © 2010 Ígor Bonadio. See LICENSE for details.