Fixed a cons falsity issue, and tests for nested vectors.

It should be possible to create non-nested vector collections; this
will be critical for defining the basic structures for the compiler.

cons(null, ()) should be legal; cons(undefined, ()) should not.  This
is now supported in the code.
This commit is contained in:
Elf M. Sternberg 2016-05-03 12:38:57 -07:00
parent 8bee006ddd
commit 99abd47e34
2 changed files with 11 additions and 1 deletions

View File

@ -35,7 +35,7 @@ _annotate = (ConsList) ->
cons = (a = nil, b = nil) ->
return (new ConsList()) if (nilp a) and (nilp b)
if (a?) then (new ConsList(a, b)) else (new ConsList(b))
if (a != undefined) then (new ConsList(a, b)) else (new ConsList(b))
nil = (-> new ConsList())()

View File

@ -57,6 +57,7 @@ describe 'List Building', ->
for [t, v] in [
[cons(), []]
[cons(nil), []]
[cons(0), [0]]
[cons('a'), ['a']]
[cons('a', cons('b')), ['a', 'b']]
[cons('a', cons('b', cons(nil))), ['a', 'b']]
@ -105,3 +106,12 @@ describe 'Metacadr Complex', ->
expect(mcadr mccomplex).to.equal(v)
expect(mcadr mccomplex).to.equal(v)
expect(mcadr mccomplex).to.equal(v)
mcnested = ['a', 'b', ['c', 'd'], 'e']
describe "Nested and not-nested VTOL:", ->
it "Should handle the nested case, as before", ->
t = vectorToList(mcnested)
expect(metacadr('cadaddr')(t)).to.equal('d')
it "Should handle a not-nested set", ->
t = vectorToList(mcnested, 0, false)
expect(metacadr('caddr')(t)[0]).to.equal("c")