Theme index -- Keyboard shortcut: 'u'  Previous theme in this lecture -- Keyboard shortcut: 'p'  Next slide in this lecture -- Keyboard shortcut: 'n'Linguistic abstraction
24.  Language Mirroring

In this chapter we will discuss language mirroring, in part as a contrast to language embedding from Chapter 23.

24.1 Mirrored Languages24.4 Course home pages ala Course Plan
24.2 Course home page mirroring in Scheme (1)24.5 Embedding versus mirroring
24.3 Course home page mirroring in Scheme (2)
 

24.1.  Mirrored Languages
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

Let us start with a definition of a mirrored language.

A new language N is a mirrored language in an existing language E if an expression in N in a systematic way can be represented as an expression in E.

  • LAML provides mirrors of a number of XML languages in Scheme:

    • HTML 4.01 and XHTML1.0

    • SVG

    • A number educational languages, such as LENO and the Course Home Page language (Course Plan)

 

24.2.  Course home page mirroring in Scheme (1)
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

Let us now illustrate how to mirror the simple course home page language in Scheme. The mirror which we deal with is a mirror of an XML language in LAML. Recall that we programmed the course home page document with simple functional abstractions in Section 22.4 and that we embedded the course home page language in Scheme in Section 23.3. Thus, the treatment below is actually our third attempt to accommodate the simple course home page abstractions in Scheme.

The simple course home page is mirrored as an XML language in Scheme and LAML

We will start by giving an overview of the practical process that leads to the creation of mirror of some XML language in Scheme and LAML.

  • Steps involved in the mirroring process:

    • Write an XML DTD of the language

    • Parse the XML DTD to a Scheme data structure

    • Synthesize the mirror of the language by the XML-in-LAML mirror generation tool

    • When using the course home page language, load the mirror as a Scheme library

It is fairly straightforward to write an XML DTD for a new 'little language', although the SGML inherited language may seem a little strange at first sight. Take a look at Program 24.1.

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
28
29
30
31
32
33
34
35
<!ENTITY % Number "CDATA">
    <!-- one or more digits -->

<!ENTITY % URI "CDATA">
    <!-- a Uniform Resource Identifier, see [RFC2396] -->

<!ELEMENT course-home-page
  (lecture-names, links)
>

<!ATTLIST course-home-page
  name                 CDATA          "#REQUIRED"
  number-of-lectures   %Number;        "#REQUIRED"
  current-lecture      %Number;        "#IMPLIED"
>

<!ELEMENT lecture-names
  (lecture-name+)
>

<!ELEMENT lecture-name
  (#PCDATA)
>

<!ELEMENT links
  (link*)
>

<!ELEMENT link
  (#PCDATA)
>

<!ATTLIST link
  href               %URI;             "#REQUIRED"
>
Program 24.1    The course home page DTD.

The XML DTD can be parsed with the LAML DTD parser. We usually make a simple LAML script for such purposes, as shown in Program 24.2.

1
2
3
4
(load (string-append laml-dir "laml.scm"))
(load (string-append laml-dir "tools/dtd-parser/dtd-parser-4.scm"))

(parse-dtd "course-home-page")
Program 24.2    The script that parses the DTD.

The DTD parser creates a Lisp list structure representation of the DTD. This list structure is passed as input to the LAML mirror generator. The LAML script in Program 24.3 shows how the mirror generator is activated.

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
28
29
(load (string-append laml-dir "laml.scm"))
(laml-tool-load "xml-in-laml/xml-in-laml.scm")

; ------------------------------------------------------------------------
; Tool parameters

; The name of the language for which we create a mirror
(define mirror-name "course-homepage")

; The full path to the parsed DTD:
(define parsed-dtd-path
  (in-startup-directory "course-home-page.lsp"))

; The full path of the mirror target directory
(define mirror-target-dir (string-append (startup-directory) "../mirror/"))

(define action-elements '(course-home-page))

(define default-xml-represent-white-space "#f")

(define auto-lib-loading "#t")


; End tool parameters
; -------------------------------------------------------------------------

(let ((mirror-destination-file
        (string-append mirror-target-dir mirror-name "-mirror" ".scm")))
  (generate-mirror parsed-dtd-path mirror-destination-file mirror-name))
Program 24.3    The script that generates the mirror.

The output of the mirror generator is a Scheme source file, which represents the mirror of the course home page language from Program 24.1. As most other automatically generated source files, the mirror library of the demonstrational course home language is not easy to read. We have therefore not included it in this version of the material. You can access it from the web version via the slide view.

 

24.3.  Course home page mirroring in Scheme (2)
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

In this section we will se how to use the mirror of the course home page language, which we created in Section 24.2.

A sample course home page document that uses the XML-in-LAML course home page mirror functions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(load (string-append laml-dir "laml.scm"))       
(define (course-home-page! doc) 'nothing)
(load "../mirror/course-homepage-mirror.scm")

(let ((ttl "Programming Paradigms")
      (max 5)
      (current 3))

 (course-home-page  'name ttl 'number-of-lectures "5"
                   'current-lecture "3"
   (lecture-names
     (map 
       (compose lecture-name  downcase-string)  
       (list "intr" "scheme" "HIGHER-ORDER-FN" 
             "eval-order" "lisp-languages")))
   (links
     (link  "schemers.org" 'href "http://www.schemers.org/")
     (link  "LAML" 'href "http://www.cs.auc.dk/~normark/laml/")
     (link  "Haskell" 'href "http://haskell.org/")
   )))
Program 24.4    A sample course home page that uses the course home page mirror functions.

The first three lines in Program 24.4 loads the laml library and the mirror library. Before loading the mirror library we need to define an action procedure of the top-level element, course-home-page. Notice that this element was announced as an action element in Program 24.3. As an action element, the action procedure takes over the rest of the transformation process, typically to HTML. In this demo setup, the action procedure is empty.

The mirror function applications in the course-home-page expression are all emphasized in red. Notice the smooth integration of the course home page mirror functions and other Scheme functions. You should in particular compare the way mapping is done with the similar mapping in Program 23.2.

Further processing and transformation is done by the action procedure course-home-page!

 

24.4.  Course home pages ala Course Plan
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

A real life course home page mirror in Scheme - The Course Plan system

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
(load (string-append laml-dir "laml.scm"))       
(laml-style "xml-in-laml/course-plan/course-plan")

(course-plan

 (course-intro 
   "This is the intro to the example course.")

 (course-info
   'last-lecture-number "3"
   'language-preference "danish"
   'color-scheme "blue-grey"
   'course-title "The example course"
   'brief-course-title "TEC"
   'course-semester "The last semester"
   'brief-course-semester "LAST"
   'teacher-name "Kurt Nørmark"
   'course-url-prefix "http://www.cs.auc.dk/~normark/courses/"
   'author-home-url "http://www.cs.auc.dk/~normark/"
   'make-overview-pages "true"
;   'calendar-start-year "2002"
;   'calendar-start-month "11"
;   'calendar-number-of-months "6"


   (time-list

     (time 'year "2002" 'month "10" 'day "1" 'hour "8" 'minute "15")
     (time 'year "2002" 'month "11" 'day "11" 'hour "8" 'minute "15")
     (time 'year "2002" 'month "12" 'day "31" 'hour "8" 'minute "15")
     (time 'year "2003" 'month "1" 'day "3" 'hour "8" 'minute "15")
     (time 'year "2003" 'month "2" 'day "4" 'hour "8" 'minute "15")

   )

   (lecture-list

     (lecture 
       'lecture-id "l1" 'subject-id "s1" 
       'exercise-start "120" 'exercise-length "105"
       'plenum-start "0"   'plenum-length "105"
       'room "room"
;       (time 'year "2002" 'month "10" 'day "22" 'hour "8" 'minute "15" 'second "0")
     )
     (lecture 
       'lecture-id "l2" 'subject-id "s2" 
       'exercise-start "120" 'exercise-length "105"
       'plenum-start "0"   'plenum-length "105"
       'room "room"
     )
     (lecture 
       'lecture-id "l3" 'subject-id "s3" 
       'exercise-start "120" 'exercise-length "105"
       'plenum-start "0"   'plenum-length "105"
       'room "room"
     )
     (lecture 
       'lecture-id "l4" 'subject-id "s3" 
       'exercise-start "120" 'exercise-length "105"
       'plenum-start "0"   'plenum-length "105"
       'room "room"
     )
     (lecture 
       'lecture-id "l5" 'subject-id "s3" 
       'exercise-start "120" 'exercise-length "105"
       'plenum-start "0"   'plenum-length "105"
       'room "room"
     )
     (lecture 
       'lecture-id "l6" 'subject-id "s3" 
       'exercise-start "120" 'exercise-length "105"
       'plenum-start "0"   'plenum-length "105"
       'room "room"
     )

   )


   (subject-list
    (subject 
     'id "s1"
     'title "Subject 1"
     (description "The first subject"))

    (subject 
     'id "s2"
     'title "Subject 2"
     (description "The second subject"))

    (subject 
     'id "s3"
     'title "Subject 3"
     (description "The third subject"))
   )


   (index-links
     (link-entry 'href "http://www.cs.auc.dk/~normark/laml/" 'target "new" "LAML - in new window")
     (link-entry 'href "http://www.w3c.org" 'target "top" "W3C - in top frame")
     (link-entry 'href "http://www.cs.auc.dk/~normark/scheme/" 'target "main" "LAML software - main frame")
   )
  
   (bottom-links
     (link-entry 'href "http://www.cs.auc.dk/~normark/" 'target "top" "Kurt Nørmark Home")
     (link-entry 'href "http://www.cs.auc.dk/" "CS at AAU")
   )

 )

 (lecture-plan-list

  (lecture-plan 'lecture-id "l1"
   (literature (div "Chapter one of 'Rof and Rif'."))
   (exercises 
      (div
       (ol (li "Exercise 1.1")
          (li "Exercise 2.1"))

      (p "More")

      )

   )
   (misc (div "Important stuff")))

  (lecture-plan 'lecture-id "l2"
   (literature (div "Chapter two of 'Rof and Rif'."))
   (exercises  (div "Exercise 1.2"))
   (misc (p "Important stuff")))

  (lecture-plan 'lecture-id "l3"
    (literature "Chapter three of 'Rof and Rif'.")
  )

 )

)
Program 24.5    A Course Plan XML-in-LAML document.

 

24.5.  Embedding versus mirroring
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

In this section we compare language embedding ala the example from Section 23.3 with language mirroring as discussed in this chapter.

How does a list-embedding of new language in Scheme compare to a mirroring of the language Scheme?

Embedding in Scheme

Mirroring in Scheme

New language fragments are represented as lists

New language fragments are represented as Scheme expressions

Many different interpretations can be provided for

The most typical transformation is 'built in', as obtained by evaluation of the Scheme expression

Processing requires a specialized interpreter

The (first level of) processing is done by the standard Scheme interpreter

Relatively awkward to combine with use of higher-order functions

Mixes well with higher-order functions

 

24.6.  References
[Transf]LAML transformation functions
http://www.cs.auc.dk/~normark/scheme/lib/xml-in-laml/man/xml-in-laml.html#SECTION18
[Course-plan-examples]The generated Course Plan page (web only)
http://www.cs.auc.dk/~normark/scheme/examples/course-plan-xml-in-laml/html/example.html

Generated: Tuesday July 2, 2013, 09:15:57
Theme index -- Keyboard shortcut: 'u'  Previous theme in this lecture -- Keyboard shortcut: 'p'  Next slide in this lecture -- Keyboard shortcut: 'n'