Exercises in this lecture  Go to the slide, where this exercise belongs -- Keyboard shortcut: 'u'  

Exercise 2
A color-text function


Write a Scheme markup function color-text of the following form:

  (color-text r g b . content-and-attributes)

The three first parameters are integers between 0 and 255. The tail parameter list text-and-attributes is arbitrary XML contents and attributes.

Examples of calls:

  (color-text 255 0 0 "This is some nice text")
  (color-text 255 0 0 "This is some" (em "nice") "text")
  (color-text 255 0 0 'class "my-class" "This is some" (em "nice") "text" _ ".")

Alternatively you may go for a form:

  (color-text 'red r 'green g 'blue b content-and-attributes)

such as

  (color-text 'red 255 'green 0 'blue 0 "This is some nice text")

Implement the desired function in terms of an HTML span element. Use the function xml-in-laml-positional-abstraction to implement the mixed positional and LAML parameter passing. The function rgb-color-encoding is also useful.


Solution