(archive 'newLISPer)

July 19, 2006

Follow-up: list indexing

Filed under: newLISP — newlisper @ 15:09
Tags:

>

In the previous post I managed to confuse myself and at least one reader (Hi Noah!) with my attempts to find my way around an SXML list structure. This blog is supposed to say somewhere that I’m learning newLISP, and I’m currently in the lower slopes of the foothills of the lowlands, but I notice that it doesn’t seem to be saying that anymore. Perhaps (new (newLISPer)) would be a suitable edit.

Here’s a revision of the script that outputs an SXML list, but using the ‘military’ numbering system that Noah used in one of his comments. Here’s the script:

#!/usr/bin/newlisp
(define (militarize-list l)
  (trim (replace " " (string l) ".") "(" ")"))
(define (start-list)
  (push 0 outline -1)
  (print "\n"  (militarize-list outline) " (" ))
(define (close-list)
  (println ")")
  (pop outline -1)
  (nth-set -1 outline (+ 1 (outline -1))))
(define (process-xml l)
  (dolist (e l)
    (unless (list? e)
      (begin
        (print " " e " ")
        (nth-set -1 outline (+ 1 (outline -1))))
     (begin
      (start-list)
      (process-xml e)
      (close-list)))))
(xml-type-tags nil nil nil nil)
(set 'sxml-data
  (xml-parse
      (get-url {http://www.alh.net/newlisp/phpbb/rss.php})
      (+ 1 2 4 8 16)))
(set 'outline '(0))
(println "0 (")
(process-xml sxml-data)
(println ")")
(exit)

and here’s the (slightly tidied up) output:

0 (
0.0 ( rss
0.1.0 ( @
0.1.1.0 ( version  0.92 ))
0.2.0 ( channel
0.2.1.0 ( docs  http://backend.userland.com/rss092 )
0.2.2.0 ( title  newLISP Fan Club )
0.2.3.0 ( link  http://www.alh.net/newlisp/phpbb/ )
0.2.4.0 ( description  Friends and Fans of newLISP)
0.2.5.0 ( managingEditor  dooright101@yahoo.com )
0.2.6.0 ( webMaster  dooright101@yahoo.com )
0.2.7.0 ( lastBuildDate  Wed, 19 Jul 2006 13:44:46 GMT )
0.2.8.0 ( item
0.2.8.1.0 ( title  newLISP and/or Whatever Else :: RE: Spam posts on this forum )
0.2.8.2.0 ( link  http://www.alh.net/newlisp/phpbb/viewtopic.php?p=6793#6793 )

I played with this script until it showed the same answers as the ref function does. If you can see where I’m going wrong, let me know!

By the way, I called this style of numbering military. Does it have a proper name, similar to the Harvard and other outlining styles? Westpoint, perhaps?

Advertisements

3 Comments »

  1. >Hi, newLISPER!0 (0.0 ( rss 0.1.0 ( @ 0.1.1.0 ( version 0.92 ))The leftmost 0 looks like an index for one of several top-level lists, like you see in a newLISP script. But thanks to your help,here’s what this newer newLISPer is thinking. 0 (0.0 (rss0.1.0 (@0.1.1.0 (version 0.92));-> is correct0 (0.0 rss0.1 (0.1.0 @0.1.1 (0.1.1.0 version 0.921 (1.0 html1.1 (1.1.0 head1.1.1 (1.1.1.0 title1.1.1.1 (1.1.1.1.0 Imaginary html sxml under the RSS sxml;-> not correctThe indexing scheme applies to a single list. The single list may contain any number of sublists. The top level list doesn’t have a number, but does have an explicit open parenthesis. The first element of the top level list is zero. So the leftmost 0 in the outline refers to the list:(rss …)which happens to be the first and only element of the top-level list.And this makes sense! Lutz invented the index numbering to manipulate elements of a list. push and pop only need information about one list to know where to act on a spot in that list. An indexing system that indexes multiple independent lists provides more information than push and pop can use to insert or remove an item from a single list. If you (the general “you”) want to manipulate multiple independent lists, you can explicitly enclose them in parentheses, and then newLISP can apply it’s indexing system to the new single list.According to one on-line author, The outline format is called Business format. It’s my prefered outlining format when I take notes. It’s easier on me than the I,A,a… style.-Noah

    Comment by Noah — July 19, 2006 @ 19:38 | Reply

  2. >I think you’re right. So you can have a single list that contains a number of SXML sublists. For example, item 0 of this big list might be the RSS feed, and item 1 could be the equivalent Atom version. You can use ref to find the lastBuildDate of the RSS list and the updated key of the Atom list.(ref ‘lastBuildDate biglist);-> (0 2 7 0)(ref ‘updated biglist);-> (1 0 6 0)

    Comment by newlisper — July 20, 2006 @ 09:02 | Reply

  3. >> I called this style of numbering military. Does it have a proper name?Wikipedia calls that style “decimal outline.” Melissa and I both thought it was called “scientific numbering.” Decimal outline is probably easier to remember, anyway ;-)m i c h a e lP.S. I haven’t had time to carefully read this or your last post yet (sorry), as I’m a little on the drowning side :-)

    Comment by m i c h a e l — July 21, 2006 @ 05:15 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: