[Prev][Next][Index][Thread]

Re: Some inquiries about Dylan tutorials and documentation



Scott Ribe <sribe@miqs.com> wrote:
> Neel Krishnaswami wrote:
> 
> > I don't think this is the most efficient possible implementation of
> > expand-template, though, since the time it takes is linear in the
> > number of entries in symbol-table -- can anyone think of a better one
> > off-hand, including a suggestion to use xformat?
> 
> I went through this in a different (nasty 4GL non-oop lacking even basic
> data structures) language and eventually dealt with it by "chunkifying"
> all templates once at startup. That way expansion became, essentially,
> linear in the number of variables in each template. (I say essentially
> because I implemented conditionals so that the branch not taken does not
> add to expansion time, and loops where of course each iteration adds to
> expansion time.)
>
> > Plus when your template language grows into a full programming
> > language (and this always happens -- witness PHP), you'll be in a
> > better position to write an interpreter with comprehensible
> > behavior.
> 
> Might as well plan from the start on having it happen. In my case I
> think it took me well under an hour to realize that I was going to need
> a dinky language rather than just text substitutions. (It's pretty
> obvious. You need iteration to display a selection from a database. And
> you need branching. And you need formatting options.)

This post just reminded me of a short little article I read a while
back. It's "Functional Unparsing" by Olivier Danvy, and is basically a
short paper on how to write a "format"-like function in ML. It's
actually even niftier than that, since it allows extensions to the set
of format options.

You can find it at (I broke the URL into 2 lines to keep my newreader
happy):

http://www.brics.dk/RS/98/Ref/
  BRICS-RS-98-Ref/BRICS-RS-98-Ref.html#BRICS-RS-98-12

(His homepage is at http://www.brics.dk/~danvy/, and is full of good
stuff.) Also of interest might be the Cayenne language report, which
has a printf-like function as an example of using dependent types, and
is in a more Dylan-ic style.


Neel



References: