On this page:
Making Languages
Code Review
The Morse Code Language
Code Review

12 Modules, Syntax, Languages

home work!

Purpose The purpose of this lab is to design a simple Racket DSL.

We will also run a Gobbler AI competition, which will partly determine the grade on Week 14 Set a.

Textbook references None


5 minutes

This lab requires two basic setup steps to accommodate all existing platforms uniformly:

  1. Create a folder named racket-says-hello-world on your computer.

  2. Download make-package.rkt into this newly created folder.

  3. Open the file and run the program. This action with install the folder as a package in the Racket world.

  4. Download main.rkt into this same folder.

  5. Open the file in DrRacket and take a look.

These steps add an extremely simple language to Racket’s large repertoire of programming languages.

It is time to use this language now:
  1. Create another folder. In principle it doesn’t matter where you create this folder but you may wish to place it a parallel position to the racket-says-hello-world folder from above.

  2. Download test.rkt and place it in this folder.

  3. Open this file in the same DrRacket that is already open. Take a look. Notice how DrRacket agrees that the racket-says-hello-world language exist by painting the first line black. If it is red, call a TA or tutor for help. Now run the program.

Right now you should have (at least) two tabs open in DrRacket: main.rkt and test.rkt.

Making Languages

10 minutes

Run the test program in Racket. What you see is that Racket accepts defines without ado, and when it encounters an expression, it displays its value. The new language does not display the value. It doesn’t even seem to evaluate it, but that’s wrong.

Exercise 1 Think of an expression that may force DrRacket to show that it does evaluate expressions in this new language.

Now let’s look at the language. It re-defines Racket’s #%module-begin. How?

Exercise 2 What is the code that this new version generates for each expression in a module? Argue why this new language still evaluates all these expressions.

Take a second look at the re-definition of #%module-begin. It expands the given code into #%plain-module-begin.

Exercise 3 Conduct an experiment. Change the definition of my-module-begin so that generates Racket’s #%module-begin. Now how does test behave? Explain.

It’s time to become creative.

Exercise 4 Revise some other linguistic construct that you know from ISL+: if, cond, define, quote, or function application.

Code Review

5 minutes

The Teaching Assistants will pick two students to explain which construct they changed and how.

(define morse-table
   (list "A"  "*-")
   (list "N"  "-*")
   (list "1"  "*----")
   (list "."  "*-*-*-")
   (list "B"  "-***")
   (list "O"  "---")
   (list "2"  "**---")
   (list ","  "--**--")
   (list "C"  "-*-*")
   (list "P"  "*--*")
   (list "3"  "***--")
   (list "?"  "**--**")
   (list "D"  "-**")
   (list "Q"  "--*-")
   (list "4"  "****-")
   (list "("  "-*--*")
   (list "E"  "*")
   (list "R"  "*-*")
   (list "5"  "*****")
   (list ")"  "-*--*-")
   (list "F"  "**-*")
   (list "S"  "***")
   (list "6"  "-****")
   (list "-"  "-****-")
   (list "G"  "--*")
   (list "T"  "-")
   (list "7"  "--***")
   (list "\"" "*-**-*")
   (list "H"  "****")
   (list "U"  "**-")
   (list "8"  "---**")
   (list "_"  "**--*-")
   (list "I"  "**")
   (list "V"  "***-")
   (list "9"  "----*")
   (list "'"  "*----*")
   (list "J"  "*---")
   (list "W"  "*--")
   (list "0"  "-----")
   (list ":"  "---***")
   (list "K"  "-*-")
   (list "X"  "-**-")
   (list "/"  "-**-*")
   (list ";"  "-*-*-*")
   (list "L"  "*-**")
   (list "Y"  "-*--")
   (list "+"  "*-*-*")
   (list "$"  "***-**-")
   (list "M"  "--")
   (list "Z"  "--**")
   (list "="  "-***-")
   (list "!"  "-*-*--")))

Figure 2: Morse code as data

The Morse Code Language

40 minutes

The goal is to create a language for writing Morse code text. The code is an old internationally standardized way of signaling, using "long" and "short" sounds, marks, etc. You can find the table that associates letters from the alphabet at the linked web site; figure 2 presents one particular way to represent this information as data in your chosen and beloved programming language, drum roll, Racket. If you don’t like the use of lists within lists, use DrRacket’s replace-all functionality to use a struct.

Here are two sample programs that should be able to run: mc1.rkt and mc2.rkt.

Challenge If you are done early, develop the language english, which maps modules that consist of word (string) sequences into lines of Morse code (one word per line).

Code Review

10 minutes

The Teaching Assistants will pick two students to present their Morse code language.