This got me thinking about how this relates to all the website stuff 
I've been doing recently. Django, the web framework I've been using, has 
a pretty nice templating system. It breaks up the inputs in a series of 
nodes, and is able to quickly construct dynamic documents without having 
to do standard string substitution. Here's a little example I'll steal 
from GvR:

http://www.artima.com/weblogs/viewpost.jsp?thread=146606

Basically, you use it like this:

 >>> t = Template("<h1>Hello {{ first_name }}, {{ last_name }}</h1>")
 >>> print t.render({"first_name": "Erick", "last_name": "Tryzelaar"})
<h1>Hello Erick Tryzelaar</h1>
 >>> print t.render({"first_name": "John", "last_name": "Skaller"})
<h1>Hello John Skaller</h1>

How could we do this simply in felix, especially the dictionary 
substitution? The parsing of the string is easy, but how could we 
substitute names? I suppose we could do a associative list:

 >>> val t = Template "<h1>Hello {{ first_name }}, {{ last_name }}</h1>";
 >>> print$ render t$ list(("first_name", "Erick"), ("last_name", 
"Tryzelaar"))
 >>> print$ render t$ list(("first_name", "John"), ("last_name", "Skaller"))

But it seems a little ugly. You have to know that in this particular 
case the list of tuples is an associative list, and not some other concept.

We could use stl's map, but that doesn't have a clean way of construction.

What do you all think?

-e

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to