Re: Variable number of arguments in SVG functions

2008-10-23 Thread Alexander Burger
On Wed, Oct 22, 2008 at 05:52:14PM +0100, Tomas Hlavaty wrote: > 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? Yes, that's right. 'run' takes care to skip the corresponding f

Re: Variable number of arguments in SVG functions

2008-10-23 Thread Alexander Burger
On Wed, Oct 22, 2008 at 05:23:40PM +0100, Tomas Hlavaty wrote: > > > The hard-to-explain thing is, that here (up @ 2) is needed: > > > >(de foo "Prg" > > (when (car "Prg") > > (run (let @ (up @ 2) (cdr "Prg"))) ) ) > > (up @ 2) is not right, it sets @ to 2 which makes the examp

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
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 > func

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
> 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,

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
> For one thing, the quote in the call of 'up' is too much. But this > is not the main problem. Sorry, my mistake. > The hard-to-explain thing is, that here (up @ 2) is needed: > >(de foo "Prg" > (when (car "Prg") > (run (let @ (up @ 2) (cdr "Prg"))) ) ) (up @ 2) is not right,

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Alexander Burger
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 ye

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Alexander Burger
On Wed, Oct 22, 2008 at 03:37:10PM +0100, Tomas Hlavaty wrote: > (de foo "Prg" >(when (car "Prg") > (run (let @ (up '@) (cdr "Prg")) ) ) ) > > Why this does not work? Well, this is a hairy one ;-) For one thing, the quote in the call of 'up' is too much. But this is not the main probl

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
> If you use transient symbols > >(de foo "Prg" > (when (car "Prg") > (run (cdr "Prg")) ) ) > > then it basically works > >: (foo T (+ 1 2 3)) >-> 6 >: (foo NIL (+ 1 2 3)) >-> NIL > > BUT if you want to use '@' > >: (and 2 (foo T (+ 1 @ 3))) >!? (+ 1 @ 3)

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
>> it would be possible to do indenting if the body prg was not run in >> the parent environment. Then we could pass some indenting state to >> the recursive calls of and indent accordingly. > > Should be possible. If we had > >(de (Level . Lst) > (default Level 0) > > Then we could do

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
> 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

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Alexander Burger
Hi Tomas, > it would be possible to do indenting if the body prg was not run in > the parent environment. Then we could pass some indenting state to > the recursive calls of and indent accordingly. Should be possible. If we had (de (Level . Lst) (default Level 0) Then we could do

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
Hi Alex, >> 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 > function we

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Alexander Burger
On Wed, Oct 22, 2008 at 01:22:50PM +0100, Tomas Hlavaty wrote: > The trick with run/eval in parent environment is used quite often in > picoLisp to avoid variable binding clashes. I was wandering whether > it would not be better sometimes to do something like Common Lispers > do with gensyms which

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Alexander Burger
On Wed, Oct 22, 2008 at 10:43:32AM +0100, Tomas Hlavaty wrote: > The body should be printed using ht:Prin to get good escaping. Sorry, didn't read this before my previous post ... > Actually, the more I think about it the less I like it. It just > introduces some questions with application spec

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Alexander Burger
Hi Tomas, thanks for the analysis! > 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

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
> The only problem with this code is that the body is not run in the > parent environment, which I don't know how to fix or what problems it > could cause. The trick with run/eval in parent environment is used quite often in picoLisp to avoid variable binding clashes. I was wandering whether it w

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
The escXml function could be like this: (de escXml (X) (for C (chop X) (prin (case C ("\"" """) ("&" "&") ("<" "<") (">" ">") (T C) ) ) ) ) > It is probably best to automatically escape attributes but leave the >

Re: Variable number of arguments in SVG functions

2008-10-22 Thread Tomas Hlavaty
Hi Jon and Alex, >> Since this is "pure" XML, it would seem natural to find a function like >> this 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. I take it

Re: Variable number of arguments in SVG functions

2008-10-21 Thread Jon Kleiser
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'

Re: Variable number of arguments in SVG functions

2008-10-21 Thread Alexander Burger
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. BTW, I always feel that a 'prog' is a kind of kludge, and avoid it if possible by inverting the 'if'.

Re: Variable number of arguments in SVG functions

2008-10-21 Thread Alexander Burger
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 '' function? It should be tried in practica

Re: Variable number of arguments in SVG functions

2008-10-21 Thread Jon Kleiser
On Mon, Oct 20, 2008 at 04:21:31PM +0100, Tomas Hlavaty wrote: That's nice. It could even be: (de Prg (prin "<" (pop 'Prg)) (while (atom (car Prg)) (prin " " (pop 'Prg) "=\"" (eval (pop 'Prg) 1) "\"") ) (prin ">") (run Prg) # the text, or other elements (prin

Re: Variable number of arguments in SVG functions

2008-10-20 Thread Tomas Hlavaty
Hi Alex, 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. Thanks, Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]

Re: Variable number of arguments in SVG functions

2008-10-20 Thread Alexander Burger
On Mon, Oct 20, 2008 at 04:21:31PM +0100, Tomas Hlavaty wrote: > That's nice. It could even be: > > (de Prg >(prin "<" (pop 'Prg)) >(while (atom (car Prg)) > (prin " " (pop 'Prg) "=\"" (eval (pop 'Prg) 1) "\"") ) >(prin ">") >(run Prg) # the text, or other elements >

Re: Variable number of arguments in SVG functions

2008-10-20 Thread Tomas Hlavaty
> How about the following? > >(de Prg > (prin " (while (atom (car Prg)) > (prin " " (pop 'Prg) "=\"" (eval (pop 'Prg) 1) "\"") ) > (prin ">") > (run Prg) # the text, or other elements > (prinl "") ) > > Then you could write > >: ( id 123 dx (+

Re: Variable number of arguments in SVG functions

2008-10-20 Thread Alexander Burger
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 Prg (prin "") (run Prg) # the text, or other elements (prinl "") ) Then you could write