pixie-lang / pixie

A small, fast, native lisp with "magical" powers
GNU General Public License v3.0
2.35k stars 124 forks source link

concat always returns a vector #474

Open jmglov opened 8 years ago

jmglov commented 8 years ago

Pixie's concat always returns a vector, whereas in Clojure, it returns a lazy seq:

Pixie:

(concat (take 2 (range 1)) (take 1 (repeat nil)))
;;=> [0 nil]

Clojure:

(concat (take 2 (range 1)) (take 1 (repeat nil)))
;;=> (0 nil)
(realized? (concat (take 2 (range 1)) (take 1 (repeat nil))))
;;=> false

I think the Clojure behaviour is more desirable here.

jmglov commented 8 years ago

@thomasmulvaney @mpenet What do you guys think about this one?

thomasmulvaney commented 8 years ago

I agree. One would expect concat to behave lazily.

mpenet commented 8 years ago

+1 for lazy concat, just for clojure compatibility's sake.

jmglov commented 8 years ago

This might be a good one for me to take a swing at into order to get familiar with Pixie's sequences implementation. I'll see what I can do. :)

brian-dawn commented 8 years ago

@jmglov Were you still planning on fixing this? If not I would be happy to work on it.

Also I noticed something interesting with regards to performance, anyone have any idea why this is?

user => (time (take 2 (concat [3] (range))))
"Elapsed time: 24.371005 ms"
(3 0)
user => (time (take 2 (lazy-seq (concat [3] (range)))))
"Elapsed time: 0.004442 ms"
(3 0)

I guess I would expect these to be fairly similar from a performance perspective.

jmglov commented 8 years ago

@brian-dawn I've gotten really busy at work with non-Pixie stuff, so please feel free to run with it.

As for your performance question, I'm really not sure.