How can I remove all the items of a list?

Discussion in 'Cadence' started by Tom_Ding, Nov 16, 2004.

  1. Tom_Ding

    Tom_Ding Guest

    Hello all,
    By using the SKILL function remd, I can remove some items of a
    list. But how can I remove all the items of a list? In other words, how
    can I make a list be empty?
    Thanks.
     
    Tom_Ding, Nov 16, 2004
    #1
  2. Tom_Ding

    Jim Newton Guest

    Do you want to destructively make a list empty? Or just set a
    variable to an empty list?
    You could do something like the following:

    (while (car some-list)
    (remd (car some-list) some-list))

    But if you just want to replace some-list with an empty list
    you can use (some-list = nil)

    What do you want to happen to other references to parts of
    the list? for example

    x = (list 1 2 3 4 5)
    y = (cdr x)
    z = (cons 0 x)

    Note that y points to the list ( 2 3 4 5), but the same one
    that (cdr x) points to. So if you do not care that y still
    points to ( 2 3 4 5) you can do something more efficient
    to x. This y unchanged, but sets z to the list ( 0)

    (rplacd x nil)
    (remd (car x) x)

    -jim
     
    Jim Newton, Nov 16, 2004
    #2
  3. Tom_Ding

    Tom_Ding Guest

    Oh! I see.
    Thanks a lot!
     
    Tom_Ding, Nov 16, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.