From: Luky10
Subject: Help for a beginner!!!
Date: 
Message-ID: <951144705.197875@fire-int>
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!!

From: Eugene Zaikonnikov
Subject: Re: Help for a beginner!!!
Date: 
Message-ID: <88rtc1$cie$1@nnrp1.deja.com>
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.
From: Eugene Zaikonnikov
Subject: Re: Help for a beginner!!!
Date: 
Message-ID: <88rvmu$e9t$1@nnrp1.deja.com>
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.
From: Tord Kallqvist Romstad
Subject: Re: Help for a beginner!!!
Date: 
Message-ID: <slrn8b5ek6.onu.romstad@janus.uio.no>
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
From: Robert Monfera
Subject: Re: Help for a beginner!!!
Date: 
Message-ID: <38B152E1.C3823F3D@fisec.com>
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!!
From: Martti Halminen
Subject: Re: Help for a beginner!!!
Date: 
Message-ID: <38B15CD7.32C1F595@solibri.com>
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
From: Tor Henrik Hanken
Subject: Re: Help for a beginner!!!
Date: 
Message-ID: <m3wvnybm37.fsf@wooster.localdomain>
[······@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
From: Luky10
Subject: Re: Help for a beginner!!!
Date: 
Message-ID: <951153770.388920@fire-int>
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