• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. About function define

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 125
  • Views 15030
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

About function define

bobbygang
bobbygang over 14 years ago

Hi, I wrote function define code like this :

procedure(MMM(A B C D E)
                   setplist(A '(B D C E))
                   F=getqq(A B)
                   F
)

I want to achieve that when I input :    MMM(bobby xx (1 2 ) yy (3 4))

it will give me the result :        (1 2)

But it always tell me          *Error* eval : unbound variable  -bobby

Does it mean that when I use the function MMM I should define symbol "bobby" "xx" "yy" first?

I think it's too cumbersome. How to solve this problem ?

  • Cancel
  • skillUser
    skillUser over 14 years ago

     Hi Bobby,

    I can't quite figure out what you are trying to do. In this case you appear to be calling the procedure incorrectly, you would need to do something like this instead: 

    MMM('bobby 'xx '(1 2) 'yy '(3 4))  (you could call "list(1 2)" instead of '(1 2) also).

    But even then the code probably wouldn't work.  If you call MMM with just "bobby" the SKILL interpreter will look for a variable (or function) that matches the symbol bobby and it is not finding one.  If you make the procedure an nprocedure then it might start to work the way you might want it to,  something like

    nprocedure(MMM(args)
      let( (h)
        when(h=car(args)
          setplist(h cdr(args))
          F=getqq(h cadr(args))
        ); when
      ); let
    ); nprocedure
    
    MMM(bobby xx (1 2) yy (3 4))
    => (1 2)
    bobby.xx
    => (1 2)
    bobby.yy
    => (3 4)
    F
    => (1 2)

    Is this what you are looking for?

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 14 years ago

    nprocedures are not the right way to do this really because usually they rely on runtime evaluation - in this case they don't, but nprocedures don't generally work properly in SKILL++ code (in this case it does work, but you still get a warning). BTW, there's a typo in Lawrence's code anyway - the getqq should be a get (no "q" at all) otherwise it doesn't work.

    Assuming you didn't really want a global variable F in the code, I  would do this as a macro (which is the right way to do this):

     defmacro(MMM (A B C D E)
      `{
        setplist(',A '(,B ,C ,D ,E))
        getqq(,A ,B)
        }
    )

    (be careful about the quotes here - the one  before the open curly bracket is a backquote; this allows selective evaluation within the macro). Macros are evaluated at "compile" time - so they will be expanded in place.

    If you really want the variable F to be assigned, just put F= before the getqq in the macro.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • skillUser
    skillUser over 14 years ago

    Oops, good catch, thank you - I tested it with "get" but I didn't copy & paste the code hence the creeping in of mistakes.

    I like the macro approach, it makes more sense even if the code looks strange.

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • bobbygang
    bobbygang over 14 years ago

    It works! Thank you very much.

    Moreover some of your discussion is diffculty to me. It seems I need more time to become familiar with function define command.  What is the difference between defmarco and procedure?

    Regards,

    Bobbygang.

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 14 years ago

    Hi Bobbygang,

    A function defined  with procedure() will be a standard "lambda" function, for which all the arguments are evaluated before the function is called. Most functions are of this type in SKILL.

    A function defined with nprocedure() is an "nlambda" function. These do not have any of their arguments evaluated before the function is called - and as such receive all the arguments raw in a list. The function itself is then responsible for evaluating those it wishes to evaluate. The downside of such functions is that they tend to rely on run-time evaluation, which means less advantage can be taken of byte-code compilation, and so can be less efficient.

    A macro defined with defmacro() is run at compile time - essentially the body of the defmacro is not supposed to actually do the action, but instead to produce the code needed to do the job. Since it sees the arguments raw, it can build SKILL code which has the same kind of semantics as a built-in function would - no need to quote things. The result of the defmacro is SKILL code, which can then in turn be byte-code compiled and so sees the same speed benefits that normal code does and it doesn't do any run time evaluation. See Understanding SKILL macros on Cadence Online Support.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • bobbygang
    bobbygang over 14 years ago

    Hi Andrew,

    I think I understand what you mean. I will see the reference for detailed imformation. Thank you !

    Regards,

    Bobbygang

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information