In his excellent blog on the Y-combinator, Matt Might - a professor at my alma mater, the University of Utah - uses a technique for placing executable Javascript code in the flow of his document.
Right now I am pasting his code into the html editor of my Google blogger to see if I can reproduce the
Open Double Quote
The following example expresses the factorial function without using recursion:
[result1]
Take a close look at the definition of Y. It uses only three kinds of expression: anonymous functions, variable reference and function application.
Close Double Quote
Back to my words: Note that even though this is a blog, the html is still functional and the Javascript program executes when the "Evaluate" button is pressed. So handy for making those subtle programming points!
If you right click this page and choose, "View Source", You can see the embedding of the code between lines 456 and 524. A short preamble and "postamble" are all that are required. Thanks Matt!
Footnotes:
Attempts to paste commented html tags were futile as they were evaluated. Attempts to color the code red didn't work either.
No comments:
Post a Comment