saving the buffer

Started by sara_dahmani, May 17, 2013, 04:30:48 PM

Previous topic - Next topic

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.

rickyboy

#1
That's fairly easy to do in newLISP: http://www.newlisp.org/downloads/newlisp_manual.html#save">//http://www.newlisp.org/downloads/newlisp_manual.html#save.  Happy hacking!
(λx. x x) (λx. x x)

sara_dahmani

#2
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 ?

rickyboy

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


$ 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 http://www.newlisp.org/downloads/newlisp_manual.html#save">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.


$ 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?
(λx. x x) (λx. x x)

sara_dahmani

#4
perfect , i corrected the syntaxe and it is working now.


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

> (save "example.lsp" 'mysymbol)
true


Thanks so much, have a nice day,