• 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. Scheme vs Common Lisp style in SKILL++

Stats

  • Locked Locked
  • Replies 18
  • Subscribers 144
  • Views 22564
  • 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

Scheme vs Common Lisp style in SKILL++

tweeks
tweeks over 11 years ago

 While you can write your SKILL++ code like it is C, Maclisp, Scheme, or Common Lisp (or none of the above...), I've been experimenting with Common Lisp style lately.

Trying to write Common Lisp style code in SKILL++ can lead to curious situations like this:

(defvar first car)

The intention is to define FIRST as another name for CAR, as in Common Lisp.  In Scheme, we would write

(define first car)

which seems pretty natural, but using DEFVAR to define a function just feels.... wrong... somehow... :)

I guess I should use ALIAS:

 (alias second cadr)

 except ALIAS has weird limitations:

ILS-> (foo = first)
primop:car
ILS-> (foo '(1 2 3))
1
ILS-> (foo = second)
macro:evalalias
ILS-> (foo '(1 2 3))
*Error* evalalias: unknown alias - foo

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 10 years ago

    theopaone said:
    3. Without a break or continue for loops, go is somewhat but seldom useful. My first language was Fortran IV with goto's, on punch cards, almost prehistoric school.

     

    I personally dislike the concept of break/continue from loops (even in C) because it's a glorified goto which makes it hard to read the flow of control. But if one really must do this, I would probably do:

    prog(()
      loop(...
        when(IwantToBreak return())
      )
    )

    You could do something similar if you want to emulate continue, but have the prog() within the loop.

    Or you could use catch and throw:

    catch('break
      for(i 1 20
        catch('continue
          printf("Before %d\n" i)
          when(i<4 throw('continue t))
          printf("After %d\n" i)
          when(i>15 throw('break t))
        )
      )
    )

    Personally I'd prefer that to using go().

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • theopaone
    theopaone over 10 years ago

    Thank you for this good tutorial, Andrew and Tom.

    I prefer writing loops without the need for breaks, but when I need to short circuit the loop processing, I use prog().

    I had not thought of using throw/catch, I'll look into it.

    Ted

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • tweeks
    tweeks over 10 years ago
    Andrew Beckett said:

    I personally dislike the concept of break/continue from loops (even in C) because it's a glorified goto which makes it hard to read the flow of control. But if one really must do this, I would probably do:

    prog(()
      loop(...
        when(IwantToBreak return())
      )
    )

    You could do something similar if you want to emulate continue, but have the prog() within the loop.

    Or you could use catch and throw:

    catch('break
      for(i 1 20
        catch('continue
          printf("Before %d\n" i)
          when(i<4 throw('continue t))
          printf("After %d\n" i)
          when(i>15 throw('break t))
        )
      )
    )

    Personally I'd prefer that to using go().

    Thanks to Andrew's examples (both of which are significantly clearer than the ones in the SKILL Language Reference and the User Guide), I finally understand how to use throw and catch!

    The next question is, when to use them instead of error/errset....

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

    tweeks said:
    The next question is, when to use them instead of error/errset....

     

    errset traps all errors, whereas the catch/throw model is more selective. Of course, you can write code which catches the error using errset and then looks at errset.errset to determine what the error was and whether you care about it, and potentially use error to pass the error on, but that's clunky. The catch/throw paradigm is a more modern way of handling catching of specific errors.

    That said, I've not really embraced the catch/throw approach because I prefer the functional programming methodology of communicating via return values. Again, you can picture catch/throw as a glorified goto...

    Another clean approach to generic error handling is to use unwindProtect which allows you to ensure that some code always gets called regardless of how the stack unwinds - either by naturally unwinding the stack, or by an error being thrown.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • theopaone
    theopaone over 10 years ago

     You dangle a bone over the fence and when we go to the docs, the cupboard is bare.

    Can you supply us with an example of unwindProtect? Can you show the forms as blocks of code?

    Does the cleanup code get evaluated regardless of the error status of the protected form?

    What is the return value of the unwindProtect function if:
    A: If the protected form runs without error
    B: If the protected form has an error

    Sorry to ask but I'm not at a client with Virtuoso access.

    Ted

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

    Ted,

    This is the documentation (IC616 at least), although it maybe isn't the clearest. 

    It's unwindProtect(protectedForm cleanupForm). The cleanupForm is always executed regardless of whether there's an error, and the function returns the return value of protectedForm if it doesn't have an error, and doesn't return at all if it fails with an error.

    unwindProtect(23 println("Hello"))
    "Hello"
    23    <- return value

    unwindProtect(1/0 println("Hello"))
    *Error* quotient: Attempted to divide by zero
    "Hello"
    ; note no return value

    It behaves like unwind-protect in Common LISP.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • theopaone
    theopaone over 10 years ago

    My client may not have the latest version available. The documentation I can access is sparse.

    Thanks for the examples. We now have all three methodologies described in the same thread.

    Ted

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • tweeks
    tweeks over 10 years ago

    theopaone said:

    Thanks for the examples. We now have all three methodologies described in the same thread.

    Yes, thank you Andrew!

    It seems (from my Common Lisp books) that unwindProtect is the standard approach when writing "with" macros, like "withOpenFile".

    • 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