Created a secretive inheritance method for the compiler. You
don't need to see this, move along...
This commit is contained in:
parent
d23c849cf9
commit
950ea513c7
11
bin/activate
11
bin/activate
|
@ -6,3 +6,14 @@
|
||||||
PROJECT_ROOT=`pwd`
|
PROJECT_ROOT=`pwd`
|
||||||
PATH="$PROJECT_ROOT/bin:$PROJECT_ROOT/node_modules/.bin:$PATH"
|
PATH="$PROJECT_ROOT/bin:$PROJECT_ROOT/node_modules/.bin:$PATH"
|
||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
|
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
|
||||||
|
_OLD_VIRTUAL_PS1="$PS1"
|
||||||
|
if [ "x" != x ] ; then
|
||||||
|
PS1="$PS1"
|
||||||
|
else
|
||||||
|
PS1="(`basename \"$PROJECT_ROOT\"`)$PS1"
|
||||||
|
fi
|
||||||
|
export PS1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
136
src/lists.coffee
136
src/lists.coffee
|
@ -34,73 +34,85 @@ ConsList = ->
|
||||||
writeable: false
|
writeable: false
|
||||||
list
|
list
|
||||||
|
|
||||||
nil = (-> new ConsList())()
|
_annotate = (ConsList) ->
|
||||||
|
nilp = (c) -> !!c.isList and c.length == 0
|
||||||
|
|
||||||
vectorp = (c) -> toString.call(c) == '[object Array]'
|
cons = (a = nil, b = nil) ->
|
||||||
cellp = (c) -> !!c.isList
|
return (new ConsList()) if (nilp a) and (nilp b)
|
||||||
pairp = (c) -> !!c.isList and (c.length == 2)
|
if (a) then (new ConsList(a, b)) else (new ConsList(b))
|
||||||
listp = (c) -> !!c.isList and (c.length == 2) and (cellp cdr c)
|
|
||||||
recordp = (c) -> Object.prototype.toString.call(c) == '[object Object]'
|
|
||||||
nilp = (c) -> !!c.isList and c.length == 0
|
|
||||||
|
|
||||||
cons = (a = nil, b = nil) ->
|
nil = (-> new ConsList())()
|
||||||
return (new ConsList()) if (nilp a) and (nilp b)
|
|
||||||
if (a) then (new ConsList(a, b)) else (new ConsList(b))
|
|
||||||
|
|
||||||
car = (c) -> c[0]
|
vectorp = (c) -> toString.call(c) == '[object Array]'
|
||||||
cdr = (c) -> c[1]
|
cellp = (c) -> !!c.isList
|
||||||
|
pairp = (c) -> !!c.isList and (c.length == 2)
|
||||||
|
listp = (c) -> !!c.isList and (c.length == 2) and (cellp cdr c)
|
||||||
|
recordp = (c) -> Object.prototype.toString.call(c) == '[object Object]'
|
||||||
|
|
||||||
vectorToList = (v, p) ->
|
car = (c) -> c[0]
|
||||||
p = if p? then p else 0
|
cdr = (c) -> c[1]
|
||||||
if p >= v.length then return nil
|
|
||||||
# Annoying, but since lists are represented as nested arrays, they
|
|
||||||
# have to be intercepted first. The use of duck-typing here is
|
|
||||||
# frustrating.
|
|
||||||
item = if pairp(v[p]) then v[p] else
|
|
||||||
if vectorp(v[p]) then vectorToList(v[p]) else v[p]
|
|
||||||
cons(item, vectorToList(v, p + 1))
|
|
||||||
|
|
||||||
list = (v...) ->
|
vectorToList = (v, p) ->
|
||||||
ln = v.length
|
p = if p? then p else 0
|
||||||
(nl = (a) ->
|
if p >= v.length then return nil
|
||||||
cons(v[a], if (a < ln) then (nl(a + 1)) else nil))(0)
|
# Annoying, but since lists are represented as nested arrays, they
|
||||||
|
# have to be intercepted first. The use of duck-typing here is
|
||||||
|
# frustrating.
|
||||||
|
item = if pairp(v[p]) then v[p] else
|
||||||
|
if vectorp(v[p]) then vectorToList(v[p]) else v[p]
|
||||||
|
cons(item, vectorToList(v, p + 1))
|
||||||
|
|
||||||
listToVector = (l, v = []) ->
|
list = (v...) ->
|
||||||
return v if nilp l
|
ln = v.length
|
||||||
v.push if pairp (car l) then listToVector(car l) else (car l)
|
(nl = (a) ->
|
||||||
listToVector (cdr l), v
|
cons(v[a], if (a < ln) then (nl(a + 1)) else nil))(0)
|
||||||
|
|
||||||
metacadr = (m) ->
|
listToVector = (l, v = []) ->
|
||||||
ops = {'a': car, 'd': cdr}
|
return v if nilp l
|
||||||
seq = vectorToList m.match(/c([ad]+)r/)[1].split('').reverse()
|
v.push if pairp (car l) then listToVector(car l) else (car l)
|
||||||
return (l) ->
|
listToVector (cdr l), v
|
||||||
inner = (l, s) ->
|
|
||||||
return l if (nilp l) or (nilp s)
|
|
||||||
inner ops[(car s)](l), (cdr s)
|
|
||||||
inner l, seq
|
|
||||||
|
|
||||||
module.exports =
|
metacadr = (m) ->
|
||||||
cons: cons
|
ops = {'a': car, 'd': cdr}
|
||||||
nil: nil
|
seq = vectorToList m.match(/c([ad]+)r/)[1].split('').reverse()
|
||||||
car: car
|
return (l) ->
|
||||||
cdr: cdr
|
inner = (l, s) ->
|
||||||
list: list
|
return l if (nilp l) or (nilp s)
|
||||||
nilp: nilp
|
inner ops[(car s)](l), (cdr s)
|
||||||
cellp: cellp
|
inner l, seq
|
||||||
pairp: pairp
|
|
||||||
listp: listp
|
{
|
||||||
vectorToList: vectorToList
|
cons: cons
|
||||||
listToVector: listToVector
|
nil: nil
|
||||||
setcar: (a, l) -> l[0] = a; a
|
car: car
|
||||||
setcdr: (a, l) -> l[1] = a; a
|
cdr: cdr
|
||||||
cadr: (l) -> car (cdr l)
|
list: list
|
||||||
cddr: (l) -> cdr (cdr l)
|
nilp: nilp
|
||||||
cdar: (l) -> cdr (car l)
|
cellp: cellp
|
||||||
caar: (l) -> car (car l)
|
pairp: pairp
|
||||||
caddr: (l) -> car (cdr (cdr l))
|
listp: listp
|
||||||
cdddr: (l) -> cdr (cdr (cdr l))
|
vectorToList: vectorToList
|
||||||
cadar: (l) -> car (cdr (car l))
|
listToVector: listToVector
|
||||||
cddar: (l) -> cdr (cdr (car l))
|
setcar: (a, l) -> l[0] = a; a
|
||||||
caadr: (l) -> car (car (cdr l))
|
setcdr: (a, l) -> l[1] = a; a
|
||||||
cdadr: (l) -> cdr (car (cdr l))
|
cadr: (l) -> car (cdr l)
|
||||||
metacadr: metacadr
|
cddr: (l) -> cdr (cdr l)
|
||||||
|
cdar: (l) -> cdr (car l)
|
||||||
|
caar: (l) -> car (car l)
|
||||||
|
caddr: (l) -> car (cdr (cdr l))
|
||||||
|
cdddr: (l) -> cdr (cdr (cdr l))
|
||||||
|
cadar: (l) -> car (cdr (car l))
|
||||||
|
cddar: (l) -> cdr (cdr (car l))
|
||||||
|
caadr: (l) -> car (car (cdr l))
|
||||||
|
cdadr: (l) -> cdr (car (cdr l))
|
||||||
|
metacadr: metacadr
|
||||||
|
}
|
||||||
|
|
||||||
|
_export = _annotate(ConsList)
|
||||||
|
Object.defineProperty _export, '_annotate',
|
||||||
|
value: _annotate
|
||||||
|
configurable: false,
|
||||||
|
enumerable: false,
|
||||||
|
writeable: false
|
||||||
|
|
||||||
|
module.exports = _export
|
||||||
|
|
Loading…
Reference in New Issue