[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Chapter 6 of Paul Graham's Ansi Common Lisp : Functions as Representation

gengyangcai

7/15/2015 8:45:00 AM

So I am currently going through chapter 6 of Paul Graham's Ansi Common Lisp : Functions as Representations.

6.1 Networks
Closures have three useful properties: they are active, they have local state, and we can make multiple instances of them. Where could we use multiple copies of active objects with local state? In applications involving networks, among others. In many cases we can represent nodes in a network as closures. As well as having its own local state, a closure can refer to another closure. Thus a closure representing a node in a network can know of several other nodes (closures) to which it must send its output. This means that we may be able to translate some networks straight into code.

The first figure given in the book , figure 6.1: Session of twenty questions given in the book looks like this :

> (run-node 'people)
Is the person a man?
>> yes
Is he living?
>> no
Was he American?
>> yes
Is he on a coin?
>> yes
Is the coin a penny? >> yes
LINCOLN

When I tried to run the first line of the program in Lispworks , this is what I got :

CL-USER 3 : 2 > (run-node 'people)

Error: Undefined operator RUN-NODE in form (RUN-NODE (QUOTE PEOPLE)).
1 (continue) Try invoking RUN-NODE again.
2 Return some values from the form (RUN-NODE (QUOTE PEOPLE)).
3 Try invoking something other than RUN-NODE with the same arguments.
4 Set the symbol-function of RUN-NODE to another function.
5 Set the macro-function of RUN-NODE to another function.
6 (abort) Return to level 2.
7 Return to debug level 2.
8 Return to level 1.
9 Return to debug level 1.
10 Return to level 0.
11 Return to top loop level 0.

Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.

I tried debugging it and invoking RUN-NODE again, but kept getting similar error messages

If anyone is interested in testing this piece of code and can get it to work or faces similar issues , let me know thanks a lot !


CAI GENGYANG
gengyangcai@gmail.com

3 Answers

Pascal J. Bourguignon

7/15/2015 9:24:00 AM

0

CAI GENGYANG <gengyangcai@gmail.com> writes:

> So I am currently going through chapter 6 of Paul Graham's Ansi Common
> Lisp : Functions as Representations.
>
> 6.1 Networks
> Closures have three useful properties: they are active, they have
> local state, and we can make multiple instances of them. Where could
> we use multiple copies of active objects with local state? In
> applications involving networks, among others. In many cases we can
> represent nodes in a network as closures. As well as having its own
> local state, a closure can refer to another closure. Thus a closure
> representing a node in a network can know of several other nodes
> (closures) to which it must send its output. This means that we may be
> able to translate some networks straight into code.
>
> The first figure given in the book , figure 6.1: Session of twenty
> questions given in the book looks like this :
>
>> (run-node 'people)

No.


The first thing would be that you knew what book you are reading.
Usually, the title of the book is written on the first page, or on the
cover.

There is no RUN-NODE function defined or talked about in Paul Graham's
"ANSI Common Lisp" (and neither in the associated source code file
acl2.lisp that you can find on Paul's web site).



There is a RUN-NODE function mentionned in "On Lisp", but it is not in
the source code file onlisp.lisp that you can find on Paul's web site.



So once you'll have made up your mind on what book you are reading,
think about how it would be possible for a function to go from a printed
book to your Common Lisp implementation in your computer?

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

gengyangcai

7/15/2015 9:29:00 AM

0

On Wednesday, July 15, 2015 at 5:24:20 PM UTC+8, informatimago wrote:
> CAI GENGYANG <gengyangcai@gmail.com> writes:
>
> > So I am currently going through chapter 6 of Paul Graham's Ansi Common
> > Lisp : Functions as Representations.
> >
> > 6.1 Networks
> > Closures have three useful properties: they are active, they have
> > local state, and we can make multiple instances of them. Where could
> > we use multiple copies of active objects with local state? In
> > applications involving networks, among others. In many cases we can
> > represent nodes in a network as closures. As well as having its own
> > local state, a closure can refer to another closure. Thus a closure
> > representing a node in a network can know of several other nodes
> > (closures) to which it must send its output. This means that we may be
> > able to translate some networks straight into code.
> >
> > The first figure given in the book , figure 6.1: Session of twenty
> > questions given in the book looks like this :
> >
> >> (run-node 'people)
>
> No.
>
>
> The first thing would be that you knew what book you are reading.
> Usually, the title of the book is written on the first page, or on the
> cover.
>
> There is no RUN-NODE function defined or talked about in Paul Graham's
> "ANSI Common Lisp" (and neither in the associated source code file
> acl2.lisp that you can find on Paul's web site).
>
>
>
> There is a RUN-NODE function mentionned in "On Lisp", but it is not in
> the source code file onlisp.lisp that you can find on Paul's web site.
>
>
>
> So once you'll have made up your mind on what book you are reading,
> think about how it would be possible for a function to go from a printed
> book to your Common Lisp implementation in your computer?
>
> --
> __Pascal Bourguignon__ http://www.informat...
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk

Sorry, I mistyped --- its not Ansi Common Lisp, but rather the book On Lisp : http://ep.yimg.com/ty/cdn/paulgraham/... --- scroll all the way down to Chapter 6, figure 6.1

CAI GENGYANG

gengyangcai

7/15/2015 10:33:00 AM

0

On Wednesday, July 15, 2015 at 5:29:24 PM UTC+8, CAI GENGYANG wrote:
> On Wednesday, July 15, 2015 at 5:24:20 PM UTC+8, informatimago wrote:
> > CAI GENGYANG <gengyangcai@gmail.com> writes:
> >
> > > So I am currently going through chapter 6 of Paul Graham's Ansi Common
> > > Lisp : Functions as Representations.
> > >
> > > 6.1 Networks
> > > Closures have three useful properties: they are active, they have
> > > local state, and we can make multiple instances of them. Where could
> > > we use multiple copies of active objects with local state? In
> > > applications involving networks, among others. In many cases we can
> > > represent nodes in a network as closures. As well as having its own
> > > local state, a closure can refer to another closure. Thus a closure
> > > representing a node in a network can know of several other nodes
> > > (closures) to which it must send its output. This means that we may be
> > > able to translate some networks straight into code.
> > >
> > > The first figure given in the book , figure 6.1: Session of twenty
> > > questions given in the book looks like this :
> > >
> > >> (run-node 'people)
> >
> > No.
> >
> >
> > The first thing would be that you knew what book you are reading.
> > Usually, the title of the book is written on the first page, or on the
> > cover.
> >
> > There is no RUN-NODE function defined or talked about in Paul Graham's
> > "ANSI Common Lisp" (and neither in the associated source code file
> > acl2.lisp that you can find on Paul's web site).
> >
> >
> >
> > There is a RUN-NODE function mentionned in "On Lisp", but it is not in
> > the source code file onlisp.lisp that you can find on Paul's web site.
> >
> >
> >
> > So once you'll have made up your mind on what book you are reading,
> > think about how it would be possible for a function to go from a printed
> > book to your Common Lisp implementation in your computer?
> >
> > --
> > __Pascal Bourguignon__ http://www.informat...
> > "The factory of the future will have only two employees, a man and a
> > dog. The man will be there to feed the dog. The dog will be there to
> > keep the man from touching the equipment." -- Carl Bass CEO Autodesk
>
> Sorry, I mistyped --- its not Ansi Common Lisp, but rather the book On Lisp : http://ep.yimg.com/ty/cdn/paulgraham/... --- scroll all the way down to Chapter 6, figure 6.1
>
> CAI GENGYANG

Anyway, I was checking up with a hacker friend on this issue and he said that the stuff in Figure 6.1 is not code but console output , a sample interaction from a program they were going to discuss later. I tried the rest of the code examples up till Figure 6.4 and managed to get all of them to work except the code example in Figure 6.5(which gave me an error message)

I'm going to post the output of the code example up till figure 6.4 here , and try to figure out figure 6.5 later :

CL-USER 1 >
(defnode 'people "Is the person a man?" 'male 'female)
#S(NODE :CONTENTS "Is the person a man?" :YES MALE :NO FEMALE)

CL-USER 2 > (defstruct node contents yes no)
NODE

CL-USER 3 > (defvar *nodes* (make-hash-table))
*NODES*

CL-USER 4 > (defun defnode (name conts &optional yes no) (setf (gethash name *nodes*)
(make-node :contents conts :yes yes
:no no)))
DEFNODE

CL-USER 5 > (defnode 'people "Is the person a man?" 'male 'female)
#S(NODE :CONTENTS "Is the person a man?" :YES MALE :NO FEMALE)

CL-USER 6 > (defnode 'male "Is he living?" 'liveman 'deadman)
#S(NODE :CONTENTS "Is he living?" :YES LIVEMAN :NO DEADMAN)

CL-USER 7 > (defnode 'deadman "Was he American?" 'us 'them)
#S(NODE :CONTENTS "Was he American?" :YES US :NO THEM)

CL-USER 8 > (defnode 'us "Is he on a coin?" 'coin 'cidence)
#S(NODE :CONTENTS "Is he on a coin?" :YES COIN :NO CIDENCE)

CL-USER 9 > (defnode 'coin "Is the coin a penny?" 'penny 'coins)
#S(NODE :CONTENTS "Is the coin a penny?" :YES PENNY :NO COINS)

CL-USER 10 > (defnode 'penny 'lincoln)
#S(NODE :CONTENTS LINCOLN :YES NIL :NO NIL)

CL-USER 11 > (defun run-node (name)
(let ((n (gethash name *nodes*)))
(cond ((node-yes n)
(format t "~A~%>> " (node-contents n)) (case (read)
(yes (run-node (node-yes n)))
(t (run-node (node-no n))))) (t (node-contents n)))))
RUN-NODE


CAI GENGYANG