newLISP Fan Club

Forum => newLISP newS => Topic started by: ale870 on September 04, 2008, 08:10:44 AM

Title: Ugly behaviuor of doargs
Post by: ale870 on September 04, 2008, 08:10:44 AM
Hello,



I'm using newlisp version V.9.4.3 on Linux, and I found a bad behaviour of doargs function.

Look at here:


(define (form-create , locVariable)
(doargs (i) (println "I: " i) )
)

(form-create "a1" "a2" 3 4 "z5")


In this case I obtain the following result:


I: 3
I: 4
I: z5


As you can see, even if I defined a local variable "locVariable", the function doargs bypassed the first two items "a1" and "a2".

Instead if I create a function without local vars it works:


(define (form-create)
(doargs (i) (println "I: " i) )
)

(form-create "a1" "a2" 3 4 "z5")

I: a1
I: a2
I: 3
I: 4
I: z5


Is it a bug or I'm wrong?
Title:
Post by: cormullion on September 04, 2008, 09:08:57 AM
I suspect that doargs is similar to args in that it looks only at unbound variables:



"Only the arguments of the current function or macro that remain after local variable binding has occurred are available."



If so, the description for (doargs) could do with a tweak?
Title:
Post by: Kazimir Majorinc on September 04, 2008, 09:26:53 AM
I think it is just as it should be:


(define (form-create , locVariable)
   (println ,)
   (println locVariable)
   (doargs (i) (println "I: " i) )
)

(form-create "a1" "a2" 3 4 "z5")


gives:



a1

a2

I: 3

I: 4

I: z5
Title:
Post by: ale870 on September 04, 2008, 10:02:44 AM
But this is not coherent with the concept that variables behind a comma   are local variables.

Only alternative I found was using (let) function to define local ones.
Title:
Post by: Jeff on September 04, 2008, 01:23:21 PM
Comma-variables are convention, not spec.
Title:
Post by: Kazimir Majorinc on September 04, 2008, 03:35:33 PM
Quote from: "ale870"But this is not coherent with the concept that variables behind a comma   are local variables.

Only alternative I found was using (let) function to define local ones.


As Jeff said, comma is trick. An alternative to "let" is "local."
Title:
Post by: ale870 on September 04, 2008, 10:41:45 PM
Ok, now I see.

I didn't think that comma was a "convention" and not an "official" behaviuor.

Now I will always use "let".



Thank you!.
Title:
Post by: DrDave on September 05, 2008, 02:33:45 AM
You have to look at it like this. In your first definition, you have two formal arguments, comma and locVariable. So, when you called your function thus (form-create "a1" "a2" 3 4 "z5"), it binds "a1" to comma, "a2" to locVariable, and then leaves the specific arguments 3, 4, "z5" for the body expression to deal with.



You can verify this by printing comma and locVariable in the body expression.



As was already stated, using comma is just a visual trick. Because comma is just another symbol, It realy *does* get bound to either a value or nil. You just don't (normally) make any use of it.