Skip to content
题叶 edited this page Jan 2, 2014 · 7 revisions

#####general builtins(general.coffee/.js)

print_ = (args...) -> console.log(arguments)   
eq = (x, y) -> x === y   
ne = (x, y) -> x !== y   
lt = (x, y) -> x < y   
le = (x, y) -> x <= y   
gt = (x, y) -> x > y   
ge = (x, y) -> x >= y   
add = (x, y) -> x + y   
sub = (x, y) -> x - y   
mul = (x, y) -> x * y   
div = (x, y) -> x / y   
mod = (x, y) -> x % y   
and_ = (x, y) -> x && y   
or_ = (x, y) -> x || y   
not_ = (x, y) -> !x   
lshift = (x, y) -> x << y   
rshift = (x, y) -> x >> y   
bitand = (x, y) -> x & y   
bitor = (x, y) -> x | y   
bitnot = (x, y) -> ~x   
inc = (x) -> x++   
inc2 = (vari) -> vari.binding += 2   
dec = (vari) -> vari.binding --   
dec2 = (vari) -> vari.binding -= 2    
# Because inc, inc2, dec, dec2 do not use vari.bind, they are not saved in solver.trail 
# and so it can NOT be restored in solver.failcont.
# EXCEPT the vari has been in solver.trail in the logic branch before vari.binding ++    
getvalue = (x) -> solver.trail.getvalue(x)      
length = (x) -> x.length    
neg = (x) -> -x   
abs = (x) -> Math.abs(x)   
index = (x, y) -> x[y]   
first = (x), **head**(x) -> x[0]   
tail = (x) -> x[1...]    
second = (x) -> x[1]    
third = (x) -> x[2]   
concat = (x, y) -> x.concat(y)   
list = (args...) -> return an array   
push = (x, y) -> x.push(y)   
pushp = (x, y) -> x.push(y), when backtracking here, x.pop()   
free = (x) -> x # is a free variable? different from logic.freep, this never fail   

Clone this wiki locally