Subject: Long Live the Minute Difference

From: Shlomi Fish <[email-masked]>
Date: Mon, 17 Dec 2001 14:28:59 +0200 (IST)

I had a "Structure and Interpretation of Computer Programs" class today.
The lecturer demonstrated how one can construct a type of a rational
number using the following notation:

(define (make-rat n d) (cons n d))

(define (numer r) (car r))
(define (denom e) (cdr r))

He then said we can also simply say:

(define make-rat cons)
(define numer car)
(define denom cdr)

And they will behave _exactly_ the same. I told him that they do not
behave exactly the same. The first notation when called will look for the
definition of cons in run-time and call it, so if cons was re-defined as
something else, the re-definition will be called instead. On the other
hand the second notation will always mean the Scheme's user-supplied cons
or whatever cons was defined as in the execution of the statement. The
lecturer did not understand me and insisted that they did exactly the same
thing.

To prove my point I left the class, went to the nearby Computer Networks
Lab and wrote the following snippet on my workstation:

(define (make-rat n d) (cons n d))
;Value: make-rat

(define (cons n d)
  (display n)
  (newline)
  (display d)
  (newline)
)
;Value: cons

(make-rat 5 6)
5
6
;Unspecified return value

During the break, I showed it to the lecturer, and after some discussion,
he got convinced that I was right. He corrected himself after the break.

The lecturer is a very good one but he doesn't seem to remember the small
nuances of the Scheme language too well. He also told us (and ... ) and
(or ... ) were functions while in fact they were special forms.

In any case, in a discussion I had with a friend of mine I suggested that
one can protect the functions from a possibility that their utility
functions will be over-riden like this:

(define make-rat (let ((cons cons)) (lambda (n d) (cons n d))))

This is useless in this case but may be useful if the expression is a bit
more complex.

Regards,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"

---

From: Tal Abir <[email-masked]>
Date: Tue, 18 Dec 2001 09:09:55 +0200 (IST)

nice, what language is that?
	Where do you use it?

On Mon, 17 Dec 2001, Shlomi Fish wrote:

> To unsubscribe from this group, send an email to:
> [email-masked]
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>

-- 
	Tal Abir

	The ultimate question:"How many T:(Z2)^2--->(Z2)^2 1:1 exists?"
	The ultimate answer:"42"

            This saying is automaticly composed by Fortune
--------------------------------------------------------------------
File cabinet:
	A four drawer, manually activated trash compactor.

---

From: Shlomi Fish <[email-masked]>
Date: Tue, 18 Dec 2001 10:00:28 +0200 (IST)

> 	nice, what language is that?

It is Scheme:

http://www.schemers.org/

But it applies to other lexically scoped languages too. (and perhaps some
that are not lexically scoped)

> 	Where do you use it?

Scheme can be used for all kinds of stuff. We use it in the EE course of
"Structure and Interpretation of Computer Programs":

http://tiger.technion.ac.il/~ee044261/

Which follows the book by the same name:

http://mitpress.mit.edu/sicp/full-text/book/book.html

Which is a very nice book, BTW.

Regards,

	Shlomi Fish

---

From: "Gilad Ben-Yossef" <[email-masked]>
Date: Tue, 18 Dec 2001 11:53:05 +0200

> Which is a very nice book, BTW.

Yes, all other things being even (execution speed, compilers quality etc. etc.) Scheme will be the laguage I would choose to program everything with...

And the wizard book is really great - although it does not teach Scheme. Oh, you will catch Scheme fast enough if you use it (note that I didn't say read, I said use) but it'll only be a tool to learn all the really really neat stuff inside which is pure computer programing, not any specific language.

It was written by 2 of the major hackers (from the original group of MIT AI lab) in the world and it shows; the opening paragraph of the book reads:
"We are about to study the idea of a computational process. Computational processes are abstract beings that inhabit computers. As they evolve, processes manipulate other abstract things called data. The evolution of a process is directed by a pattern of rules called a program. People create programs to direct processes. In effect, we conjure the spirits of the computer with our spells."

I think only a true hacker can understand the last sentence.

-- 
Gilad Ben-Yossef <[email-masked]>
Tel: +972(9)9717330 | Fax: +972(9)9717334   | Cel: +972(54)756701
Kagoor Networks ltd | http://www.kagoor.com |

---

From: Oleg Goldshmidt <[email-masked]>
Date: 18 Dec 2001 11:02:29 +0200

Gilad Ben-Yossef <[email-masked]> writes:

> "In effect, we conjure the spirits of the computer with our spells."
> 

Or a Harry Potter fan? ;-)

-- 
Oleg Goldshmidt | [email-masked] 
"If it ain't broken, it has not got enough features yet."

---

From: Oleg Goldshmidt <[email-masked]>
Date: 19 Dec 2001 00:18:27 -0500

> lecturer did not understand me and insisted that they did exactly the same

You are right, of course, and there are more aspects to it than your 
exercise in lexical scoping. E.g. 

(define make-rat cons) 

means not that make-rat *calls* cons but that make-rat *is* cons. This
means that there will be only one function call involved in

(make-rat n d)

and not two. And I am not sure if you can easily debug the second
definition of make-rat, in terms of tracing calls to make-rat or
putting a breakpoint in it [surely you don't want to trace or break in
every call to cons].

What your professor probably meant that the two definitions are
functionally equivalent in terms of operations on rational numbers, as
long as cons, car, and cdr are a consistent triplet of pair
constructor and accessors, i.e. for any x, y we have

(car (cons x y)) is x
(cdr (cons x y)) is y

Any triplet of procedures satisfying the above can be used to form
pairs, and both definitions of make-rat and friends will lead to
the same results as far as rational arithmetic is concerned.

-- 
Oleg Goldshmidt | [email-masked] 
If it aint't broken it hasn't got enough features yet.

---

From: Oleg Goldshmidt <[email-masked]>
Date: 19 Dec 2001 00:37:33 -0500

> 	nice, what language is that?

Scheme - a dialect of Lisp.

> 	Where do you use it?

Of the popular things GIMP and scsh (a shell with scheme-like syntax,
written in scheme) come to mind. However, scheme does have a
reputation of an academic language. I'd love to do a serious project
in scheme (or Lisp). Ideas, anyone?