From: John Somerville
Subject: destroying old definitions
Date: 
Message-ID: <88492-847250009@mindlink.bc.ca>
I am a beginner.

Q1) Suppose I define a function 'foo and get it wrong.   Now if I redefine
function 'foo my lisp system has two foos.   How do I defuze the first 'foo
before I define the second 'foo.  Better yet, can I access deeply nested
'foos?

Q2) I am using XLisp and I try the following:
        (setq house '((color white) (trim black) (location suburbs)))

    Now if I type:
        (assoc 'color house)
    The machine returns 'white.

b B But if I type:
        (get 'house color)
    The machine returns 'nil.

    Have I got the syntax wrong, or is XLisp different?

regards John

From: DDL
Subject: Re: destroying old definitions
Date: 
Message-ID: <55q8nd$qm5@decius.ultra.net>
···············@mindlink.bc.ca (John Somerville) wrote:
>
> I am a beginner.
> 
> Q1) Suppose I define a function 'foo and get it wrong.   Now if I redefine
> function 'foo my lisp system has two foos.   How do I defuze the first 'foo
> before I define the second 'foo.  Better yet, can I access deeply nested
> 'foos?

You're not define two foos.  When you redefine foo, the old definition
goes away.  What DEFUN does is bind a user-defined function to the
function slot of a symbol (in this case FOO).  If you use DEFUN again,
the old function gets discarded (and then garbage collected), the
the new function is attached to FOO.

I'm not sure what you mean by "deeply nested foos"


> 
> Q2) I am using XLisp and I try the following:
>         (setq house '((color white) (trim black) (location suburbs)))
> 
>     Now if I type:
>         (assoc 'color house)
>     The machine returns 'white.
> 
> b B But if I type:
>         (get 'house color)
>     The machine returns 'nil.

You're confusing associations with property lists. An association is
a list of pairs, where usually the first is an identifier and the next
is a value, in your example '((color white) etc..)

The function ASSOC simply searches a list for a pair where the CAR
matches the supplied parameter, and then returns the CADR 
(car of the CDR).

Properties are a different feature.  Lisp symbols have a property
slot, where "properties" can be stored, usually using an association
list.  Remember: associations work on lists, properties work on
symbols.

So in your example, you're trying to get the property of color from
the symbol house, but you have not SET that property value yet, 
therefore it returns NIL.

Hope this helps,

David Lowry

···@DBRC.com
From: Jens Kilian
Subject: Re: destroying old definitions
Date: 
Message-ID: <55t021$gc6@isoit109.bbn.hp.com>
DDL (···@DBRC.com) wrote:
> Properties are a different feature.  Lisp symbols have a property
> slot, where "properties" can be stored, usually using an association
> list.  Remember: associations work on lists, properties work on
> symbols.

IIRC, property lists are NOT association lists:

Alist	'((foo . 1) (bar . 2) (baz . 3) (zip . 42))
Plist	'( foo   1   bar   2   baz   3   zip   42 )

Greetings,

	Jens.
--
Internet:  ···········@bbn.hp.com  Phone: +49-7031-14-7698 (TELNET 778-7698)
MausNet:   [currently offline]     Fax:   +49-7031-14-7351
PGP:       06 04 1C 35 7B DC 1F 26 As the air to a bird, or the sea to a fish,
0x555DA8B5 BB A2 F0 66 77 75 E1 08 so is contempt to the contemptible. [Blake]
From: Lyman S. Taylor
Subject: Re: destroying old definitions
Date: 
Message-ID: <55qcl7$3fa@pravda.cc.gatech.edu>
In article <···············@mindlink.bc.ca>,
John Somerville <···············@mindlink.bc.ca> wrote:
>I am a beginner.
>
>Q1) Suppose I define a function 'foo and get it wrong.   Now if I redefine
>function 'foo my lisp system has two foos.   How do I defuze the first 'foo
>before I define the second 'foo.  Better yet, can I access deeply nested
>'foos?

  "Deeply nest" I'll assume means to define a function within a function.
  The following does NOT work. 

	(defun foo () 3 )
	
	(defun superfoo()  (defun foo () 5 ) (+ 2 (foo)))

  The DEFUN has a global side effect. So after evaluating SUPERFOO the 
  definition of FOO will be changed.

	(defun superfoo()  
	  (labels (  (foo () 5 ) )
	     (+ 2 (foo ))))

  Above there is a local only version of FOO.  The above is Common Lisp.

 In Scheme, I'm pretty sure you  can nest DEFINEs and get the local scoping
 property.   Never used XLisp...

-- 
					
Lyman S. Taylor            "It's not *OUR* fault....."
(·····@cc.gatech.edu)           Kei and Yuri , the 'Dirty Pair'... eerrr
					'Lovely Angels'
From: Sunil Mishra
Subject: Re: destroying old definitions
Date: 
Message-ID: <efyg22mocbm.fsf@cleon.cc.gatech.edu>
In article <···············@mindlink.bc.ca> ···············@mindlink.bc.ca (John Somerville) writes:

\\ Q1) Suppose I define a function 'foo and get it wrong.   Now if I redefine
\\ function 'foo my lisp system has two foos.   How do I defuze the first 'foo
\\ before I define the second 'foo.  Better yet, can I access deeply nested
\\ 'foos?

You don't need to worry about the old definition. It is automatically
discarded.

I don't understand deeply nested.

\\ Q2) I am using XLisp and I try the following:
\\         (setq house '((color white) (trim black) (location suburbs)))
\\ 
\\     Now if I type:
\\         (assoc 'color house)
\\     The machine returns 'white.
\\ 
\\ b B But if I type:
\\         (get 'house color)
\\     The machine returns 'nil.
\\ 
\\     Have I got the syntax wrong, or is XLisp different?

The value of a symbol is different from its property list. get will
access the property list of the symbol, while assoc will look at its
value. Common lisp has another function, getf, that allows to treat the
value of the variable as a property list.

To set the value in a property list in common lisp, you would have to say:

(setf (get 'house 'color) 'white)

This will have no effect on the value. I am assuming the syntax in xlisp
would be similar.

If you are using a PC, I would recommend getting freelisp from Harlequin,
http://www.harlequin.com/ provided of course you have the resources to run
it.

Sunil