From: Alfred Teoh Siang Huat
Subject: Simple LISP qustion. Pls help me to solve this. Can you?
Date: 
Message-ID: <368096B5.38A564E1@domain.com>
Hi,

Could you pls help me to solve this easy problem ?

1) How can I write  a FETCH procedure that takes a key and an ssociation
list.  If the key found, the
first element of an item on the association list than the second item is
to be returned.
Other wise FETCH is to return nil.  eg:-

(SETQ CHART '((TEMPERATURE 100)(PRESSURE(120 60)) (PULSE 72)))

(FETCH 'TEMPERATURE CHART)
100

(FETCH 'COMPLAINTS CHART)
NIL


2) Define PRESENTP a predicate that determines whether a given atom
occurs anywhere in an expression.
PRESENTP differs from MEMBER, in that MEMBER looks at the top level
instances. Symbolic Mathematics systems
makes use of a procedure like PRESENTP to determine if an expression
contains a particular variable.  Consider
these examples.

(SETQ FORMULA '(SQRT(/(+EXPT X 2) (EXPT Y 2))2.0)))

(PRESENTP 'X FORMULA)
T

(PRESENTP 'Z FORMULA)
NIL.

3) Define CIRCLE such that it returns a list of the circumference and
area of a circle whose radius is given. Assume
PI is a global free variable whose value is PI.

Thank you.

Pls send the solution to me ··········@hotmail.com if possible.

Best Regards,
Teoh.

From: Larry Kramer
Subject: Re: Simple LISP qustion. Pls help me to solve this. Can you?
Date: 
Message-ID: <3680F5EC.9554E7FC@stsci.edu>
Alfred Teoh Siang Huat wrote:
> 
> Hi,
> 
> Could you pls help me to solve this easy problem ?
> 
> 1) How can I write  a FETCH procedure that takes a key and an ssociation
> list.  If the key found, the
> first element of an item on the association list than the second item is
> to be returned.
> Other wise FETCH is to return nil.  eg:-
> 
> (SETQ CHART '((TEMPERATURE 100)(PRESSURE(120 60)) (PULSE 72)))
> 
> (FETCH 'TEMPERATURE CHART)
> 100
> 
> (FETCH 'COMPLAINTS CHART)
> NIL
> 
> 2) Define PRESENTP a predicate that determines whether a given atom
> occurs anywhere in an expression.
> PRESENTP differs from MEMBER, in that MEMBER looks at the top level
> instances. Symbolic Mathematics systems
> makes use of a procedure like PRESENTP to determine if an expression
> contains a particular variable.  Consider
> these examples.
> 
> (SETQ FORMULA '(SQRT(/(+EXPT X 2) (EXPT Y 2))2.0)))
> 
> (PRESENTP 'X FORMULA)
> T
> 
> (PRESENTP 'Z FORMULA)
> NIL.
> 
> 3) Define CIRCLE such that it returns a list of the circumference and
> area of a circle whose radius is given. Assume
> PI is a global free variable whose value is PI.
> 
> Thank you.
> 
> Pls send the solution to me ··········@hotmail.com if possible.
> 
> Best Regards,
> Teoh.

Teoh,

You will find people in this newsgroup very willing to help you if
you're
*stuck* on a problem, but we're not going to do your homework for you.
I solved similar problems 17 years ago when I first learned Lisp,
and I struggled with the harder ones at that time.  But, I began to
learn
Lisp in the process.

Regards,

Larry
From: Barry Margolin
Subject: Re: Simple LISP qustion. Pls help me to solve this. Can you?
Date: 
Message-ID: <WF9g2.31$en4.4490@burlma1-snr1.gtei.net>
In article <·················@domain.com>,
Alfred Teoh Siang Huat  <···········@domain.com> wrote:
>Could you pls help me to solve this easy problem ?

Yes, these should be very easy.  Maybe you should explain why they're
giving you so much trouble?  Perhaps show the code that you tried, and we
could explain where you went wrong.

>1) How can I write  a FETCH procedure that takes a key and an ssociation
>list.  If the key found, the
>first element of an item on the association list than the second item is
>to be returned.
>Other wise FETCH is to return nil.  eg:-

Use ASSOC and SECOND.  WTP?

>2) Define PRESENTP a predicate that determines whether a given atom
>occurs anywhere in an expression.
>PRESENTP differs from MEMBER, in that MEMBER looks at the top level
>instances. Symbolic Mathematics systems
>makes use of a procedure like PRESENTP to determine if an expression
>contains a particular variable.  Consider
>these examples.

This seems like it should be a trivial recursive function.  If the
expression is an atom, test whether it's EQL to the object.  If not,
recurse on the car and cdr of the expression.

>3) Define CIRCLE such that it returns a list of the circumference and
>area of a circle whose radius is given. Assume
>PI is a global free variable whose value is PI.

These are simple, well-known mathematical formulas: 2 pi r and pi
r-squared.  How hard could it possibly be to translate them into Lisp?
Please help us help you by explaining what's confusing you.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.
From: David Steuber
Subject: Re: Simple LISP qustion. Pls help me to solve this. Can you?
Date: 
Message-ID: <m3g1a5kudg.fsf@solo.david-steuber.com>
Isn't this remarkably like a homework problem from a 100 level
programming course?  It amazes me that people still ask these things.

Of course a homework problem wouldn't be quite so bad if the poster at 
least made an attempt at it and posted the code.  Then at least people 
could comment on the effort.

Oh, and the poster doesn't want to bother looking at the news group
for replies.  He wants personal e-mail.

Merry Winter Solstice

PS David Steuber will figure out how to use gnus properly in the
fairly distant future.