• 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. Use one method definition for several types of classes

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 149
  • Views 11407
  • 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

Use one method definition for several types of classes

LDIL
LDIL over 4 years ago

Hello all.

The original problem is as follows. I have a method  which should accept both float number and integer, as well as anihter which is bar:

I only know how to the following:

defmethod( foo ( ( num fixum ) ( gro bar ) )

foo( float( num ) gro )

)

defmethod( foo ( ( num flonum ) ( gro bar ) )

.. code

)

Is there a way to have one method definition for both fixnum and flonum?

Also, is there a way to generalize this for any type of classes?

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 4 years ago

    The way you would normally handle this would be to define the method for a common superclass of the classes involved. Of course, for user-defined classes, you are free to define the class hierarchy as you wish, with abstract classes in the hierarchy to achieve the grouping you wish.

    With the built-in types, there is already a common superclass of fixnum and flonum, which is called number: 

    subclassesOf(findClass('number))
    (class:fixnum class:flonum)

    So all you'd need to do is define:

    defmethod(foo ((num number) (gro bar))
       ; do something
    )

    There's no way to define a method to be specialised on more than one class (well, not without horrible use of custom specializers probably - I didn't think about it too hard). I wrote an article How to use custom specializers in SKILL++ methods to specialize on the objType of a database object from which the main conclusion I drew was that this should be used with extreme caution because it could be very hard to follow the flow of control if you deviate too far from the standard method dispatch.

    The right way is to specialize on a superclass, as I suggested above.

    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