What are the wrong lists for?

This is a continuation of my previous question: Why do we need nil? Obviously, the correct lists are used most of the time. But what is the purpose of the wrong list?

+3
source share
4 answers

Not without reason. The only thing that invalid lists are really good is as part of the syntax of association lists - and even there it would be better to have custom syntax for key-value pairs. Any use that you can think of for invalid lists can be better implemented using record types, which ultimately include lists: you can define Lisp lists in terms of records, but not vice versa (because lists do not allow you to define structures data whose type does not overlap with all other types of language).

The abuse of pairs and lists to represent all types of data is what I like to call Lisp a disease to a programmer, and this is a real shame that Lisp proponents advocate. I had too much time cleaning up this stuff.

+4
source

! , ...). , - .

: ", . , , " "? , , ".

, , "assoc", , , .

+6

cons, car cdr. lisp, . - .

+4

" " , , cons.

, , cons , ML.

- . , :

;; A Stream-of-X is one of
;;   - null, ie '()
;;   - (cons X Stream-of-X)
;;   - a procedure taking no arguments and returning a Stream-of-X result

;; nats-from : nat -> Stream-of-nat
(define (nats-from n)
  (cons n (lambda () (nats-from (+ n 1)))))
+1

All Articles