Arc Forumnew | comments | leaders | submitlogin
Example conversions and problems from Dybvig's The Scheme Programming Language
1 point by goodbyejim 6076 days ago | 8 comments
A place where I and others can work through Dybvig's book.

For instance, from the bottom of page 14 (3rd edition):

(define square (lambda (n) (* n n)))

becomes:

(def square(n) (* n n))

Which is one less keyword and one fewer pairs of braces. Excellent!



5 points by tjr 6076 days ago | link

Nothing against Arc, but don't forget that Scheme also lets you write:

(define (square x) (* x x))

-----

1 point by goodbyejim 6076 days ago | link

Interesting. I wonder why Dybvig used the wordier way to do it.

-----

2 points by tjr 6076 days ago | link

Not sure. Could be because the wordier approach more clearly states what is going on, and makes it easier to understand anonymous lambda expressions later on?

-----

1 point by goodbyejim 6076 days ago | link

The reciprical function in the middle of pg 15 becomes:

arc> (def reciprocal(n) (if (is n 0) "oops!" (/ 1 n)) )

which again reduces the number of keywords and pairs of braces by one, because there is no longer a need to state that what follows def is a lambda.

That makes sense. What else would it be?

-----

1 point by goodbyejim 6074 days ago | link

Arc's form of let does not accept an extra pair of parentheses:

arc> (let ((x 2)) (+ x 3)) Error: "Can't understand fn arg list 2"

But: arc> (let x 1 (+ x (* x 2))) results in 3

So:

arc> (let x 2 (+ x 3)) results in 5

-----

1 point by goodbyejim 6074 days ago | link

arc> (cdr '(a)) nil

which in regular scheme would return () . This is has the effect of reducing the number of parentheses, which is a good thing.

-----

1 point by goodbyejim 6074 days ago | link

arc> (list) ()

On another thread I asked why this does not return nil. Someone responded that () and nil are two ways of saying the same thing.

-----

1 point by goodbyejim 6073 days ago | link

Someone on another thread pointed out that if you want to run the arc server on port 9090 instead of 8080 you just say:

(asv 9090)

-----