5 ms·
There are all kinds of useful structures that you can make out of conses: trees (with two cells per node), infinite lists, and so on. They're also useful in con
by qwertyuiop924 10y ago
There are all kinds of useful structures that you can make out of conses: trees (with two cells per node), infinite lists, and so on. They're also useful in conveying intent.
- phyrex 10y agoI don't see why you can't make those out of the data structures provided - or even the Clojure conses?
- qwertyuiop924 10y agoWell, it's nice to have a uniform cell structure, and you can't make them out Clojure conses, because Clojure conses don't really have a cdr, not as such, as Clojure's cdr cannot contain arbitrary data.
- phyrex 10y agoCan't it? This seems to work just fine: (cons :a (cons '[x] (cons {:foo :bar} #{:x :y}))) and cljs.user=> (rest (cons :a (cons '[x] (cons {:foo :bar} #{:x :y})))) ;=> ([x] {:foo :bar} :x :y) Maybe I don't understand what you mean. I also don't see why a uniform cell structure would be preferable?
- qwertyuiop924 10y agoThe result you got isn't actually what you'd get with proper cons cells. With real conses, you wouldn't get a list, you'd get an improper list, or a pair: i.e: Scheme: (define x (cons 'a (cons 'b '()))) ;> (a b) (define y (cons 'a 'b)) ;> (a . b) (cdr x) ;> (b) (cdr y) ;> b (eq x y) ;> #f If clojure doesn't behave like that, that it's not using real conses. As for why a uniform cell structure is preferable, it's a preference thing, but I feel it makes dealing with lists and other cons-based structure (mostly lists, but you get the occaisional alist or plist or tree in there too) much nicer.