An Emacs Programming Challenge

In Converting S-Expressions To XML In Emacs, I showed how to take a log record expressed as Lisp and turn it into the equivalent XML. In More Fun With Log Files Stored As Lisp, I showed how to take that same log record and make it executable so that it transformed one of the fields when the record was executed.

Here is a challenge for Elisp programmers: take the record

(record
  (date "2005-02-21T18:57:39")
  (millis 1109041059800)
  (sequence 1)
  (logger nil)
  (level 'SEVERE)
  (class "java.util.logging.LogManager$RootLogger")
  (method 'log)
  (thread 10)
  (emessage "A very very bad thing has happened!")
  (exception
    (emessage "java.lang.Exception")
    (frame
      (class "logtest")
      (method 'main)
      (line 30))))

and turn it into XML like this:

<record>
<date>2005-02-21T18:57:39</date>
<millis>1109041059800</millis>
<sequence>1</sequence>
<logger></logger>
<level>SEVERE</level>
<class>java.util.logging.LogManager$RootLogger</class>
<method>log</method>
<thread>10</thread>
<emessage>A very very bad thing has happened!</emessage>
<exception>
<emessage>java.lang.Exception</emessage>
<frame>
<class>logtest</class>
<method>main</method>
<line>30</line></frame></exception></record>

Do this by making the Lisp record executable so that it transforms itself into the XML when executed. Your XML doesn't have to be formatted exactly like mine and it's sufficient to have it print out in the echo area or the *Messages* buffer.

I'll give my solution in a few days so that you have time to work on it. If you get stuck, the wrap-up post has some techniques that may help.

This entry was posted in Programming and tagged , . Bookmark the permalink.

2 Responses to An Emacs Programming Challenge

  1. I think I did not write it the way you wanted, but here's mine

    (defun xmlizer (l)
    (cond ((null l) "")
    ((listp l)
    (concat ""
    (loop for x in (cdr l) concat (xmlizer x))
    ""))
    ((symbolp l) (symbol-name l))
    ((stringp l) l)
    ((numberp l) (number-to-string l))))

Comments are closed.