bim takes the idea from bc (linux command line basic calculator) and shift it in to a modern context. bim is designed to evolve into a modern scripting language.
$ make help #(show make options)
$ make #(make FLEX=osx #to build in macosx)
$ sudo make install
- flex
- bison
- readline (libreadline libreadline-dev)
- gcc
read the bim man page
#this is a comment
2 #number
0xfe # hex number
0b1010 #binary
2.2 #number
"foo" #interpolated string
'foo' #simple string
[1,2,3,4] #list
[0x23,"foo",12] #list
{'foo':2,'bar':3} #hash
{foo:2,bar:3} #hash
{'index1':"foo",'index2':'foo2'} #hash
{index1:"foo",index2:'foo2'} #hash
a="foo" #a = string 'foo'
!!a[1] # 'o'
a=2+2 # 4
a='foo' # 'foo'
!!a[0] # 'f'
a=0xfe #254
let a=[1,2,3,4,5,6] #a is a list
count(a) # 6 (number of elements)
!!a[3] # 4
!!a[-1] # 6
!!a[2:5] # [3,4,5,6]
!!a[:3] # [1,2,3,4]
!!a[3:] # [4,5,6]
let a={'foo':2,'bar':3} # a is a hash
let a={foo:2,bar:3} # a is a hash (keys without string quotes)
count(a) # 2 (number of elements)
!!a~['foo'] # 2
!!a.foo # 2
^a=4 # assign global var a (^ refers to global vars ... see functions section).
2+2 # 4
2+3.1 # 5.1
2-2 # 0
2--2 # 4 ... 2-(-2) :)
2---2 # 0 ... 2-(-(-2))
2+3*4 # 14
(2+3)*4 # 20
6/3 # 2
6/5 # 1.2
#t # true
#f # false
!#t # false (not true)
!#f # true (not false)
2<3 # #t
2==2 # #t
2==3 # #f
2>3 # #f
2<=3 # #t
2>=3 # #f
2!=3 # #t
2!=2 # #f
!(2<3) # #f
if(#t) #t else #f
if(2!=2) {prn "this is not executed\n"; prn "foo"} else {prn "multiple commands can be wrapped in block code curly brackets"}
a=1;
while(a<=10){
prn a,"\n";
a=a+1;
}
prn "list params...",1,2,3,"foo","\n";
print("list params...",1,2,3,"foo","\n");
\x.x+1 #lambda (anonymous function)
\x.x+1->(3) #lambda function with application. returns 4
\x.{x+1}->(3) #same
\x,y.{x+y}->(2,3) #5
\x.{y=3;x+y;prn "done\n";}->(2)
f=\x.x+1 #assign function to f
f->(3) # 4 (function application)
f(3) # 4 (shortcut for func apply)
f:\x.x+1 # you ca assign a function either with '=' or ':'
f->(3) # 4 (func application)
f(3) # 4 (shortcut for func apply)
f:\_.prn "the _ ignore the parameter"
# if you want to ignore a var you ca use the '_' unsderscore sign as a var name
f() # func application with no params
y=5;\x.{x+^y}->(2) #7 (^ refers to global var)
y=5;\x.{y=1;x+y+^y}->(2) #8
f:\x.{if(x==1) 1 else x*f(x-1)} #fibonacci func
f(5) # 120
let f=~\x,y.x+y # define f as a clojure function
let g=f(2) # g is a function partial application of f
g(3) # output 5
!!f,2,3 # apply 2 and 3 to f
!!2..f,3 # chain 2 with f(3) ... result 5
!! is a post operator executor symbol. post operators are: .. [] . ,
lisp syntax is embedded between (% and %)
f=\x,y.x+y
(% (f 2 3) %)
(% (__assign__ g (__lambda__ (x y)(__add_ x y))) %)
g(3,4)
in the repl you can change the var of __debug__ var to #t to debug and inspect internal sturctures.
the last evaluated expression is stored in the special variable $! and you can use it in any way as a normal var in an expression.
- lambda recursion
- var namespaces
- IO socket
- IO files/disk
- JSON encode/decode
- DB SQL interact
- foreach - list and hash loop
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.