Arc Forumnew | comments | leaders | submitlogin
Bug in pushing with nested lists?
2 points by Darmani 6154 days ago | 3 comments
While attempting to write a function that splits sequences according to a condition, I encountered what I am pretty sure is a bug. I spent a few minutes searching for the root version, but nothing jumped out at me, and I was being forced to retire for the night. Anyway, here's a minimal version

  (def breaker nil
   (let seq '(())
     prn.seq
     (push 1 car.seq)))


 arc>(breaker)
 (nil)
 (1)
That's as expected. Future calls are not so nice.

arc>(breaker) ((1)) (1 1)

arc>(breaker) ((1 1)) (1 1 1)

arc>(breaker) ((1 1 1)) (1 1 1 1)



5 points by almkglor 6154 days ago | link

' introduces a constant. This means that for each call of breaker, it's referring to the same list. If you want to recreate a list each time, use list, not '.

Really, you should avoid using ' on lists unless you know exactly what ' does. ' on symbols is OK, but not ' on lists, because it does strange stuff.

-----

1 point by raymyers 6152 days ago | link

Right. Of course, backtick'd lists with at least one comma are still born anew each time; i.e. `((,a)) is safe.

-----

4 points by pg 6154 days ago | link

That looks correct to me.

-----