Page 1 of 1

why don't this work?

Posted: Fri Apr 14, 2006 12:06 am
by ericsm
why doesn't the following work?

(define (addcustomer )
(set 'namee (read-line))
(set 'street (read-line))
(push '((namee) (street)))customer)

The part that isn't working is: (push '((namee) (street)))customer)

Posted: Fri Apr 14, 2006 2:39 am
by Lutz
Try this program:

Code: Select all

; test
(define (addcustomer)
        (set 'namee (read-line))
        (set 'street (read-line))
        (push (list namee street)  customer)) 
now execute it:

Code: Select all

~> newlisp test
newLISP v.8.8.0 on OSX UTF-8, execute 'newlisp -h' for more info.

> (addcustomer)
John Doe 
123 Main Street, Anytown    
("John Doe" "123 Main Street, Anytown")
> 
Lutz

Posted: Fri Apr 14, 2006 7:28 am
by cormullion
As for why. First:

Code: Select all

(namee)
is trying unsuccessfully to evaluate the first item in this list as the function namee.

But:

Code: Select all

'(namee street)
will produce (namee street), because the quote prevents these symbols from being evaluated.

So your original code:

Code: Select all

'((namee) (street)))
is doing two things that you don't want: preventing evaluation of a list of lists, and trying to evaluate those lists and failing to find useful functions.

WIthout the doubled parentheses:

Code: Select all

(push '(namee street) customer)
you would have a nice unevaluated list of symbols:

Code: Select all

> (push '(namee street) customer)
(namee street)
Since namee contains information you want, evaluate it.