# what is the difference between defun and procedure?

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

1. ### Reotaro HashemotoGuest

Hi,
What is the difference between creating a skill function using defun
and procedure statements?
Thanks and regards,

Reotaro Hashemoto, May 8, 2008

2. 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
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 ...

3. ### Andrew BeckettGuest

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