take a random number from 0 to 100,
if it is 0 -> 49 = Head
50 = Costs
51 -> 100 = Cross:
(defun coin
(if (< (setq x (random 101)) 50) 'Head
(if (= x 50) 'Costs
'Cross)))
Why the interpreter says:
Error: (< SETQ X (RANDOM 101) ...) is not a symbol.
Signalled by COIN.
???
Thank you!!
In article <················@fire-int>,
Luky10 <······@iname.com> wrote:
> take a random number from 0 to 100,
> if it is 0 -> 49 = Head
> 50 = Costs
> 51 -> 100 = Cross:
>
> (defun coin
> (if (< (setq x (random 101)) 50) 'Head
> (if (= x 50) 'Costs
> 'Cross)))
>
> Why the interpreter says:
>
> Error: (< SETQ X (RANDOM 101) ...) is not a symbol.
> Signalled by COIN.
Obviously you missed the lambda-list after the function name. Another
thing is that you bind to global X: while not a error, it is considered
to be a bad style.
You may rewrite the function this way:
(defun coin ()
(let ((x (random 101)))
(cond ((= x 50) 'costs)
((< x 50) 'head)
(t 'cross))))
--
Eugene.
Sent via Deja.com http://www.deja.com/
Before you buy.
And BTW, the chances to stabilize on the verge for a symmetric coin is
much less than 1/101.
--
Eugene.
Sent via Deja.com http://www.deja.com/
Before you buy.
On Mon, 21 Feb 2000 18:21:23 GMT, Eugene Zaikonnikov <······@cit.org.by> wrote:
>And BTW, the chances to stabilize on the verge for a symmetric coin is
>much less than 1/101.
it depends on the thickness of the coin, I guess... :-)
Tord
Check out the definition of DEFUN.
Also, you better use LET for local variable binding, using special
variables (X) is as ugly as it gets.
[Re: Lisp teaching thread:
Using SETQ is usually a give-away that it is a homework problem here,
possibly gotten from outdated materials unaware of SETF.]
Robert
Luky10 wrote:
>
> take a random number from 0 to 100,
> if it is 0 -> 49 = Head
> 50 = Costs
> 51 -> 100 = Cross:
>
> (defun coin
> (if (< (setq x (random 101)) 50) 'Head
> (if (= x 50) 'Costs
> 'Cross)))
>
> Why the interpreter says:
>
> Error: (< SETQ X (RANDOM 101) ...) is not a symbol.
> Signalled by COIN.
>
> ???
> Thank you!!
Robert Monfera wrote:
> [Re: Lisp teaching thread:
> Using SETQ is usually a give-away that it is a homework problem here,
> possibly gotten from outdated materials unaware of SETF.]
While that is possible, I think there may be some people besides
myself who prefer using setq instead of setf where applicable
under the idea of "use the most specific construct" or something
like that.
M.Halminen
[······@iname.com]
| (defun coin
| (if (< (setq x (random 101)) 50) 'Head
| (if (= x 50) 'Costs
| 'Cross)))
|
| Why the interpreter says:
|
| Error: (< SETQ X (RANDOM 101) ...) is not a symbol.
| Signalled by COIN.
this is because you have skipped the argument list, so that what you
assume to be the body of the function is actually the argument list.
what you want is:
(defun coin ()
(if (< (setq x (random 101)) 50)
'Head
(if (= x 50)
'Costs
'Cross)))
also, you should create a local variable with LET instead of creating
a special one with SETQ, and a COND would be better than the nested IF:
(defun coin ()
(let ((number (random 101)))
(cond ((< number 50) 'head)
((= number 50) 'costs)
(t 'cross))))
--
best wishes,
Tor Henrik Hanken
thankyou tor, your answer was right!
Tor Henrik Hanken <········@ifi.uio.no> wrote:
> [······@iname.com]
> | (defun coin
> | (if (< (setq x (random 101)) 50) 'Head
> | (if (= x 50) 'Costs
> | 'Cross)))
> |
> | Why the interpreter says:
> |
> | Error: (< SETQ X (RANDOM 101) ...) is not a symbol.
> | Signalled by COIN.
> this is because you have skipped the argument list, so that what you
> assume to be the body of the function is actually the argument list.
> what you want is:
> (defun coin ()
> (if (< (setq x (random 101)) 50)
> 'Head
> (if (= x 50)
> 'Costs
> 'Cross)))
> also, you should create a local variable with LET instead of creating
> a special one with SETQ, and a COND would be better than the nested IF:
> (defun coin ()
> (let ((number (random 101)))
> (cond ((< number 50) 'head)
> ((= number 50) 'costs)
> (t 'cross))))
> --
> best wishes,
> Tor Henrik Hanken