Newbie problem - defun

Discussion of Common Lisp
Post Reply
j831526
Posts: 11
Joined: Mon Nov 10, 2014 4:24 pm

Newbie problem - defun

Post by j831526 » Mon Nov 10, 2014 4:36 pm

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

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Newbie problem - defun

Post by nuntius » Mon Nov 10, 2014 8:11 pm

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.

j831526
Posts: 11
Joined: Mon Nov 10, 2014 4:24 pm

Re: Newbie problem - defun

Post by j831526 » Tue Nov 11, 2014 11:07 am

Nuntius,

That was it.

Thanx - Charlie

Post Reply