what is the difference between defun and procedure?

Discussion in 'Cadence' started by Reotaro Hashemoto, May 8, 2008.

  1. Hi,
    What is the difference between creating a skill function using defun
    and procedure statements?
    Thanks and regards,
    Ahmad
     
    Reotaro Hashemoto, May 8, 2008
    #1
  2. Reotaro Hashemoto

    Riad KACED Guest

    Hi Ahmad,

    That's a very hard question and this is my attempt

    1. To start, there is a bit of comment from the SKILL Language User
    Guide.
    In SKILL, function calls can be written in either of the following
    notations:
    - Algebraic notation used by most programming languages: func( arg1
    arg2 …)
    - Prefix notation used by the Lisp programming language: (func arg1
    arg2 …)

    For comparison, here is a SKILL program written first in algebraic
    notation, then the same
    program, also implemented in SKILL, using a Lisp style of programming.

    procedure( fibonacci(n)
    if( (n == 1 || n == 2) then
    1
    else fibonacci(n-1) + fibonacci(n-2)
    )
    )

    Here is the same program implemented in SKILL using a Lisp style of
    programming.
    (defun fibonacci (n)
    (cond
    ((or (equal n 1) (equal n 2)) 1)
    (t (plus (fibonacci (difference n 1))
    (fibonacci (difference n 2)))
    )
    )
    )

    2. My point of view is both defun and procedure are doing the same job
    with a slightly different syntax. The only difference is :
    With defun, you have to keep a white space between the function name
    and the "(" of arguments, i.e fibonacci (n).
    3. defun is a lisp function actually whereas procedure is a pure skill
    function
    4. I'm enable to tell you whether there is any difference in terms of
    performance. I don't think so otherwise Cadence would have advised one
    syntax preferably to the other.
    5. My thinking is that defun suits the Lisp-ish chaps and procedure
    the C-ish ones. So the choice is yours !

    Let's wait for other comments ...

    Riad.
     
    Riad KACED, May 9, 2008
    #2
  3. Riad KACED wrote, on 05/09/08 00:51:
    It boils down to being a slightly different syntax. They both produce function
    objects. The key difference is that the first argument to procedure is a list
    containing both the function name and the formal arguments. Whereas with defun,
    the first argument is the function name, and the second argument is the formal
    argument list.

    As Riad said, defun is primarily there because
    (defun funName (arg1 arg2) body...) is the LISP way of doing things.

    Andrew.
     
    Andrew Beckett, May 9, 2008
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.