Homework 6

Omnibus

out:10/28, due:12/12

1. Review Growing a Language [30]

Watch the video of the talk Growing a Language by Guy Steele and write a short review of at least 500 words intended for an audience of Junior Computer Science majors. Your review should include a short factual description covering the basic facts, e.g., who is the speaker, when and where was the talk given, that is the topic, what qualifications does the speaker have relative to the topic. It should also briefly state the major position or points the speaker made in the talk. Finally, you should express your own opinion about the talk, e.g., do you recommend it to other computer science majors? Why or why not? Is it still relevant after 13 years? Does Dr. Steele's rhetorical trick of starting with a simple subset of English help or obscure his point. Did the talk give you new insights into the design and evolution of programming languages?

Submit your review as a pdf document named growing.pdf.

2. The right tool [25]

The Right Tool web site implements an interesting idea: develop a knowledge base to help choose the right "tool" for a "job" by asking people to characterize or rank tool choices along a set of dimensions. The site started with a focus on programming languages, as described in a blog post:

"James Iry recently wrote a post about type systems in which he ranked type systems according to two characteristics, safety and sophistication. We had an interesting discussion about it on IRC afterwards, in which one of the things discussed was whether these were really the right axes.

It occurred to me that we spend a lot of time talking about the major axes on which you compare programming languages, and that it would be interesting to gather some data on what these actually were instead of just plucking things that seem like they may sense out of the air. So I’ve created a little app to gather data for this: Check out The Right Tool, and I’d love it if you’d rank some languages on it.

Essentially the idea is this: I have a list of statements and a list of programming languages, and I want you to rank those languages in order of how well the statements apply to them."

Try out the site (for programming languages, not gins or martial arts) by identifying the programming languages you know and answering at least 20 statements for them. Based on your experience and an exploration of the site, write a brief review of it, again for an audience of university programming language majors. Start by describing what the site tries to do for programming languages, who created it and why. offer your opinion about whether you think the idea behind the site is useful and works for programming languages. Describe how you imagine programmers might use the site. HEre are some final questions you might address: Looking at the range of statements, are there any you think are particularly insightful? Are there some where the collective answers surprised you? can you think of some statements that you think would be good to add or remove? Are there languages that you think should be added?

Submit your work as a file hammer.pdf.

3. An enigma [5]

Complete the comment so it describes in a sentence or two what does the following function does and what kind of argument it should be called with to avoid getting a run time error.

(define (enigma x)
;; the enigma function ...
(or (null? x)
(null? (rest x))
(and (not (equal? (car x) (car (cdr x))))
(enigma (rest x)))))

Hint: it you can't see what enigma does by inspection, load it into a Scheme interpreter and experiment with it. If it is obvious from the code what it does, it's still wise to load it into Scheme and verify your theory.

4. A conundrum [5]

Complete the comment so it describes in a sentence or two what does the following function does and what kind of argument it should be called with to avoid getting a run time error.

(define (conundrum x y)
  ;; The amazing function conundrum ...
(cond ((null? y) -1) ((equal? x (first y)) 0) (else (let ((z (conundrum x (rest y)))) (if (< z 0) z (+ 1 z))))))

Recall that the let is used to create an environment with new local variables and to initially bind them to particular values. Let evaluates the expressions for the initial values outside the environment and then creates the new local variables and makes the initial assignments. A typical example is creating a local variable TEMP used to swap the values of two other variables, A and B:

(let ((temp #f)) 
   (set! temp a)
   (set! a b)
   (set b temp))

Note that we might simplify this as follows:

(let ((temp a)) 
   (set! a b)
   (set b temp))

5. lambda expressions [15]

Write lambda expressions that evaluate to the following:

  • 5.1 A function that takes no arguments and always returns 0
  • 5.2 A function that takes two strings and returns the one that should occur first in a alphabetic ordering. (Hint: the builtin function string<? will be helpful.)
  • 5.3 A function that takes a single argument, F, that is a predicate function and returns a new function that is F's converse. Whenever the predicate F is true for some argument, its converse will be false and whenever F is false, its converse will be true. (Hints: the answer is simple and will have the form (define q3.3 (lambda (F) ...)). You will need a lambda inside a lambda. Since you don't know how many arguments F will take (and might in fact take a variable number) you will have to use apply and the syntax for defining a lambda expression that takes any number of arguments -- e.g., ((lambda X (apply + (map square X))) 1 2 3 4) returns 30.
Be sure to test your lambda expression in the Scheme interpreter. Here is an example of a lambda expression that takes a single numberic argument and returns a value that is one more.
(lambda (n) (+ n 1))
and this shows how you would call it
> ((lambda (n) (+ n 1)) 100)
101
You can use test2.in to test your answers, which should produce output list test2.out when used with the test.ss module, as in this session.
Welcome to MzScheme v4.2.5 [3m], Copyright (c) 2004-2010 PLT Scheme Inc. > (require "test.ss") > (load "hw6.ss") > (test "tests2.in" "tests2.out") #t

6. unique-atoms (30)

Write a function unique-atoms that takes an arbitrary s-expression and returns a list of the unique atoms in it. The order of the atoms in the list is not important.

> (load "hw6.ss")
> (unique-atoms '(a (b) b ((c)) (a (b))))
(a c b)
> (unique-atoms '(a . a))
(a)
> (unique-atoms '())
()

Hint: Start by writing a function atoms that takes an s-expression and returns a list of all of the atoms in it. Then write a function unique-members that takes a list and returns a list of the unique top-level elements of the list. Once you have these two, you are almost done.

Testing your code

We will provide a file hw6test.ss that you can use to test your code. Put this file in the same directory as your hw6.ss file on gl and then call the following:

mzscheme -f hw6test.ss

 

What to hand in

Start with the stub file hw6stub.ss. Rename this to hw6.ss and edit it to include your answers to problems 3-5 and the code for problem 6. Submit three files: growing.pdf, hammer.pdf and hw6.ss to the submit directory on gl.