How to insert a vaule in List

Discussion in 'Cadence' started by kumar_eee, Nov 26, 2007.

  1. kumar_eee

    kumar_eee Guest

    Can anybody tell me How to insert a value in a list..

    Eg:

    old_list=((0.39 1.2) (1.985 1.2) (1.985 1.4) (4.12 1.4) (4.12
    1.11))

    new_list=((0.39 1.2) (1.985 1.2) (0.4 1.4) (4.12 1.4) (4.12 1.11))

    I have changed the xcoord value of 3rd (1.985 1.4) list.

    How can I build a new list?.
     
    kumar_eee, Nov 26, 2007
    #1
  2. kumar_eee

    S. Badel Guest

    Can anybody tell me How to insert a value in a list..
    ((0.39 1.2)
    (1.985 1.2)
    (1.985 1.4)
    (4.12 1.4)
    (4.12 1.11)
    )
    (0.4 1.4)
    ((0.39 1.2)
    (1.985 1.2)
    (0.4 1.4)
    (4.12 1.4)
    (4.12 1.11)
    )


    simlarly, to change the y coordinate :
    ((0.39 1.2)
    (1.985 1.2)
    (0.4 0.4)
    (4.12 1.4)
    (4.12 1.11)
    )

    or to replace the whole points
    ((0.39 1.2)
    (1.985 1.2)
    (1.985 1.4)
    (4.12 1.4)
    (4.12 1.11)
    )



    Cheers,

    Stéphane
     
    S. Badel, Nov 26, 2007
    #2
  3. kumar_eee

    Edward Guest

    There's a couple of ways you can go about this, each with it's own
    caveats.

    The easiest way is to use the subst command.

    1)

    new_list = subst( '(1.985 1.4) '(0.4 1.4) old_list)

    NOTE: subst is non-destructive, so it creates a new list and assigns
    it to "new_list."
    CAVEAT: the subst command will substitute ALL occurences of '(1.985
    1.4) with '(0.4 1.4).

    The second method (which I would most likely use) includes using
    "copy" in conjunction with "rplaca."

    2)

    new_list = copy(old_list)
    rplaca( member( '(1.985 1.4) new_list ) '(0.4 1.4))

    NOTE: "copy returns a copy of a list. ... You should consider making
    a copy of any list before using a destructive modification on the
    list." -- SKILL Language User Guide
    CAVEAT: "copy only duplicates the top-level list cells. All lower-
    level objects are still shared." -- SUG

    Both method 1) and 2) treat the duplicate elements within a list a
    little differently. The first merely replaces all duplicate elements
    in a list with the replacement element. This is probably not what you
    want. The second replaces the FIRST matching element in a list with
    the replacement element. This may not be what you want either. And
    the reason for this is that the elements in a list are not guaranteed
    to be unique.

    GENERAL CAVEAT: When doing operations on a list (based on element
    values), try to have some idea how likely it is each element will be
    unique (not "equal") to any of the others and whether or not you're
    okay with that. It's possible that a list may not be the data
    structure you need for your project.

    Edward
     
    Edward, Nov 28, 2007
    #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.