logoalt Hacker News

shaknayesterday at 9:05 PM1 replyview on HN

Pairs are used by about 3-quarters of the standard library of Scheme, so I really would not consider its use to be a code smell.

You should be using the pairs when using make-hash, for example.

Cons also doesn't always return a pair. Its main purpose is for prepending to a list. Only when "the second argument is not empty and not itself produced by cons" does it produce a pair.

Which means '(a . b) is clearer code in intent, than (cons a b).


Replies

tkrntoday at 12:45 AM

Good points. I don't think pairs are a code smell when used reasonably in situations where a pair of two values makes sense, like in your make-hash example. Ideally though I'd like to have a real, distinct (immutable) pair/association type separate from the cons/list and maybe use the dot syntax for that instead.

Deeply nested pair & list constructs that need to be unpacked with complex car/cdr combinations is what IMHO gets messy and I take the appearance of cddar & co in code as a sign that I should start thinking about using proper data structures.