Thu, Mar 29, 2007, 6:01am F-Script Web Test Working
Programming » F-Script
(Last updated: Fri, Mar 30, 2007, 4:30pm)
was able to get a full test going of using F-Script as a scripting language to serve up a webpage. Heck it even validates properly (if only tentatively, though I'm not sure why not entirely). It uses a very primitive template file and just makes a simple table of x vs x to the 2.5th power.

Ever since Andrew Weinrich added his fscript command-line tool, it's been a lot more fun to play with applications of F-Script. I added a couple of lines to my Apache config file and am able to perform this simple CGI test. Andrew kindly clued me in to the "out" object, which pipes to standard out (likewise, there's "in" and "err").

You can view the page here: test. I'm sure the code can be improved, and I'm still deciding on the right indentation style I want to use in my F-Scripts, but fairly happy with how quickly and cleanly this could be mocked up. The page itself shows both its own code and the code of the template file. It shows off a simple example of a couple of blocks, and some other syntactical trickery. The whole thing, idea to what you see, took about 2 hours.

(If anyone is actually reading the code, I had to use the trick of writing 'TEMP'++'LATE' instead of 'TEMPLATE', otherwise the regex would greedily find these patterns in its own code.)

Having a good night sleep now, I made a second attempt at cleaning up the look and structure of the code and posted it here: test2. Similar, but I think conceptually more elegant.

Update 3/29: As I'm completely unable to leave well-enough alone, I produced test3. I ended up abstracting the file grabbing operation, producing better code (intent of code more easily read + reused and less error-prone). I also didn't need to align the inString: methods at the end, but it makes the nesting idea more transparent. Lastly, the row block was cleaned up a bit, and the CSS improved. I dare say this is good looking code (or I need to get out of the house a lot more -- probably both).

Update 3/30: As if you didn't see this coming, I've made one better variation, after actually reading some of the new methods provided by the fscript runtime, giving the most succinct and readable code so far: test4.

Of course, any suggestions about how to improve this code would be appreciated.

  • Mirko Matt (Thu, December 13th, 2007, 2:15am UTC)
    Is there any progress in developing this project? It seems very interesting and I would like to see it in action.

  • Jeff (Thu, December 13th, 2007, 3:52am UTC)
    Mirko: Yes! I've actually made great strides since these tests were done, and now even use F-Script in several places in this blog. It's one of the (now several) languages that the templating system I've been developing uses. I hope to release it generally in some way sometime early in '08.

    As a more recent example, F-Script runs this site's Chicago Recycling page.

    I'll try to post more about this in '08. Let me know if there's something specific you're interested in discussing too.

Leave a comment