[plt-scheme] How to insert an element in empty list?

From: Chris Laux (chris at terraminds.com)
Date: Sun Aug 12 16:21:54 EDT 2007

Majorinc, Kazimir wrote:
> If list is not empty, it is easy (although not really trivial). But how
> to do that with empty list, both set-first! and set-rest! complain they
> do not work with empty lists.

You could do (cons 'x ()) and would get (x). But I wouldn't call that
inserting per se. A list is just a chain of cons cells, so maybe you
have the wrong paradigm?

--
Chris Laux




Posted on the users mailing list.