Some systems augment a programming language with special semantics that enable one to embed markup in the programming language. This strategy for generating dynamic pages is called markup-in-code and resorts under ProgrammingLanguageCentric strategies.

The markup-in-code strategy can best be explained by an example:

Quixote is an extension to the Python programming language. An example of a Quixote function can be seen in the following code excerpt (which returns the body of an HTML document):

   1 def foo [plain] ():
   2     '<body>'
   3     for word in ['these', 'words']:
   4         '<p>Word: %s</p>' % word
   5 
   6     '</body>'

A Quixote function always returns a string (even though no return value is explicitly specified). This return value is automatically computed as follows: at first the string is empty, but as each statement in the function is executed, its individual return value is converted to a string and appended to the return value of the function. Quixote is helped here by the fact that literal values in Python can be used as statements (with no side effects, but themselves as return value). Return values of None are ignored. (In Python, a return value of None denotes a void return value.)

Hence, text can be embedded in a programming language with the programming language used to govern the final text that will be returned. The example above will yield:

  '<body><p>Word: these</p><p>Word: words</p></body>'

MarkupInCode (last edited 2006-01-25 09:36:00 by IwanVosloo)