dtc
1 Chapter 1:   Prologues
print
print
print
2 Chapter 2:   Beginnings
cat
meta-cat
first-viral-cat
edison-cat
authors-cat
rotate
shrink
grow
rotate-left
redify
blueify
greenify
orangeify
purpleify
yellowify
meme-teacher
dtc-cover
dijkstra
habermann
notkin
griswold
2.1 Bonus images
meso-star-1
meso-star-2
meso-star-3
meso-star-4
meso-sun-1
meso-sun-2
meso-sun-3
meso-sun-4
meso-rain-1
meso-rain-2
meso-rain-3
meso-rain-4
meso-fish-1
meso-fish-2
meso-fish-3
meso-fish-4
3 Chapter 3:   Middles
image
animation
napoleon/  turk
napoleon/  turk-raw
image-chess
image-tic-tac-toe
4 Chapter 4:   Ends
define
define
if
cond
print
~a
eq?
current-day
image-code
shuffle
animate-deck
7.5

dtc

Stephen R. Foster and Lindsey Handley

image

This is the documentation page for the programming languages used in the book Don’t Teach Coding.

These languages are used in various sections of the book, shown in green below:

image

1 Chapter 1: Prologues

Here we document the various "Hello, World!" languages from Chapter 1.

 #lang dtc/hello/normal package: dtc

procedure

(print s)  void?

  s : string?
This simply prints to the screen whatever you give it, allowing you to participate in the age-old tradition of writing "Hello, World!" programs in the earliest moments of your coding journey.

Simply:

#lang dtc/hello/normal
(print "Hello, World!")

The output of Stories like (print "Hello, World!") are intended to be compared with identical-looking stories written in different languages (see below). The point is to show by demonstration that syntax can remain constant while semantics differ from language to language.

 #lang dtc/hello/colors package: dtc

procedure

(print s)  void?

  s : string?
This allows you to particplate in the age-old tradition of writing "Hello, World!" programs – but with a colorful twist! (I mean, come on, it’s the 21st century, "Hello, World!" programs are allowed to be cooler than just displaying text.)

Simply:

#lang dtc/hello/colors
(print "Hello, World!")

Gives you something a bit different every time:

image image image

 #lang dtc/hello/animation package: dtc

procedure

(print s)  void?

  s : string?
This allows you to particplate in the age-old tradition of writing "Hello, World!" programs – but with an animated twist!

#lang dtc/hello/colors
(print "Hello, World!")

That produces an animation describable with this Story:

image

2 Chapter 2: Beginnings

Here we document the various cat-related and Story-related languages from Chapter 2.

 #lang dtc/story/images package: dtc

This language has no specific vocabulary. In fact, any Story is valid.

Rules: Moments should be separated by an arrow (->). Separate Stories must go on separate lines.

This language simply compiles valid Stories to images. For example, this program will produce three images:

#lang dtc/story/images
 
today -> I -> wrote -> "Hello, World"
love -> conquers -> all
history -> matters
 

Images can be saved to disk within DrRacket by right-clicking on them and selecting Save image...

Images can be embedded in a Story by placing the cursor where you want the image and clicking Insert > Insert Image ...

Exercise Can you produce this image?

image

 #lang dtc/story/cats package: dtc

A language with various vocabulary for producing and manipulating images of cats.

procedure

(cat)  void?

A photograph of a kitten from the 1800s, by Harry Pointer – the Father of Cat Photos and definer of the cat photography genera.

image

procedure

(meta-cat)  void?

A photograph of a cat from 1870, by Harry Pointer. Also, perhaps the first meta-photo of a cat in human history. Titled The Photographer, the image shows a cat apparently operating a camera, while being photographed by a camera.

image

procedure

(first-viral-cat)  void?

A frame from one of the first viral cat videos in the history of YouTube. Uploaded in the year 2006, it can be found here.

image

procedure

(edison-cat)  void?

The boxing cats filmed in 1894 by Thomas Edison. The video can be found here.

image

procedure

(authors-cat)  void?

A cat owned by one of the authors.

image

procedure

(rotate)  void?

Rotates an image (of a cat, or otherwise):

#lang dtc/story/cats
 
cat -> rotate

Gives:

image

In other languages, the same can be accomplished with a different syntax:

#lang dtc/story+/cats
 
(rotate (cat))

procedure

(shrink)  void?

Halves the size an image (of a cat or otherwise).

#lang dtc/story/cats
 
cat

Gives:

image

#lang dtc/story/cats
 
cat -> shrink

Gives:

image

#lang dtc/story+/cats
 
(shrink (cat))

Is the same.

procedure

(grow)  void?

Doubles the size of an image.

#lang dtc/story/cats
 
cat

Gives

image

#lang dtc/story/cats
 
cat -> grow

Gives:

image

procedure

(rotate-left)  void?

Same as rotate, but in the other direction.

image

procedure

(redify)  void?

Tints an image red – e.g.:

image

procedure

(blueify)  void?

Tints an image blue – e.g.:

image

procedure

(greenify)  void?

Tints an image green – e.g.:

image

procedure

(orangeify)  void?

Tints an image orange – e.g.:

image

procedure

(purpleify)  void?

Tints an image purple – e.g.:

image

procedure

(yellowify)  void?

Tints an image yellowify – e.g.:

image

procedure

(meme-teacher)  void?

A famous image used as the basis for the "Unhelpful High School Teacher" meme, reaching peak popularity in 2011. For more details, see knowyourmeme.com

image

procedure

(dtc-cover)  void?

The cover of the book!

image

procedure

(dijkstra)  void?

Edsger W. Dijkstra (1930-2002), a famous and influential computer scientist – a prolific writer, researcher, and mathematician.

image

procedure

(habermann)  void?

Nico Habermann (1932-1993), influential computer scientist and student of Dijkstra. His Wikipedia page can be found here. And his teacher/student family tree (from 1990) can be found here.

image

procedure

(notkin)  void?

David Notkin (1955-2013), influential computer scientist and student of Nico Habermann. His 2013 IEEE Memorandum can be found here.

image

procedure

(griswold)  void?

Influential computer scientist, student of David Notkin. His Wikipedia page can be found here.

image

2.1 Bonus images

Some bonus images of Mesopotamian symbols. Higher numbers indicate later versions of that symbol. They can be treated like any other image. Example:

#lang dtc/complete
 
(image
  `(,(redify (meso-star-1))
    ,(orangeify (meso-star-2))
    ,(yellowify (meso-star-3))
    ,(greenify  (meso-star-4))))

Produces the Story image of how the symbol for "star" grew more abstract over time:

image

procedure

(meso-star-1)  void?

image

procedure

(meso-star-2)  void?

image

procedure

(meso-star-3)  void?

image

procedure

(meso-star-4)  void?

image

procedure

(meso-sun-1)  void?

image

procedure

(meso-sun-2)  void?

image

procedure

(meso-sun-3)  void?

image

procedure

(meso-sun-4)  void?

image

procedure

(meso-rain-1)  void?

image

procedure

(meso-rain-2)  void?

image

procedure

(meso-rain-3)  void?

image

procedure

(meso-rain-4)  void?

image

procedure

(meso-fish-1)  void?

image

procedure

(meso-fish-2)  void?

image

procedure

(meso-fish-3)  void?

image

procedure

(meso-fish-4)  void?

image

3 Chapter 3: Middles

Here we document the various nestable Story languages from Chapter 3.

 #lang dtc/story+/images package: dtc

This is like #lang dtc/story/images except that it recognizes Stories written with the parenthesized syntax, rather than the Arrow syntax.

So instead of this...

#lang dtc/story/images
 
today -> I -> wrote -> "Hello, World"
love -> conquers -> all
history -> matters
 

... you would write this ...

#lang dtc/story+/images
 
(today I wrote "Hello, World")
(love conquers all)
(history matters)

By denoting the beginning and end of a Story with parentheses:

 #lang dtc/story+/cats package: dtc

Provides the same vocabulary as #lang dtc/story/cats (see various definitions above). But the grammar requires the parenthesized syntax instead of the Arrow syntax.

To ease the transition, though, many of the images above can be used flexibly – i.e. the following two programs are both valid and equivalent:

#lang dtc/story+/cats
 
(cat rotate redify)
#lang dtc/story+/cats
 
(redify (rotate (cat)))

Also note, although this is not mentioned in the book, this language is actually a super-set of the Racket language, meaning that you have access to all common functions (i.e. sqrt). You can also import other Racket libraries. For example, using (require 2htdp/image) can be used to bring in more image-related vocabulary words (as documented by the 2htdp library]):

#lang dtc/story+/cats
 
(require 2htdp/image)
 
(scale 2
 (overlay
  (redify (rotate 15 (dijkstra)))
  (circle 100 'solid 'black)))

image

This is so that students who go on to read How To Design Programs can return and creatively reengage with the content of "Don’t Teach Coding".

Vocabulary words that overlap (like rotate) will be overwritten by the required library. So you must adhere to the grammatical rules documented by that library (i.e. putting the rotation angle in the first position of a (rotate ...) expression.

 #lang dtc/frames/cats package: dtc

Same as #lang dtc/story+/cats (see above) but adds vocabularly related to nested Stories.

procedure

(image moments)  image?

  moments : (listof moment?)
Takes a Story (also known as a list) and turns it into an image. The color scheme is designed to make clear which parts of the Story (if it were code) would execute as code and which parts would be treated as data. The colors black and gray are used to differentiate between code and data.

A simple example would be

#lang dtc/frames/animations
 
(image '(this is a story))

Giving:

image

The provided Story may contain nested Stories, in which case, the sub-Stories are rendered in a nested part of the resulting image.

#lang dtc/frames/animations
 
(image `(this `(is a story)))

Gives:

image

And:

#lang dtc/frames/animations
 
(image `(this `(is `(a story))))

Gives:

image

The top-most (framing) Story is always render in black. A quoted story is rendered in gray.

Escaping from a gray story, causes the escaped story to render in black:

#lang dtc/frames/animations
 
(image `(this `(is ,(a story))))

Gives:

image

The gray dot is a visual representation of the quotation mark, high on the line. The black dot is the visual representation of the comma, low on the line.

Finally, note that you have access to all of Racket, so there are many valid things you can do with Stories before they are handled by image.

#lang dtc/frames/animations
 
(image (shuffle '(this is a story)))

image

And:

#lang dtc/frames/animations
 
(image (reverse '(this is a story)))

Giving:

image

procedure

(animation moments)  image?

  moments : (listof moment?)
Converts moments into images and shows them in the frames of an animated sequence. If the moment is already an image, that image will be used as the frame. Strings, numbers, and symbols will be automatically coverted into images.

procedure

(napoleon/turk [n])  image?

  n : number? = #f
If given a number n, this returns an image of move n in the famous 1809 game between Napoleon Bonepart and Johann Allgaier, who was (unknown to Napoleon) hidden inside the Mechanical Turk. The machine was believed by many to be an automaton. Edgar Alan Poe debunked the hoax in 1836, but was incorrect about many of the mechanical details.

If not given a number, napoleon/turk returns a Story whose moments are the images in the game.

For example, the full game can be animated to completion with:

#lang dtc/frames/animations
 
(animate (napoleon/turk))

procedure

(napoleon/turk-raw n)  Story?

  n : number?
Like the above, but instead of returning images, this returns the full data that would be used to construct the image, using image-chess.

The following two programs are equivalent

#lang dtc/frames/animations
 
(napoleon/turk 4)
#lang dtc/frames/animations
 
(image-chess (napoleon/turk-raw 4))

Both give:

image

procedure

(image-chess s)  image?

  s : ChessStory?
Turns a 64-moment Story describing where the pieces on a chessboard are into an image of a chess board.

Valid moments are:
  • An underscore '_ – indicating an empty square.

  • A lowercase letter indicating a white piece.

  • An uppercase letter indicating a black piece.

Valid letters are 'K (for King), 'Q (for Queen), 'B (for Bishop), 'N (for Knight), 'R (for Rook), and 'P (for Pawn).

procedure

(image-tic-tac-toe s)  image?

  s : TicTacToeStory?
Turns a 9-moment Story into an image of a Tic-Tac-Toe board. Normal moments are '_ (for a blank square), 'X, and 'O.

#lang dtc/frames/animations
 
(image-tic-tac-toe
  `(_ _ _
    _ X _
    _ O _))

Gives:

image

Note that other moments are accepted too. For example, games of red cats vs blue Dijkstras may be generated as follows:

#lang dtc/frames/animations
 
(define X (redify (cat)))
(define O (bluify (dijkstra)))
 
(image-tic-tac-toe
  `(_ _  _
    _ ,X _
    _ ,O _))

image

4 Chapter 4: Ends

Here we document the various nestable Story languages from Chapter 4.

 #lang dtc/complete package: dtc

This language has everthing in it that Racket does, and more. We won’t document everything from Racket here – only the vocabulary that’s directly used in Don’t Teach Coding.

syntax

(define word def)

Allows you to add the new word to your language from that point forward.

#lang dtc/complete
(define hello "Hello, everybody!")

From that point forward hello can be used without errors. It’s meaning has been given.

syntax

(define (word slot ...) def)

Allows you to add a complex expression to your language from that point forward.

#lang dtc/complete
(define (hello ___)
   (~a "Hello, " ___ "!"))

From that point forward hello can be used, as long as it matches the pattern (hello _). For example, (hello "World") or (hello (hello "World")).

syntax

(if condition true-branch false-branch)

Is equivalent to true-branch when condition is #t (true), and to false-branch otherwise.

For example:

#lang dtc/complete
 
(if (eq? 'tuesday (current-day))
  (print "Cook tacos")
  (print "Cook the usual"))

This program will behave differently on Tuesdays because the (if ...) expression behaves differently on Tuesdays.

syntax

(cond [if then] ... [else __])

Like if, but supports more two or more branches.

#lang dtc/complete
 
(cond
  [(eq? 'monday (current-day))
   (print "Cook burgers")]
  [(eq? 'tuesday (current-day))
   (print "Cook tacos")]
  [else (print "Cook the usual")])

Note that there are many ways to do conditional branching. Racket for example, has a construct called match which can express the above idea in an even more syntactically clear way

#lang dtc/complete
 
(match (current-day)
  ['monday  (print "Cook burgers")]
  ['tuesday (print "Cook tacos")]
  [else     (print "Cook the usual")])

We mention it here to remind you that there’s an entire world of linguistic discovery to be had beyond the pages of these docs...

procedure

(print s)  void?

  s : string?
Just displays the given string in the interactions window.

procedure

(~a s ...)  image?

  s : string?
Combines a bunch of things into one string. It converts non-string things (like numbers) into strings.

#lang dtc/complete
 
(define number-of-people 5)
(define number-of-plates (* 2 number-of-people))
(define number-of-cups   (* 3 number-of-people))
(define bags-of-chips    (/ number-of-people 3))
(define bottles-of-soda  (/ number-of-people 4))
 
(print
  (~a "Buy:\n"
      number-of-plates " plates \n"
      number-of-cups " cups \n"
      bottles-of-soda " bottles \n"
      bags-of-chips " chips \n"))

procedure

(eq? x y)  image?

  x : any/c
  y : any/c
Checks if two things are the same. This is commonly used in conjunction with if or cond.

Something that is the same today might not be the same tomorrow.

We’ll now document the things that dtc/complete adds to Racket.

procedure

(current-day)  image?

Depending on the day, returns either 'monday, 'tuesday, etc.

#lang dtc/complete
 
(define number-of-people
  (cond
    [(eq? 'monday (current-day))  5]
    [(eq? 'tuesday (current-day)) 9]
    [(eq? 'thursday (current-day)) 12]
    [(eq? 'friday (current-day))  17]
    [else 0]))
 
(if (> number-of-people 10)
  (print "Bring extra chairs")
  (print "Bring the usual stuff"))

procedure

(image-code s)  image?

  s : Story?
Takes a Story and returns an image of it – so that it can, for example, be embedded in flashcards or other materials that wish to talk about code. Code is visual; images are a key component of visual storytelling. If you want to communicate about code, you’ll need to be able to make images of it. Taking a screenshot is the non-automated form of this.

#lang dtc/complete
 
(image-code
 `(animate
    `(cat ,(cat))))

This gives you:

image

Remember that once something is an image, other vocabulary that pertains to images becomes relevant:

#lang dtc/complete
 
(rotate
 (image-code
  `(animate
    `(cat ,(cat)))))

image

procedure

(shuffle s)  Story?

  s : Story?
Takes a story and jumbles its moments up randomly.

#lang dtc/complete
 
(define class-members '(alice bob jimmy susan marco ))
 
(define random-person
  (first (shuffle class-members)))
 
(print
   (~a "The winner is..." random-person))

This program will pick a random class member.

procedure

(animate-deck s)  image?

  s : Story?
Takes a Story and assumes that each Moment is a Story with two Moments. This makes the outer Story like a "deck" and the inner Stories like "cards". Each "card" has a front and a back – its two Moments.

The animate-deck word displays each front until you press a key. Then it will display the back. Then it will go to the next card. And so on, until all the cards are shown, at which point it loops back to the beginning.

Here’s a program for animating a small deck of two flashcards.

#lang dtc/complete
 
(animate-deck
 `((cat             ,(cat))
   (first-viral-cat ,(first-viral-cat))))
#lang dtc/complete
 
(define dtc-trivia-deck
 `(("Year of first program comprehension fMRI study?"
    "2014")
 
   ("American Sign Language shares what \"modality\" or
     \"channel\" with computer languages?"
    "The visual-spatial modality, or channel")
 
   ("The oldest known story-within-a-story dates back to?"
    "Ancient Egypt (18th to 16th century BC).
    King Cheops' 5 sons tell 5 stories about magic and
    miracles.")
 
   ("Both the backslash and the backtick serve a similar
     abstract purpose.  What is it?"
    "To \"escape\" the thing that comes after it.  The
     backslash precedes a literal quote or a literal
     backslash.  The backtick precedes a literal
     (uninterpreted) story.")
 
   ("Programming comprehension, understanding American Sign
     Language, and reading English have all been
     shown to activate which part of the brain?"
    "Broca's area.")
 
   ("In a Story that describes a flashcard, how many
     Moments are there?"
    2)
 
   ("In a Story that describes a tic-tac-toe board, how
     many Moments are there?"
    9)
 
   ("In a Story that describes a deck of cards, how many
     Moments are there?"
    "It depends.  As many as there are cards in the deck.")
 
   ("In a Story that describes a game of chess, how many
     Moments are there?"
    "It depends.  As many as there are moves in the game.")
 
   ("In a Story that describes a game of tic-tac-toe, how
     many Moments are there?"
    "It depends.  As many as there are moves in the game.
     But no more than 9.")
 
   ("Write a simple program that animates through a deck
     with two cards, both of which have pictures of cats
     on the back."
    (image-code
       `(animate-deck
          `("What does the first viral cat on the internet
             look like?"
            ,(first-viral-cat))
          `("What does the oldest photo of a cat look
             like?"
            ,(cat)))))
 
   ("Write a simple program that animates through the
     numbers from 1 to 10."
    (image-code
       `(animate
          `(1 2 3 4 5  6 7 8 9 10))))
 
   ("Write a simple program that shows a picture of a Story
     whose three moments are three images of cats."
    (image-code
       `(image
          `(,(cat) ,(edison-cat) ,(first-viral-cat)))))
 
   ("Write a Story that shows a picture of a flashcard that
     has a picture of a chessboard on the back."
    (image-code
       `(image
          `("What does the starting state of a chessboard
             look like?"
            ,(napoleon/turk 1)))))))
 
 
   (animate-deck dtc-trivia-deck)