Page 1 of 1

Newbie problem - defun

Posted: Mon Nov 10, 2014 4:36 pm
by j831526
Following is from my CCL REPL:

Code: Select all

? (defun my-half (x)
  (* (x 0.5)))

;Compiler warnings :
;   In MY-HALF: Undefined function X
;   In MY-HALF: Unused lexical variable X
MY-HALF
? (my-half 8)
> Error: Undefined function X called with arguments (0.5) .
> While executing: MY-HALF, in process Listener(4).
> Type cmd-/ to continue, cmd-. to abort, cmd-\ for a list of available restarts.
> If continued: Retry applying X to (0.5).
> Type :? for other options.
1 > q
? 
I'm obviously missing something REALLY basic, but I just don't see it:(

Thanx - Charlie

Re: Newbie problem - defun

Posted: Mon Nov 10, 2014 8:11 pm
by nuntius
In Lisp, the first token after an opening parenthesis, '(', is generally a function or macro.

In your example, you wrote "(* (x 0.5))". By default, there is no function named "x". You meant to write "(* x 0.5)".

Common issue when you're starting.

In Common Lisp, the variable "x" can have both a function value and a normal value.
In Scheme, the system would have complained that the value 8 was not a function.

Re: Newbie problem - defun

Posted: Tue Nov 11, 2014 11:07 am
by j831526
Nuntius,

That was it.

Thanx - Charlie