Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - paweston2003

#1
newLISP in the real world / Re: Newbie question
January 27, 2013, 08:09:07 AM
Quote from: "cormullion"Well, if it works reliably on your test examples, it's 'good enough' code! :)



I think there's no real alternative to carefully slicing it up like you're doing. Although by slicing the XML into pieces presumably it's no longer valid XML when it comes out...?


That's right. I was thinking of outputting some basic markdown, and then importing it into the Retext program. After I posted this I thought of chopping up the text before feeding it into xml-parse. However it will definitely be malformed then. I will see if that works when I get home from work. I can always paste on html and body tags to reform it.


Quote from: "hilti"Welcome Peter!



Would You please post an example of Your XML. It's easier to help then.



Thanks

- Marc


It is the "Introduction to Scheme" at uTexas. I saw that it was in the "garbage" folder there, I want to read it, but the format is awful. Retext will output this as pdf. I found it while trying to figure out "(+1- var)" syntax. I definitely prefer "dec".



ftp://ftp.cs.utexas.edu/pub/garbage/cs345/schintro-v14/schintro_12.html#SEC12">ftp://ftp.cs.utexas.edu/pub/garbage/cs3 ... html#SEC12">ftp://ftp.cs.utexas.edu/pub/garbage/cs345/schintro-v14/schintro_12.html#SEC12



Thanks-

Peter
#2
newLISP in the real world / Newbie question
January 26, 2013, 04:26:08 PM
I'm new to newLISP and to LISP in general.



I am trying return a slice of an xml-parsed nested list but I can't work out the syntax. Essentially I'm trying isolate all the list between the first and last horizontal rules. I have made a kludge which seems to work, but I would like to know how to do this correctly.



Here is what I have come up with so far:
;Try to open the file given in the main args
(if (not (set 'myxml (read-file (main-args -1))))
((println (rest (sys-error)))(exit 1)))

;Set the flags so that the XML parser doesn't return "Element" "CType", etc.
(xml-type-tags nil nil nil nil)

;Hopefully parse the text into an s-expression list. The numbers at the end of xml-parse are the parser settings.
(if (not (set 'myxml (xml-parse myxml (+ 1 2 8))))
((println (first (xml-error))) (exit 1)))

;Isolate the <body>
(set 'myxml (myxml 0 2))

;Discard everything before the first <HR>
(set 'myxml (slice myxml (inc (first (ref 'HR myxml)))))

;Discard everything after the remaining <HR>
(set 'myxml (slice myxml 0 (first (ref 'HR myxml))))

;Output to console to be piped or redirected
(println myxml)

(exit)


Any help, or direction to help, would be appreciated.



-Peter Weston