Linguistic abstraction |
In Chapter 22 we discussed how to establish languages, especially in Lisp.
In this chapter we will discuss how to combine two (or more) existing languages. More specifically, we will look at ways to embed one language into another.
23.1 Embedded languages | 23.3 Course home page embedding in Scheme |
23.2 Examples of language embedding in HTML |
23.1. Embedded languages
Contents Up Previous Next Slide Subject index Program index Exercise index
We start with a definition of language embedding.
|
As a possible practical organization of the embedding of a new language into another language, the interpreter of the new language N is made available as a function in the existing language E.
In the web domain there are many examples of language embeddings. Below we mention some of them.
|
23.2. Examples of language embedding in HTML
Contents Up Previous Next Slide Subject index Program index Exercise index
In this section we will illustrate some examples of language embedding from the web domain. More specifically, we will see how fragments in various programming languages can be embedded into HTML. Such language embedding is widely used at the server side of the World Wide Web.
Concrete illustrations of JSP, ASP, and BRL documents |
The ASP and JSP examples are available via the slide and the annotated slide view of this material. (The examples are too large to warrant inclusion at this location of the material). Please take a look at the web material for the details.
The BRL [Lewis00] example is included here, because it is relatively small. In some sense it also covers the essence of the two others. We see Scheme fragments (emphasized with red color) within a conventional HTML document. When the web document is delivered by the server, the program fragments are executed. The functional results of the program execution become part of the web document. In a nutshell, this is a very common way to deal with dynamic web contents.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <html> <head> [ (inputs word) ; HTML input. Will be null if no such input. (define newword (if (null? word) "something" word)) ] <title>Backwards</title> </head> <body> <form> Type a word: <input name="word"> <input type="Submit"> </form> <p>[newword] spelled backwards is [(list->string (reverse (string->list newword)))] </p> <p>This message brought to you by [(cgi SERVER_NAME)] as a public service.</p> </body> </html> | |||
|
23.3. Course home page embedding in Scheme
Contents Up Previous Next Slide Subject index Program index Exercise index
We will illustrate embedded languages with an embedded list-based language in Scheme. This is done as a direct continuation of the course home page example from Section 22.4.
The simple course home page language is an embedded list language in Scheme |
In Program 23.2 we see the course home page expression, emphasized with red color. This is a list structure, formed in its own language: A simple course home page language. The language is list-based, and the non-constant parst of the language are brought in via quasiquotation (also known as backquoting). Thus, the course home page subdocument makes use of variables and expressions from the surrounding Scheme program. Notice, however, that a special interpreter is needed to process the backquoted course-home-page expression.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | (let ((ttl "Programming Paradigms") (max 5) (current 3) ) `(course-home-page (name ,ttl) (number-of-lectures ,max) ,(cons 'lecture-names (map downcase-string (list "intr" "scheme" "HIGHER-ORDER-FN" "eval-order" "lisp-languages"))) (current-lecture ,current) (links "schemers.org" "http://www.schemers.org/" "LAML" "http://www.cs.auc.dk/~normark/laml/" "Haskell" "http://haskell.org/" ) ) ) | |||
|
23.4. References
[Lewis00] | Bruce R. Lewis, "BRL---A database-oriented language to embed in HTML and other markup", October 2000. |