• 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 SKILL
  3. custom let with local variables from list (defmacro)

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 143
  • Views 13289
  • 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

custom let with local variables from list (defmacro)

Adrian Nistor
Adrian Nistor over 10 years ago

Hi,

I'm playing around with defmacro (as a defmacro beginner) and I can not succeed :(

I have a list of strings:

myVarList = list( "a" "b" "c" )   ;;any number of parameters, not necessary 3 !

[ or: myVarSymbolList = list( 'a 'b 'c)   ]

I want to define a custom let where my string would be local variable, and I would like to use it like this

myCustomLet( myVarList
  ;; here starts my normal code having a, b and c as local variables
  a = 1    b = 2    c = 3
)

I don't know how to do it properly :(

I tried like this:

(defmacro customLetWithLocalVars (listOfVars @rest code )
    `(let  ,listOfVars ,@code )
)

But it is working only like this:
customLetWithLocalVars(    (a b c)  a=1 b=2 c=3)

and NOT LIKE THIS:

customLetWithLocalVars(   myVarSymbolList   a=1 b=2 c=3 )

:(

Do you have any hints?

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 10 years ago

    Adrian,

    You can't do this with a macro. The value of myVarSymbolList would only be known at run time, not at the time the macro is expanded. You'd have to do something like this:

    (defun customLetWithLocalVarsInt (listOfVars code)
      (eval `(let ,(mapcar 'concat listOfVars) ,@code)))

    (defmacro customLetWithLocalVars (listOfVars @rest code)
      `(customLetWithLocalVarsInt ,listOfVars ',code))

    Uses run-time evaluation (eval), which isn't brilliant - but I don't see how else you could do it. Seems a slightly unusual thing to want to do to me.

    The above example will work with lists of strings or lists of symbols. The macro is just so that you don't have to quote the code.

    Regards,

    Andrew.

    • 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