SICP question 
Author Message
 SICP question

Hi,

I'm studying 'Structure and interpretation of computer programs
second edition'.

However, I'm stuck at exercise 1.6 at page 25.

First I thought that it had something to do with the difference
between applicative-order evaluation and normal-order evaluation
(like discussed on page 16).

However, if I type the program in DrScheme and use the de{*filter*},
I get the message:

'define: name is already bound: square'

Bottom line: I'm completly confused. Somebody who can help me
understand this exercise ?

                        Thank you, Philip



Sun, 01 Feb 2004 02:22:05 GMT  
 SICP question

Quote:

>First I thought that it had something to do with the difference
>between applicative-order evaluation and normal-order evaluation
>(like discussed on page 16).

Right you are!

Quote:
>However, if I type the program in DrScheme and use the de{*filter*},
>I get the message:
>    'define: name is already bound: square'

If you must use DrScheme, find the "Language" preference panel
and tell it to be a Scheme interpreter, instead of a not-Scheme
interpreter as it is by default.


Sun, 01 Feb 2004 04:09:22 GMT  
 SICP question

Quote:

> If you must use DrScheme, find the "Language" preference panel
> and tell it to be a Scheme interpreter, instead of a not-Scheme
> interpreter as it is by default.

They call it "Full Scheme," a name I consider misleading because the
"student" languages are not really subsets of Scheme, just different.


Sun, 01 Feb 2004 05:41:04 GMT  
 SICP question

Quote:

>>First I thought that it had something to do with the difference
>>between applicative-order evaluation and normal-order evaluation
>>(like discussed on page 16).

> Right you are!

Ok :-)
Now, let's see: since i'm using DrScheme, wich has an applicative-order
evaluation model (as concluded in excercise 1.5 on page 21), the
evaluation of

(new-if (good-enough? guess x)
        guess
                (sqrt-iter (improve guess x)
                                   x))

begins with the evaluation of the tree operands of the new-if
function. However, the last operand (the else clause) is a recursive
call. This way, the function cannot return any value since it's
in an infinite loop.

Am I correct ?

Quote:
> If you must use DrScheme, find the "Language" preference panel
> and tell it to be a Scheme interpreter, instead of a not-Scheme
> interpreter as it is by default.

I have choosen DrScheme because it was recommended to me. However,
i'll check the FAQ for better alternatives. Wich one can you recommend
(it needs to be free and i'd like it to be RC5 complaint) ?

                         Thank you very much, Philip

PS: is it accepted group policy to prepare excercices and when in need,
    ask for help ? Or is this a more theoretical group ?



Sun, 01 Feb 2004 06:00:10 GMT  
 SICP question

[...]
Quote:
> However, if I type the program in DrScheme and use the de{*filter*},
> I get the message:

> 'define: name is already bound: square'

[...]

Without looking into the question yet, did you set your language level
in Dr. Scheme? (The Language menu item.)

Make sure you're set to "full scheme" or you will get bizarre errors.
The language levels are something that they use in Rice University,
but it confuses people who are learning on their own.

g.



Sun, 01 Feb 2004 06:17:40 GMT  
 SICP question

Quote:

> I have choosen DrScheme because it was recommended to me. However,
> i'll check the FAQ for better alternatives. Wich one can you recommend
> (it needs to be free and i'd like it to be RC5 complaint) ?

DrScheme is fine.  Just set the language to "Full Scheme."


Sun, 01 Feb 2004 07:38:48 GMT  
 SICP question

Quote:
> PS: is it accepted group policy to prepare excercices and when in need,
>     ask for help ? Or is this a more theoretical group ?

There should be some mention of the group attitude towards homework in
the FAQ (which is currently under re-construction at
<http://www.schemers.org>), because we get a lot of homework-related
questions.

That said, there are a lot of teaching Profs that hang out around
here. A lot of Schemers seem to have a teaching/mentoring bent to
their personalities, too. So we tend to answer all kinds of
programming questions, especially if it appears that the poster has
worked on the problem and actually cares to understand the
answer. OTOH people who post things like "Can someone give me the
answer to X, I need it to get out of this stupid course I have to
take" (this actually happened). will get royally flamed. You're also
more likely to get a friendly reception at times other than Sept, Dec,
Jan, and May, as that's when the bulk of the clueless homework
assignment postings tend to occur.

OTOH, most of the Schemers here also delight in deep and detailed
discussions of language semantics (witness the perpetually recurring
discussions of type issues, and the endless dissection of R5RS
minutiae), and in fact are authors of implementations (in many cases
they are contributors to the standards). So there is a strong
theoretical bent to a lot of the discussion.

At the end of the day, we try to be friendly to people who are really
trying to learn, but if you're just trying to duck your Prof's latest
HW assignment, you'll probably get flamed (and he might be readding
the group anyway).

david rush
--
The beginning of wisdom for a [software engineer] is to recognize the
difference between getting a program to work, and getting it right.
-- M A Jackson, 1975



Sun, 01 Feb 2004 16:15:54 GMT  
 SICP question

Quote:


> Now, let's see: since i'm using DrScheme, wich has an applicative-order
> evaluation model (as concluded in excercise 1.5 on page 21), the
> evaluation of

> (new-if (good-enough? guess x)
>         guess
>            (sqrt-iter (improve guess x)
>                               x))

> begins with the evaluation of the tree operands of the new-if
> function. However, the last operand (the else clause) is a recursive
> call. This way, the function cannot return any value since it's
> in an infinite loop.

> Am I correct ?

I have explained this rather clumsy. The excercise above is ideal to
think about 'procedure application lists' (to use the proper term).

Ofcourse, it depends on the implementation of the scheme interpreter
whether it will be application order evaluation or normal order
evaluation. And the behauviour like explained above is clearly
for an interpreter which follows the application order evaluation
model.

Am I understanding this right ?

                                Thank you, Philip



Sun, 01 Feb 2004 18:51:13 GMT  
 SICP question

Quote:

>Ofcourse, it depends on the implementation of the scheme interpreter
>whether it will be application order evaluation or normal order
>evaluation.

Everything you said is correct except for this sentence.  If it doesn't
use applicative order, it's not a Scheme interpreter!

One can, of course, write an interpreter for an almost-Scheme language
using normal order evaluation (as is done in SICP 4.2).  But the
resulting language isn't Scheme, even though it looks a lot like
Scheme.

(And Scheme does allow you to make explicit requests for normal order
evaluation by using DELAY and FORCE.)



Mon, 02 Feb 2004 04:36:32 GMT  
 SICP question

Quote:

>Ofcourse, it depends on the implementation of the scheme interpreter
>whether it will be application order evaluation or normal order
>evaluation.

Everything you said is correct except for this sentence.  If it doesn't
use applicative order, it's not a Scheme interpreter!

One can, of course, write an interpreter for an almost-Scheme language
using normal order evaluation (as is done in SICP 4.2).  But the
resulting language isn't Scheme, even though it looks a lot like
Scheme.

(And Scheme does allow you to make explicit requests for normal order
evaluation by using DELAY and FORCE.)



Mon, 02 Feb 2004 03:32:11 GMT  
 SICP question

Quote:
> Everything you said is correct except for this sentence.  If it doesn't
> use applicative order, it's not a Scheme interpreter!

> One can, of course, write an interpreter for an almost-Scheme language
> using normal order evaluation (as is done in SICP 4.2).  But the
> resulting language isn't Scheme, even though it looks a lot like
> Scheme.

> (And Scheme does allow you to make explicit requests for normal order
> evaluation by using DELAY and FORCE.)

I don't understand this at all. Why would a scheme-implementation with normal
order evaluation be 'an almost-scheme' ?

                        Thank you, Philip



Mon, 02 Feb 2004 06:34:42 GMT  
 SICP question

Quote:


> > Everything you said is correct except for this sentence.  If it doesn't
> > use applicative order, it's not a Scheme interpreter!

> > One can, of course, write an interpreter for an almost-Scheme language
> > using normal order evaluation (as is done in SICP 4.2).  But the
> > resulting language isn't Scheme, even though it looks a lot like
> > Scheme.

> > (And Scheme does allow you to make explicit requests for normal order
> > evaluation by using DELAY and FORCE.)

> I don't understand this at all. Why would a scheme-implementation with
> normal order evaluation be 'an almost-scheme' ?

The language definition explicitly requires applicative-order evaluation.

From R5RS:

    Arguments to Scheme procedures are always passed by value, which means
    that the actual argument expressions are evaluated before the procedure
    gains control, whether the procedure needs the result of the evaluation
    or not.  ML, C, and APL are three other languages that always pass
    arguments by value.  This is distinct from the lazy-evaluation
    semantics of Haskell, or the call-by-name semantics of Algol 60, where
    an argument expression is not evaluated unless its value is needed by
    the procedure.

That's from section 1, although I can't be more specific on the reference,
since I'm working from the Texinfo version.

Richard



Mon, 02 Feb 2004 20:03:54 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Questions about SICP

2. Question about SICP's query system...

3. Question to SICP, Exercise 3.42

4. SICP (2Ed) Ch. 5 question?...

5. SICP for the US & Canada

6. SICP for the US & Canada

7. Spread of Scheme and SICP?

8. SICP again

9. OOP: Java vs. SICP

10. Help me! if you have the book SICP

11. Help needed - Scheme code from SICP

12. Scheme code (SICP)

 

 
Powered by phpBB® Forum Software