4 ms·
I agree that there is maybe too much potential for confusion with that, but is the dot operator (or read syntax?) actually used that much these days? Personall
by tkrn 8mo ago
I agree that there is maybe too much potential for confusion with that, but is the dot operator (or read syntax?) actually used that much these days?
Personally I have mostly sometimes used it with Emacs Lisp, but in general relying too much on plain cons cells and cadring down the cars of their cddars feels like a code smell to me and if I need a pair I can always just use cons? As the (only, I think?) infix operator in traditional lisps it has always felt extra-ordinarily useless to me (outside of Schemes use of it lambda lists), but maybe I'm just missing something.
- shakna 8mo agoPairs 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).
- tkrn 8mo agoGood 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.
- shakna 8mo agoA distinct and immutable pair is... A pair. (eq? (pair? '(A . B)) #t) (eq? (pair? (list 1 2 3)) #f) But agree you probably want list-ref instead of cddr and friends.
- wiml 8mo agoI think you need something like it in order to have a print representation of a cons cell whose cdr is not a cons-or-nil. And it's nice if your print representations are readable.