Commas in parameter lists

Started by HPW, November 01, 2003, 11:32:21 PM

Previous topic - Next topic

HPW

When I read this sample code in the help:


(define (my-func a b c , x y z)
        (set 'x .....)
        ...
        ...
        )


Make me thinking if this is possible (replacing comma with forward slash):


(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

#1
One Problem, this does not work any more:


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


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

HPW

#2
So with 7.2.8 this no longer works.


(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

#3
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

#4
Testing it with:


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


and


(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

#5
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