why don't this work?

Started by ericsm, April 13, 2006, 05:06:05 PM

Previous topic - Next topic

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)
I am a newbe so please help me

Lutz

#1
Try this program:



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


now execute it:



~> 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

cormullion

#2
As for why. First:


(namee)

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



But:


'(namee street)

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



So your original code:


'((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:


(push '(namee street) customer)

you would have a nice unevaluated list of symbols:


> (push '(namee street) customer)
(namee street)


Since namee contains information you want, evaluate it.