Search code examples
schemecons

Are expressions such as (set! c (cons 3 c)) the way to add an item to a list?


Scheme has set-car! and set-cdr!, but no set-cons! .

Are expressions such as

(set! c (cons 3 c))

which places the element 3 on the list c, the proper/only/best/usual way to modify a list?


Solution

  • That is the correct way to modify the list c. But such usage is rare. Perhaps you could tell us more about what you are trying to do.