Re: Variable number of arguments in SVG functions
The disadvantage of gensym'd symbols is that the code is more difficult to understand when pretty printed, and cannot be written to some file and retrieved later. True. The PicoLisp solution of transient symbols has an identical effect (especially if you surround the function definition(s) with ()). I see! Though the usage of transient symbols (like gensym'd symbols) nicely protects from symbol capture, there is one nasty detail: Symbols that we *want* to be evaluated in the outer environment, most notably '@'. Thanks for explanation. Is @ the only problem? How serious problem/inconvenience do you consider it? Would not it be possible somehow to rebind it again with some trick along the lines of: (de foo Prg (when (car Prg) (run (let @ (up '@) (cdr Prg)) ) ) ) Why this does not work? Thank you, Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Variable number of arguments in SVG functions
On Wed, Oct 22, 2008 at 04:47:36PM +0100, Tomas Hlavaty wrote: (de foo Prg (let At (up @) (when (car Prg) (let @ At (run (cdr Prg)) : (and 2 (foo T (+ 1 @ 3))) - 6 Yep. In that case, you can even omit the 'up', as '@' is not modified yet. And the 'let's are not needed (just 'setq') because '@' will be internally restored anyway when 'foo' terminates. (de foo Prg (setq At @) (when (car Prg) (setq @ At) (run (cdr Prg)) ) ) But I think we are getting esotherical ;-) Up until now, the simplest (and recommended, I think) version was: (de foo Prg (when (car Prg) (run (cdr Prg) 1) ) ) Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Variable number of arguments in SVG functions
Up until now, the simplest (and recommended, I think) version was: (de foo Prg (when (car Prg) (run (cdr Prg) 1) ) ) Well, I think this version has one important limitation: if Prg has a recursive call(s) to foo, the deeper foo won't see any values set by the foo above, or will it? : (de foo Prg (when (car Prg) (print Foo) (let Foo (pack Foo %) (run (cdr Prg) 1) ) ) ) - foo : (foo T (foo T (foo T)) (foo T)) NILNILNILNIL- NIL : (de foo Prg (when (car Prg) (print Foo) (let Foo (pack Foo %) (run (cdr Prg)) ) ) ) # foo redefined - foo : (foo T (foo T (foo T)) (foo T)) NIL- NIL : (de foo Prg (when (car Prg) (print Foo) (let Foo (pack Foo %) (run (cdr Prg)) ) ) ) - foo : (foo T (foo T (foo T)) (foo T)) FooFoo%Foo%%Foo%- NIL : So if I want to write recursive xml function, I cannot use (run ... 1). So far, I have this: () (de xml Lst (let (At @ Tag (pop 'Lst)) (if Tag (queue 'Xml (make (link Tag) (let Att (make (while (and Lst (atom (car Lst))) (link (cons (pop 'Lst) (eval (pop 'Lst) 1))) ) ) (let Xml NIL (let @ At (run Lst) ) (ifn Xml (when Att (link Att) ) (link Att) (chain Xml) ) ) ) ) ) (let (Xml NIL Out (when (and Lst (atom (car Lst))) (eval (pop 'Lst) 1) ) xmlPrin '(@ (queue 'Xml (pass pack))) ) (let @ At (run Lst) ) (if (=T Out) (car Xml) (out Out (xml (car Xml)) ) ) ) ) ) ) () This works well: : (load '@lib/xml.l) - attr : (and 4 (xml NIL (xml elt att @ (xmlPrin hi elt att=4hi/elt - : I don't think it could possibly work without me being esotheric:-) Thank you, Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Variable number of arguments in SVG functions
Hi Alex and Jon, Indenting is impossible to do well I think because the function does not know what is going to happen in the body (the 'xml' function knows I think so, too. This is also the reason why the functions in lib/xhtml.l don't do any efforts to indent. And with this xml function we go a little in the direction of HTML (as Jon also mentioned in his initial post). So it is possible. The file implementing xml function is attached. I might improve formatting/indenting in the original 'xml' function later. I welcome any comments on the code. Ah, I was not aware that this is also legal in XML. I double checked and it is legal, see http://www.w3.org/TR/REC-xml/#syntax ...they MUST be escaped using either numeric character references or the strings amp; and lt; respectively. The right angle bracket... * Usage of the attached code The top-level xml call can be: (xml T = returns list suitable as input for 'xml' function (xml NIL -3 T = writes to NIL (stdout) with 3 tabs indenting and xml decl (xml /tmp/a 3 = writes to /tmp/a with 3 spaces indenting (xml = writes to NIL (stdout) with no indenting (and 4 (xml NIL -3 T (xml hoy id 123 class 'yes att Xml at @ (xml inner1) (xml text id 123 dx (+ 3 4) dy (* 3 4) xx you me yy ![CDATA[\Me, Myself I\]] (xmlPrin No font color arguments yet) ) (xml inner2 fun abc (xmlPrin Hi 1 asfdlkasjhfdshad) (xml line x 0 y 0 dx 100 dy 100 (xmlPrin thick @)) (xmlPrin Hi 2) ) (xml inner3 (xml inner3a (xml inner3a1) ) ) (xml inner4 fun abc) ) ) ) will print ?xml version=1.0 encoding=utf-8? hoy id=123 class=yes att=Xml at=4 inner1/ text id=123 dx=7 dy=12 xx=you #38; me yy=#60;![CDATA[#34;Me, Myself #38; #60;I#34;]]No font #38; color arguments yet/text inner2 fun=abcHi 1 asfdlkasjhfdshadline x=0 y=0 dx=100 dy=100thick4/lineHi 2/inner2 inner3 inner3a inner3a1/ /inner3a /inner3 inner4 fun=abc/ /hoy Thanks, Tomas (de xmlL Lst (let Att @ (push 'Xml (make (link (pop 'Lst)) (let Att (make (while (and Lst (atom (car Lst))) (link (cons (pop 'Lst) (eval (pop 'Lst) 1))) ) ) (let Xml NIL (let @ At (run Lst) ) (ifn Xml (when Att (link Att) ) (link Att) (chain (flip Xml)) ) ) ) ) ) ) ) (de xmlO Lst (let (Att @ Tag (pop 'Lst) ) (when Nl (prinl) (when Pre (prin Pre) )) (prin Tag) (while (and Lst (atom (car Lst))) (prin (pop 'Lst) =\) (escXml (eval (pop 'Lst) 1)) (prin \) ) (ifn Lst (prin /) (prin ) (use Nlx (let (@ At Nl N Pre (cons Pre Nn)) (run Lst) (setq Nlx Nl) ) (when Nlx (prinl) (when Pre (prin Pre) )) ) (prin / Tag ) ) ) ) (de xml Lst (let (At @ Out (when (and Lst (atom (car Lst))) (eval (pop 'Lst) 1) )) (if (=T Out) (let (Xml NIL xml xmlL xmlPrin '(@ (push 'Xml (pass pack))) ) (let @ At (run Lst) ) (car (flip Xml)) ) (let (N (when (and Lst (atom (car Lst))) (eval (pop 'Lst) 1) ) Decl (when (and Lst (atom (car Lst))) (eval (pop 'Lst) 1) ) Nn NIL Nl NIL Pre NIL xml xmlO xmlPrin '(@ (off Nl) (mapc escXml (rest))) ) (when N (do (abs N) (push 'Nn (if (lt0 N) ^I ))) ) (out Out (when Decl (xml? T) ) (let @ At (run Lst) ) ) ) ) ) ) (de escXml (X) (for C (chop X) (prin (case C (\ quot;) ( amp;) ( lt;) ( gt;) (T C) ) ) ) )
Re: Variable number of arguments in SVG functions
Hi Tomas, maybe it could become part of lib/xml.l? I would use it as it looks more convenient than building list for 'xml' function in some cases. I'm not sure. It might be convenient, but it makes 'xml' asymmetrical. Are you thinking of a separate 'xml' function? It should be tried in practical use. Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Variable number of arguments in SVG functions
Hi Alex, Hi Jon, The test (if (car Lst) ... determines whether the current element is a container (hoy) or not (inner). Is the 'car' necessary? Otherwise a simple test of 'Lst' would suffice. No, it seems to work quite well without the 'car'. ;-) BTW, I always feel that a 'prog' is a kind of kludge, and avoid it if possible by inverting the 'if'. Then the following would also do: (ifn Lst (prinl /) (prin ) (run Lst 1) (prinl / Tag ) ) ) ) ) But perhaps this is a matter of taste. That inversion is OK with me. /Jon Since this is pure XML, it would seem natural to find a function like this xml in lib/xml.l. I haven't studied the functions in that file Tomas also suggested this. I think it is a good idea. I would like to let Tomas make the final decision and/or design. Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Variable number of arguments in SVG functions
Hi Jon, then the calls would very often have a lot of NIL arguments, which looks rather ugly. Should I switch to property lists? Any suggestions? How about the following? (de text Prg (prin text) (while (atom (car Prg)) (prin (pop 'Prg) =\ (eval (pop 'Prg) 1) \) ) (prin ) (run Prg) # the text, or other elements (prinl /text) ) Then you could write : (text id 123 dx (+ 3 4) dy (* 3 4) (prin No font and color arguments yet) ) text id=123 dx=7 dy=12No font and color arguments yet/text Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Variable number of arguments in SVG functions
How about the following? (de text Prg (prin text) (while (atom (car Prg)) (prin (pop 'Prg) =\ (eval (pop 'Prg) 1) \) ) (prin ) (run Prg) # the text, or other elements (prinl /text) ) Then you could write : (text id 123 dx (+ 3 4) dy (* 3 4) (prin No font and color arguments yet) ) text id=123 dx=7 dy=12No font and color arguments yet/text That's nice. It could even be: (de xml Prg (prin (pop 'Prg)) (while (atom (car Prg)) (prin (pop 'Prg) =\ (eval (pop 'Prg) 1) \) ) (prin ) (run Prg) # the text, or other elements (prinl /text) ) (xml text id 123 dx (+ 3 4) dy (* 3 4) (prin No font and color arguments yet) ) :-) Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]