HtDP newbie

11 views
Skip to first unread message

Cena Mayo

unread,
Jan 8, 2009, 7:20:56 PM1/8/09
to Study-HTDP
Hi all,

Just started my first exercise: 2.1.1, and have a question about the
solution to the squaring the number problem.

Here's what I came up with: (define (square n) (* n n)) then you
run (square n). Actually I ripped this off another site, but it made
sense to me, even though I'm not a programmer.

However, after completing my 'research' I wanted to know if this
answer was 'correct'. I found the site of a guy working through the
problems and his answer was (* n n), which also makes sense, and was
also my first (non-research-based) response.

Is there a preferred method?

Geoffrey S. Knauth

unread,
Jan 8, 2009, 7:42:50 PM1/8/09
to study...@googlegroups.com
On Jan 8, 2009, at 19:20, Cena Mayo wrote:

> Just started my first exercise: 2.1.1, and have a question about the
> solution to the squaring the number problem.

The question was, "Find out whether DrScheme has operations for
squaring a number..."

Did you find out if it has such an operation? How did you explore
DrScheme's capabilities? Searching the Internet doesn't really count,
because you've got this great tool (DrScheme) right at your
fingertips, and what you're really supposed to do it explore that
tool, including its help system, to figure out what kinds of things it
can do.

> Here's what I came up with: (define (square n) (* n n)) then you
> run (square n).

I certainly think your definition is correct. But what if I told you
that and meanwhile I turned out to be a complete ignoramus? How could
you check for yourself?

I'll put it another way. Someone comes to your front door holding a
black box. He says, "This black box squares numbers. Put a number in
one side, and the square of the number comes out the other side." How
would you check if he was telling the truth?

Cena Mayo

unread,
Jan 8, 2009, 8:25:52 PM1/8/09
to Study-HTDP
Hi Geoffrey,

Thanks for the thoughtful (and quick) response! Well, seems I can
just (sqr n). *shamefaced

I did run the two different instructions I mentioned previously, and
they worked. I can see why (sqr n) is preferable to (* n n), but under
what circumstances (if any) would (define (square n) (* n n)) be
preferable to (sqr n)?

I really am a total newbie at this, although hopefully not a complete
ignoramus.

Thanks for your time, and for not simply telling me to RTFM! (which is
where I found the solution) :)

Cena

Grant Rettke

unread,
Jan 8, 2009, 10:15:13 PM1/8/09
to Study-HTDP
On Jan 8, 7:25 pm, Cena Mayo <cenaz...@gmail.com> wrote:
> Thanks for the thoughtful (and quick) response!  Well, seems I can
> just (sqr n). *shamefaced

No need to be as you still have two tries left: a function for
computing the sine of an angle and for determining the maximum of two
numbers.

Cena Mayo

unread,
Jan 9, 2009, 11:59:15 AM1/9/09
to Study-HTDP

> No need to be as you still have two tries left: a function for
> computing the sine of an angle and for determining the maximum of two
> numbers.

Well, those two didn't present a problem (sin x), (max x y). My
question was really about the various ways in which one might square a
number, and if there was a 'best practice' for accomplishing that.

In other words, is there any substantive difference between:
(sqr x)
(* x x)
(define (square x)
(* x x))
?

Grant Rettke

unread,
Jan 9, 2009, 12:51:10 PM1/9/09
to Study-HTDP
On Jan 9, 10:59 am, Cena Mayo <cenaz...@gmail.com> wrote:
> In other words, is there any substantive difference between:
> (sqr x)
> (* x x)
> (define (square x)
>    (* x x))
> ?

The first one communicates more information to the reader (yourself or
others), and is easier to maintain.

That is my level of interest in the topic at least :).

Cena Mayo

unread,
Jan 9, 2009, 1:25:25 PM1/9/09
to Study-HTDP
Ha, okay. I didn't have a particular interest in squaring numbers,
per se, just trying to be a completist and make sure there wasn't some
non-obvious gotcha there.

I've gone back through the group archives here and see that the group
was/is mostly made up of professional or high-level amateur coders. I
am neither. In fact, it pleased me to no end last night when I was
working on exercise 2.2.1 (Fahrenheit->Celsius) that I was able to
knock out the (working!) code in DrScheme without referring to
anything but the conversion equation. That felt like a real
accomplishment to me. :)

Anyway, thanks again, Grant and Geoff, for the help on this minor
topic!

Cena

Grant Rettke

unread,
Jan 9, 2009, 1:47:03 PM1/9/09
to Study-HTDP
Hi Cena,

> I've gone back through the group archives here and see that the group
> was/is mostly made up of professional or high-level amateur coders.  I
> am neither.  

A lot of us professionals studying HtDP are, in my opinions,
"relearning" how to program!

Additionally, there are beginners, along with experts who have
finished HtDP and even teach it now.

A mix is critical here. Thank you for joining and participating!

> In fact, it pleased me to no end last night when I was
> working on exercise 2.2.1 (Fahrenheit->Celsius) that I was able to
> knock out the (working!) code in DrScheme without referring to
> anything but the conversion equation.  That felt like a real
> accomplishment to me. :)

That *is* awesome!
Reply all
Reply to author
Forward
0 new messages