2.1 Getting started with Scheme and LAML *
The purpose of this exercises is learn the most important practical details of using a Scheme system on Unix. In case you insist to use Windows we will assume that you install the necessary software in your spare time. There is no time available to do that during the course exercises. Further details on installation of Scheme and LAML on Windows.
You will have to choose between DrScheme and MzScheme.
DrScheme is a user friendly environment for creating and running Scheme programs, with lots of menus and lots of help. However, it is somewhat awkward to use DrScheme with LAML. Only use DrScheme in this course if you cannot use Emacs, or if you are afraid of textually, command based tools. Follow this link for further details.
MzScheme is the underlying engine of DrScheme. MzScheme is a simple read-eval-print loop, which let you enter an expression, evaluate and print the result. MzScheme is not very good for debugging and error tracing. MzScheme works well together with Emacs, and there is a nice connection between MzScheme and LAML. MzScheme used with Emacs is preferred on this course. Please go through the following steps:
(html (head (title "A title")) (body (p "A body")))
2.2 Construction of symbolic expressions *
Experiment with h being the empty list. Try to use a proper list function, such as length, on your structures.
2.3 Every second element of a list **
Write a function, every-second-element, that returns every second element of a list. As examples
(every-second-element '(a b c)) => (a c)
(every-second-element '(a b c d)) => (a c)
It is recommended that you formulate a recursive solution. Be sure to consider the basis case(s) carefully.
It is often worthwhile to go for a more general solution than actually needed. Sometimes, in fact, the general solution is simpler than one of the more specialized solutions. Discuss possible generalizations of every-second-element, and implement the one you find most appropriate.
2.4 Creation of association lists *
Program a function pair-up that constructs an association list from a list of keys and a list of values. As an example
(pair-up '(a b c) (list 1 2 3))
((a . 1) (b . 2) (c . 3))
Think of a reasonable solution in case the length of the key list is different from the length of the value list.
2.5 Association list and property lists *
Association lists have been introduced at this page. An association list is a list of keyword-value pairs (a list of cons cells).
Property lists are closely related to association lists. A property list is a 'flat list' of even length with alternating keys and values.
The property list corresponding to the following association list
((a . 1) (b . 2) (c . 3))
(a 1 b 2 c 3)
Program a function that converts an association list to a property list. Next, program the function that converts a property list to an association list.
2.6 Parameter passing in Scheme *
Familiarize yourself with the parameter passing rules of Scheme by trying out the following calls:
((lambda (x y z) (list x y z)) 1 2 3)
((lambda (x y z) (list x y z)) 1 2)
((lambda (x y z) (list x y z)) 1 2 3 4)
((lambda (x y z . r) (list x y z r)) 1 2 3)
((lambda (x y z . r) (list x y z r)) 1 2)
((lambda (x y z . r) (list x y z r)) 1 2 3 4)
((lambda r r) 1 2 3)
((lambda r r) 1 2)
((lambda r r) 1 2 3 4)
Be sure that you can explain all the results
2.7 Colors in HTML **
The symbols r, s, t, u, v, and w are all hexadecimal numbers between 0 and f (15). rs is in that way the hexadecimal representation for red, tu is the code for green, and vw is the code for blue.
As an example, the text string
represents white and
In Scheme we wish to represent a color as the list
(color r g b)
where color is a symbol, r is number between 0 and 255 which represents the amount of red, and g and b in a similar way the amount of green and blue in the color.
Write a Scheme function that transforms a Scheme color to a HTML color string.
It is a good training to program the function that converts decimal numbers to hexa decimal numbers. I suggest that you do that - I did it in fact in my solution! If you want to make life a little easier, the Scheme function (number->string n radix) is helpful (pass radix 16 as second parameter).
2.8 Letter case conversion **
Write functions capitalize-a-string, upcase-a-string, downcase-a-string for these purposes.
As examples of their use, please study the following:
(capitalize-a-string "monkey") => "Monkey"
(upcase-a-string "monkey") => "MONKEY"
(downcase-a-string "MONkey") => "monkey"
Hint: I suggest that you program the necessary functions yourself. Convert the string to a list of ASCII codes, do the necessary transformations on this list, and convert the list of modified ASCII codes back to a string. The Scheme functions list->string and string->list are useful.
Hint: If you want to make life a little easier (and learn less from this exercise...) you can use the Scheme functions char-upcase and char-downcase, which work on characters. But these functions do maybe not work on the Danish letters, so you you probably need some patches.
Generated: Tuesday July 2, 2013, 09:14:46