Page 1 of 1

saving the buffer

Posted: Fri May 17, 2013 11:30 pm
by sara_dahmani
Hi,

I'm a new user on newLISP and I would like to know how to save the result of an xml-parse on an xml file to an lsp file.

Best Regards.

Re: saving the buffer

Posted: Sat May 18, 2013 2:24 am
by rickyboy
That's fairly easy to do in newLISP: http://www.newlisp.org/downloads/newlis ... .html#save. Happy hacking!

Re: saving the buffer

Posted: Sat May 18, 2013 11:30 am
by sara_dahmani
hi,
thanks rickyboy for your answer, i already tried the function save :
(save "output.lsp" xml-parse (read-file "input.xml"))
am i doing it wrong ?

Re: saving the buffer

Posted: Sat May 18, 2013 1:55 pm
by rickyboy
Yes. :) No worries though. The most important thing to rememeber about using save is that whatever you require to be saved must be referenced by a symbol. So, all you need to do before calling save is to get the output of xml-parse referenced by a symbol. Use something like define or any variation of set (for instance, setq, setf) — and there are other primitives that assign values to symbols — to accomplish this. Here's an example.

Code: Select all

$ newlisp
newLISP v.10.4.5 on OSX IPv4/6 UTF-8 libffi, execute 'newlisp -h' for more info.

> (setf stuff (xml-parse "<stuff><a>42</a><b>hello</b><c>more</c></stuff>"))
(("ELEMENT" "stuff" () (("ELEMENT" "a" () (("TEXT" "42"))) ("ELEMENT" "b" () (("TEXT" 
      "hello"))) 
   ("ELEMENT" "c" () (("TEXT" "more"))))))
> (save "stuff.lsp" 'stuff)
true
Now go look at the contents of stuff.lsp. You should see a set expression with the symbol you used (in this example, the symbol is stuff) and its value at the time you performed the save.

And as Lutz noted in the manual entry for save, you can later perform a load to retrieve what you saved. Here's what it looks like from a clean (i.e. new invocation of the) REPL.

Code: Select all

$ newlisp
newLISP v.10.4.5 on OSX IPv4/6 UTF-8 libffi, execute 'newlisp -h' for more info.

> (load "stuff.lsp")
(("ELEMENT" "stuff" () (("ELEMENT" "a" () (("TEXT" "42"))) ("ELEMENT" "b" () (("TEXT" 
      "hello"))) 
   ("ELEMENT" "c" () (("TEXT" "more"))))))
> ;;
> ;; It's really loaded and referenced by the symbol `stuff'.  Check it out:
> ;;
> stuff
(("ELEMENT" "stuff" () (("ELEMENT" "a" () (("TEXT" "42"))) ("ELEMENT" "b" () (("TEXT" 
      "hello"))) 
   ("ELEMENT" "c" () (("TEXT" "more"))))))
Pretty cool, eh?

Re: saving the buffer

Posted: Sat May 18, 2013 10:12 pm
by sara_dahmani
perfect , i corrected the syntaxe and it is working now.

Code: Select all

> (setf mysymbol (xml-parse (read-file "ex.xml")))

> (save "example.lsp" 'mysymbol)
true
Thanks so much, have a nice day,