RE: Request for help on functional programming!

Subject: RE: Request for help on functional programming!
From: Avi Kivity <Avi@xxxxxxxxxxxxx>
Date: Tue, 2 Mar 1999 20:39:17 +0200
On Tuesday, March 02, 1999 18:30, J-P Theberge [SMTP:yesod@xxxxxxx] wrote:
> Hi,
> 
> I agree with theory of functional programming, but when it's time
> for me to do actual codes (mostly in scheme), I generally use a lot
> of
> imperative short-cut (all thoses things ending in !)
> 
> So I'll appreciate if somebody can give me some hints on how to do 
> the following (with or without using the -2 extension to jade):

Let's try without.

> 
> I have to completely redesign a web site (http://www.admtl.com).
> I've decided to code all the pages in XML then convert it to HTML 
> with jade.  
> 
> My problem is here: 
> http://www.admtl.com/dorval/yul-sect-3/cies-aeriennes-e.html
> 
> I want the xml document to be very simple. something like:
> 

You need a root element container, let's assume

<airlinedb>

>  <airline name="Aeroflot"
>        code="SU"
>        regphone="(514) 288-2125"/>
> 
>  <airline 
>        name="Air Alliance"
>        href="http://www.aircanada.ca/french/ac_world/";
>        code="3J"
>        regphone="(514) 393-3333"
>        tfphone="1-800-361-8620"/>
> 
> e.t.c...
> 

</airlinedb>

> And I want the style sheet to handle things like the navigation bar
> at the top and the capital letters that mark the sub-section.
> 
> My (probably bad) idea was to parse the document without actually
> outputing nothing but storing (using set!) all the info in a huge
> alist, then create the page and output it.
> 
> Do you have better ideas?
> 

You output contains:

1. A static section (nav bar)
2. A horizontal list of airlines; only the first airline of each letter is
displayed
3. Another static section (list header)
4. A vertical list of airlines; the first airline of each letter has
specialized formatting (an additional row)
5. Yet another static section (footer)

Of course you want the elements of the first list linked to the second.

This translates nicely into dsssl:

(root (make entity ... (process-children))) ;create the output file

(element airlinedb
	(make element
		gi: "html"
		(header-section)
		(with-mode horizontal (process-children))
            (separator-section)
		(with-mode vertical (process-children))
		(footer-section)
      )
)

The two modes format the same data in two different ways:

(mode vertical
	(element airline
		(sosofo-append
			(if (first-of-its-letter?)
				(letter-row-header)
				(empty-sosofo)
			)
			(format-airline)
		)
	)
)

(mode horizontal
	(element airline
		(if (first-of-its-letter?)
			(sosofo-append
	
(format-intervening-letters-from-previous-node-as-dead-text)
	
(format-airline-as-letter-with-link-to-airline)
			)
			(empty-sosofo) ;not lucky enough
		)
	)
)

(define (first-of-its-letter?)
	(or
		(first-sibling?)  ;trivial
		(string-ci<? 
			(first-letter-of (ipreced (current-node)))
			(first-letter-of (current-node))
		)
	)
)

etc.

Hope this helps,
- Avi
---
"The only words which have meaning are the last ones spoken"


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread