saving the buffer

For the Compleat Fan
Locked
sara_dahmani
Posts: 3
Joined: Fri May 17, 2013 11:24 pm

saving the buffer

Post 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.

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: saving the buffer

Post by rickyboy »

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

sara_dahmani
Posts: 3
Joined: Fri May 17, 2013 11:24 pm

Re: saving the buffer

Post 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 ?

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: saving the buffer

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

sara_dahmani
Posts: 3
Joined: Fri May 17, 2013 11:24 pm

Re: saving the buffer

Post 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,

Locked