sxml to xml (xhtml)

Started by chen, March 10, 2004, 06:01:24 PM

Previous topic - Next topic

chen

Hi everyone,



I noticed newlisp a while ago, like the small foot print and the concept of keeping everything small and simple.



On the other hand, most of the folks have been doing coding in a more complex way for a very long time,  including myself.  In my case, it became a challenge in my thinking pattern, I admit that I have been brain washed for years.



Anyway, I'd like to say thanks for making newlisp available, it's refreshing compare to the rest of the languages wildly used in most of the industries.



Question: Is there a way to convert s-expression to xml or (xhtml) ?  I notice how easy it is to parse xml in newlisp. I am thinking if this can be done, then the door will be wide open for newlisp to the browsers. There are many javascript xml parsers available for 90% of the web browsers.



Regards.

Lutz

#1
Hello Chen,



very welcome to the group and newLISP. At the moment newLISP only does SXML to S-expressions conversion. Bit the other way is very simple to code in most instances and diffcult to generalize for any kind of problem.



There is also the possibility to evaluate S-expressionns so that they format themselves to XML, and this is the real beauty of SXML:



Imagine this is your SXML: (atag a b c)



Now define a macro or function for 'atag'



(define-macro (atag )

  (append "<atag> " (join (map string (args)) " ") " </atag>"))



Now evaluate ther SXML

(atag a b c) => "<atag> a b c </atag>"



So the idea is to define a function or macro for every tag and then let them format themselves ;-)



Lutz

chen

#2
Hi Lutz,



I am  a bit new to the newlisp kind of coding concept such as define-macro and the lambda. I am not quite understand the full protential of these functions yet,  getting there slowly.



I did some testing and here is what I come up with so far:



(define (parsetree alist ps ((gs "")))

  (set 'gs (string gs ps))

  (while (> (length alist) 0)

   (set 'tmp (pop alist))

   (set 'gs (string gs "<" (first tmp) ">"))

   (if (list? (nth 1 tmp))

    (set 'gs (string gs (parsetree (nth 1 tmp) "")))

    (set 'gs (string gs (last tmp) "</" (first tmp) ">"))))gs)



(set 'record '(

  (field1 "ddfeewfw")

  (field2 ((child1 "") (child2 "")))

  (field3 "fdss")))



(parsetree record "")



output->

    <field1>ddfeewfw</field1>

    <field2><child1></child1>

               <child2></child2>

   <field3>fdss</field3>



As you can see the approach I am taking is still very non lisp. which result

in a bigger foot print in the code.



Once again, thanks for the tips with the define-macro, I will give it a try, hopely it will help me parseing not only the xml tags but all the attributes too.



Regards,

Lutz

#3
Very nice, only one comment:



(define (parsetree alist ps ((gs "")))



the '((gs "")) doesn't do anything since newLISP version 7.3.0, and is also not necessary in your function, you can just do wihtout it:



(define (parsetree alist ps)  .....)



It seems to me that you are using still 7.2 or older version? You should get the 7.5 release or the 7.5.8 development version from http://newlisp.org">http://newlisp.org



About 'define-macro', this like many other things in newLISP work different from conventional LISPs, see the manual.



Lutz

chen

#4
Hi Lutz,



I did revmove the extra ((gs "")) as you suggested on both 7.1** and 7.52 version, both of  them works.



I kind of like the ((gs "" )) , according to the help document, it provides me a way of serializing the object and the statics vars; such a nice features!! Whole lots of potential for database or something like apache's sessions on the serverside.



Pretty happy with the current sxml to xml functions(for now), I am  working on the javascript for the browser side to sync with the DOM objects.



Regards,

Lutz

#5
Static variables in lambda expreessions where abondaned in version 7.3, and there is no reference about it in the 7.5.x documentation. Make sure you are using a 7.5.x version!



But you still can have objects with enclosed static variable contents by using contexts. These contexts can be saved/serialized to a file. All variables in a context are static to that context and lexically seperated from other contexts.



Using 'save' you can fully serialize contexts or any other contents stored in a variable symbol. There are chapters in the documentation on how to do this.



There was a great speedup of 'xml-parse' in version 7.5.4. Mainly on bigger files. Make sure your are running on of the later development releases.



I have used JavaScript in some of my newLISP cgi programs as well and it works great together.



Lutz

chen

#6
Hi  Lutz,



Thanks for the info on the static variables, I will remember to use contexts from now on,



Here is an idea forming on top of my head:

After being through the life cycles of developments, I am starting to think that it's really important to re-think the coding approach from ground up, instead of keep on wraping some

complex codes and carry them through out the life cycles due to "Programer's EGO".



So I am starting to re-enginer myself with the following:



1: Use newLisp on the server side to manage all logics rules and de-normalized  

    database structures.

2: Browser front end communicate with server side newlisp interface. (sxml <-->xml)



3: Finally, the crazy part,  is there a way to code and run newlisp right in side the  

    browser?  I ran into an javascript implementating which can run and compile R5RS

    (scheme).   But not sure how different it is between newlisp and scheme syntax.



The idea of keeping everything simple by using newlisp in all these tiers of process should really cut down lot's of overhead on development, debuging, implementing

and support cycles.  



What do you think about the  "newlisp in browser" ??



Regards,

Lutz

#7
Hi Chen,



using newLISP client side like JavaScript seems like a good idea, but I am not familiar enough with the hooks current browsers offer to built in execution of newLISP. newLISP would also have to be expanded with a DOM interface and made secure omitting a lot of stuff like file I/O, importing libraries etc..



So you would have to offer a plugin for all browsers out there (some can't even do JavaScript at this time). At the moment there are no plans to do all this, but you can still use newLISP embedded in a webpage but parsed out and evaluated server side.



The newlisp-IDE-22.tgz in the download directory is a good example for this. There you have newLISP source embedded in HTML pages. Another example is newlisp-wiki-10.tgz which also embeds newLISP source in 'blog.html'.



Of course all this doesn't give you DOM integration, which probably is what you are interested in. What you could do is create helper functions in newLISP which output JavaScript code doing the DOM stuff on the browser side.



Lutz

chen

#8
Actually, I am running some webpage with javascript parser to evaluate scheme code. Which already intergrated with a hook to the browser's DOM or javascript routines.



My question for you will be : you think the syntax between newlisp and schem can co exists? What will you suggest I do to make them seemless?



Regards,

Lutz

#9
The syntax is pretty much the same, but so many functions work differently, too make this seamless you would have to go through every Scheme function  implemented in JavaScript and see how it works in newLISP.



Lutz

chen

#10
Hi Lutz,



The javascript shceme parser is no way comparing to newlisp at all,  I am just trying to stream line the coding effort for example:



I am thinking to code newlisp like syntax on the browser based REPL  console,  then pass the sexpression through remoting to the server side newlisp process or cgi then the call back on the javascript parser will pick it up then do the very basic evaluation then taking care of the DOM or GIU front end.



Kind of tired of debuging all these different pieces of programing languages. That's what I called Wrapping the complicated coding design while here Iam  thinking it's possiable to do all my coding in newlisp all the way around.   I might be dreaming or crazy :))



Regards,

chen

#11
Hi Lutz,



Being thinking about your respondes couple times just to make sure I fully understand you, without my programer's assumption of "I think I know that".



I  will have to say bye or run away from these scheme implementations for my new quest.  In some way I think they might be complicating the issues, including the js version.



I also check out the sxml  and stuff for scheme, their libs to do all that are bigger than newLisp's foot print or exe , while newLisp does it in one function.



Back to the basic form of the matters..  like you suggested newLisp returns html and JS to the client browser.  Only I will call it " html and javascript embeded inside newlisp" !!



Regards,

Lutz

#12
Interacting between javaScript on the client and the backend newLISP seems like an interesting idea! Keep us updated on your work.



Lutz