You should be automatically redirected . If not, visit
and update your bookmarks.


Follow-up: list indexing

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:

(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)
        (print " " e " ")
        (nth-set -1 outline (+ 1 (outline -1))))
      (process-xml e) 
(xml-type-tags nil nil nil nil)
(set 'sxml-data        
      (get-url {})        
      (+ 1 2 4 8 16)))
(set 'outline '(0))
(println "0 (")
(process-xml sxml-data)
(println ")")

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

0 (
0.0 ( rss 
0.1.0 ( @ ( version  0.92 ))
0.2.0 ( channel ( docs ) ( title  newLISP Fan Club ) ( link ) ( description  Friends and Fans of newLISP) ( managingEditor ) ( webMaster ) ( lastBuildDate  Wed, 19 Jul 2006 13:44:46 GMT ) ( item ( title  newLISP and/or Whatever Else :: RE: Spam posts on this forum ) ( link )

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?


At 20:38, Anonymous Noah said...

Hi, newLISPER!

0 (
0.0 ( rss
0.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 (rss
0.1.0 (@ (version 0.92))
;-> is correct

0 (
0.0 rss
0.1 (
0.1.0 @
0.1.1 ( version 0.92

1 (
1.0 html
1.1 (
1.1.0 head
1.1.1 ( title ( Imaginary html sxml under the RSS sxml

;-> not correct

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


At 10:02, Blogger newlisper said...

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)

At 06:15, Anonymous m i c h a e l said...

> 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 l

P.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 :-)


Post a Comment

Links to this post:

Create a Link

<< Home