question on Design Elements and Patterns in newLISP

For the Compleat Fan
Locked
frontera000
Posts: 72
Joined: Sun Jun 11, 2006 8:02 pm
Location: berkeley, california
Contact:

question on Design Elements and Patterns in newLISP

Post by frontera000 »

i am new to newlisp.

section 6 of Design Elements and Patterns in newLISP
has the following:

(set 'data:data '(a b c d e f g h))

(define (change db i value)
(nth-set (db i) value))

(change data 3 999)

but db is undefined when change is called.
ERR:value expected in function nth-set : (db i)

can anyone tell me why?

William James
Posts: 58
Joined: Sat Jun 10, 2006 5:34 am

Post by William James »

It doesn't work for me either, but the book is for version 8.8.9 of newLISP and my version is 8.8.0. I presume that the code is correct for version 8.8.9.

I had to change

Code: Select all

(nth-set (db i) value))
to

Code: Select all

(nth-set i db value))
and

Code: Select all

(change data 3 999)
to

Code: Select all

(change data:data 3 999)

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

newLISP v.8.8.9 on Win32 MinGW.

> (set 'data:data '(a b c d e f g h))
(a b c d e f g h)
> (define (change db i value)(nth-set (db i) value))
(lambda (db i value) (nth-set (db i) value))
> (change data 3 999)
d
> data
data
> data:data
(a b c 999 e f g h)
>
Works for me.
Hans-Peter

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Perhaps this is the change introduced in 8.8.1, so still in the Development release and release notes...
implicit n-rest and slice on default lists and strings:
(set 'foo:foo '(a s d f g h j))
(2 foo) => (d f g h j)
(-3 2 foo) => (g h)
Or perhaps it isn't.

The Design Patterns document is way ahead of itself, it seems! Good for it, but confusing if that's one piece of the documentation that isn't tied to the release...

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Sorry for the version confusion with the "Design Patterns" document, it says: "newLISP 8.8.9 and after" on the title page. I will add this also on the Documentations page so it does not get overlooked.

Lutz

Locked