• 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. map/apply a list to a function with multiple arguments

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 143
  • Views 5357
  • 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

map/apply a list to a function with multiple arguments

ZoltanT
ZoltanT over 5 years ago

Hello everybody,

I would like to obtain a list by substituting an argument of a multiple argument function with elements of a list.

Example:

procedure(foo(a b) a+b)
foo
mapcar('foo(1) 'list(1 2 3))
*Error* mapcar: not a function - (foo 1)

It works if the function has only one argument, but how should I proceed if the function has multiple arguments? Shall I define another procedure where I reduce the number of arguments to only one? Or just build the desired list in a foreach loop element-wise? I do not have a good feeling what would be the "skill-ed" way to accomplish this and I would like to hone my SKILL knowledge a bit.

Thanks!
Zoltan

  • Cancel
Parents
  • skillUser
    skillUser over 5 years ago

    Hi Zoltan,

    You can supply multiple lists for mapcar so that each successive pair is taken from the two lists, for example:

    mapcar('foo '(1 2 3) '(1 1 1))  ; but this could be tedious, so:
    mapcar('foo '(1 2 3 4 5) ciUtilsRepeatNTimes(1 5))
    => (2 3 4 5 6)

    If 'foo' had three arguments you would make three lists and so on.  Generally speaking though, when I encounter this I refactor the code using foreach, e.g.

    foreach(mapcar input list(1 2 3)
      foo(input 1) ; assuming '1' is a fixed argument in this context
    )
    => (2 3 4)

    This can make for better code readability too, and generally would be easier to understand for most folks.

    Hopefully this helps explain mapcar better?

    Best regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 5 years ago in reply to skillUser

    If you really want to just use mapcar directly, the pattern that Lawrence shows using foreach mapcar is equivalent to doing:

    mapcar(lambda((input) foo(input 1)) list(1 2 3))

    In essence, it creates an anonymous function which takes one argument (which calls your original function with two arguments) and passes that to mapcar. The foreach(mapcar ...) form is a macro that generates the mapcar above.

    Regards,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 5 years ago in reply to skillUser

    If you really want to just use mapcar directly, the pattern that Lawrence shows using foreach mapcar is equivalent to doing:

    mapcar(lambda((input) foo(input 1)) list(1 2 3))

    In essence, it creates an anonymous function which takes one argument (which calls your original function with two arguments) and passes that to mapcar. The foreach(mapcar ...) form is a macro that generates the mapcar above.

    Regards,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • ZoltanT
    ZoltanT over 5 years ago in reply to Andrew Beckett

    Thanks for both of you!

    • 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