• 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. Is there a way i can cretea a function on the fly?

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 142
  • Views 13265
  • 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

Is there a way i can cretea a function on the fly?

kb how
kb how over 12 years ago

Hi,

May i know is there are way to create function at the fly. Meanings that create a control loop flow script to create unique function name.

Example as below (But this doesn't works)

foreach( ele list( list("funcA" funcB") list("funC" "funcD"))

    newFunctionName = stringToSymbol(strcat( car(ele) cadr(ele) ))

    (defun newFunctionName args

          (printf "Hello World - %L\n" args))

)

 

My intention is to create a function at the fly.Any idea? Is this possible? 

 

 

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 12 years ago

    foreach( ele list( list("funcA" "funcB") list("funC" "funcD"))
        newFunctionName = stringToSymbol(strcat( car(ele) cadr(ele) ))
        putd(newFunctionName lambda((args)
              printf("Hello World - %L\n" args)
              )
        )
    )

    funcAfuncB("test")

    Hello World - "test"

    However, I would say that creating functions on the fly is something that is even more powerful in SKILL++ mode, because that supports the concept of "closures". For example (either type toplevel('ils) and then type this in the CIW, or put in a file with a ".ils" suffix):

    defun(CCFmakeCounter (@key (init 0) (step 1))
      lambda(() init=init+step)
    )

    c1=CCFmakeCounter()
    c2=CCFmakeCounter(?init 4 ?step 3)

    c1() => 1
    c1() => 2
    c2() => 7
    c2() => 10
    c1() => 3

    This concept is covered in more detail in the SKILL documentation. The idea is that CCFmakeCounter() is returning a function object with the specific environment containing the arguments that were passed in (it's the same function object, but the environment changes in essence). In SKILL++ mode functions are variables, so you can much more easily pass around function objects without needing to use funcall or apply to call them.

    Regards,

    Andrew.

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 12 years ago

    foreach( ele list( list("funcA" "funcB") list("funC" "funcD"))
        newFunctionName = stringToSymbol(strcat( car(ele) cadr(ele) ))
        putd(newFunctionName lambda((args)
              printf("Hello World - %L\n" args)
              )
        )
    )

    funcAfuncB("test")

    Hello World - "test"

    However, I would say that creating functions on the fly is something that is even more powerful in SKILL++ mode, because that supports the concept of "closures". For example (either type toplevel('ils) and then type this in the CIW, or put in a file with a ".ils" suffix):

    defun(CCFmakeCounter (@key (init 0) (step 1))
      lambda(() init=init+step)
    )

    c1=CCFmakeCounter()
    c2=CCFmakeCounter(?init 4 ?step 3)

    c1() => 1
    c1() => 2
    c2() => 7
    c2() => 10
    c1() => 3

    This concept is covered in more detail in the SKILL documentation. The idea is that CCFmakeCounter() is returning a function object with the specific environment containing the arguments that were passed in (it's the same function object, but the environment changes in essence). In SKILL++ mode functions are variables, so you can much more easily pass around function objects without needing to use funcall or apply to call them.

    Regards,

    Andrew.

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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