setq vs. = vs. arrays

Discussion in 'Cadence' started by danmc, Aug 28, 2006.

  1. danmc

    danmc Guest

    (declare x[5])
    (setq x[3] 7.2)

    fails with *Error* setq: argument #1 should be a symbol (type template
    = "sg") - x[3]

    declare( x[5] )
    x[3] = 7.2

    works.

    The manual says

    "Sets a variable to a new value. setq is the same as the assignment (=)
    operator. This is a syntax form."

    So I'm puzzled. If I have a somewhat large program that is written
    using skill style (foo x) instead of procedural style foo(x), how can I
    assign an element in an array?

    Thanks
    -Dan
     
    danmc, Aug 28, 2006
    #1
  2. danmc

    Jimka Guest

    Hi Dan, this is a trick of the SKILL parser. x[3]=7.2 does not
    parse as setq something while x=7.2 does.

    To find out how the parser reads infix notation into an sexpression,
    do the following.

    (sstatus printinfix nil)
    '(x[3] = 7.2)


    this will output the expression in prefix notation. You'll see
    that it is not a call to setq at all but rather a call to setarray.

    setq is only able to set the value of a symbol, not of an array
    element.

    If you simply want to assign to an array element, you can also simply
    use x[3] = 7.2
    this works as well inside a program that it written with prefix
    notation.
    SKILL does not care if your program is written with infix or prefix or
    a mixture of the two.


    after (sstatus printinfix nil) you can even pp a function to see the
    entire
    function in infix notation. or you can (sstatus printinfix t) and pp
    the function
    to see it with infix notation.

    hope this helps.

    -jim
     
    Jimka, Aug 28, 2006
    #2
  3. danmc

    danmc Guest

    yes. Big help!

    Thank you.

    -Dan
     
    danmc, Aug 29, 2006
    #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.