Commas in parameter lists

For the Compleat Fan
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Commas in parameter lists

Post by HPW »

When I read this sample code in the help:

Code: Select all

(define (my-func a b c , x y z)
        (set 'x .....)
        ...
        ...
        )
Make me thinking if this is possible (replacing comma with forward slash):

Code: Select all

(defun my-func (a b c / x y)(setq x 10 y (+ a b c)))
And it works! :-)
Will help me in my work for an xlisp/alisp compatible layer for reusing existing sources. (defun macro from init.lsp)

Maybe it should be added to the doc that it can be another character.
Hans-Peter

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

Post by HPW »

One Problem, this does not work any more:

Code: Select all

(defun test ( a b c / x y)(setq x 10 y(/ a b )))
operator '/' is set to nil inside the function.
But we can do this:

Code: Select all

(defun test ( a b c / x y)(setq x 10 y(div a b )))
Hans-Peter

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

Post by HPW »

So with 7.2.8 this no longer works.

Code: Select all

(defun test ( a b c / x y)(setq x 10 y(div a b)))
symbol is protected : /
called from user defined function test

So have to change to the ',' but loose xlisp-compatibility.
Hans-Peter

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

Post by Lutz »

there would be a 'hack' importing a function like 'sprintf' and using 'dump' (which always has been available but is not doumented):

(unpack "c c" (last (dump '/))) => (0 48)

to get the address of the symbol, than change the symbols flags. The 48 would have to be a 32 (see newlisp.h)

so:
(import "xxxxx" "sprintf")
(sprintf (last (dump '/)) "%c %c" 0 32) ; unprotect symbol /

would probably do it, but I don't know at the moment (have no Win32 SDK docs) which function from what windows library would work. A 'memcpy' would be fine too:

(import "xxxxx" "memcpy")
(memcpy (last (dump '/)) (pack "c c" 0 32) 2) ; unprotect symbol /

Lutz

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

Post by HPW »

Testing it with:

Code: Select all

(import "msvcrt" "sprintf")
(sprintf (last (dump '/)) "%c %c" 0 32)
and

Code: Select all

(import "msvcrt" "memcpy")
(memcpy (last (dump '/)) (pack "c c" 0 32) 2)
crashes both on WIN XP prof.

I am not sure if it is worth to think more about this hack,
because it is platform-dependent.
Hans-Peter

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

Post by Lutz »

There is an undocumented 'cpymem' in 7300, which works:

(cpymem (pack "c c" 0 32) (last (dump '/)) 2)

note, that the order of addresses is 'from' 'to' for cpymem

Lutz

Locked