From: Navindra Umanee Date: 2005-07-17T00:34:36+09:00 Subject: Re: delaying string evaluation Eric Hodel wrote: > > I would like to partially expand a string and then further expand it > > later on when more information is available. I am currently using > > string interpolation with a reeval method suggested by Bill Kelly. > > is sprintf (aka %) unable to fulfill your requirements? I am aware that there are solutions such as these, but I keep finding the string interpolation solution to be the most attractive/elegant one as a general solution. > s = "#{expanded} %s" > s = s % delayed If there are multiple occurrences of delayed, you have to repeatedly apply it in the second line in proper order, and if you have any independent occurrence of % in the string, I'm not entirely sure how to escape it. This solution isn't very symmetric either. > I think the reeval thing is the wrong way to go about it. What do you have against reeval? I have been trying to convince myself there are better solutions, but after looking I keep coming back to it. It just seems more natural or at least it works as a general solution. > I find it much more useful to use a library that generates HTML > programatically You mean like the CGI.* stuff or Amrita? CGI.* stuff looks very painful and verbose to use, and Amrita, while it looks interesting in simple cases, gives me the feeling that I will have to use too many contortions to get it to work the way I want. I mean constructs like

in Amrita look brilliant. But then you get to stuff like Amrita2 which starts to look more ugly and as you get to complex conditional code generation it gets worse and worse. It just seems easier to "just do it the way I want" in Ruby instead of artificially constraining myself in Amrita, since I have the feeling I would have to resort to Ruby programming in addition to Amrita just to get the sort of effects I want anyway. It could well be I'm not giving Amrita its due. I have been considering re-implementing my stuff in it, but at the depressing prospect, I thought I'd try making the string interpolation template stuff more elegant (which it obviously isn't yet). > or from a template than to try fancy substitution tricks (unless its > really small). Eventually you end up with either a template language > or programatic HTML generation in the end. I agree that this is what I will end up with -- I'm just trying to get it to work in the most elegant way I can. What do you use? Cheers, Navin.