[BULK] [plt-scheme] Teaching Scheme

From: Shriram Krishnamurthi (sk at cs.brown.edu)
Date: Mon May 3 10:53:15 EDT 2010

Dear Samuel,

It might also be considered a strength to compute rather than print,
and teaching programming by showing printf's might be considered a
weaknesses.

[Note: I use "might be" in a strained effort to be polite.  If I were
being more honest, I'd say the alternatives you suggest are slightly
brain-damaged.]

Shriram

On Mon, May 3, 2010 at 7:44 AM, Samuel Williams
<space.ship.traveller at gmail.com> wrote:
> Dear Shriram,
>
> In an effort to be equivalent to all the other implementations, it would be great to write the values to stdout in the same format.
>
> If this isn't possible with Scheme, thats fine, but it might be considered a weakness. Lots of people want to print something out, either for debugging purposes or simply to see intermediate results of processing. It is a very common way of teaching programming at present.
>
> This might not be the best way to debug Scheme (I'm not a Scheme programmer) but if this is the case then it will be important to discuss this on the page about Scheme, especially as a potential reason why someone would want to use Scheme.
>
> Kind regards,
> Samuel
>
> On 4/05/2010, at 2:31 AM, Shriram Krishnamurthi wrote:
>
>> Functions compute values.  They don't print output.
>>
>> On Mon, May 3, 2010 at 7:26 AM, Samuel Williams
>> <space.ship.traveller at gmail.com> wrote:
>>> Dear Stephen,
>>> Can you let me know firstly which function is responsible for printing the
>>> output?
>>> Secondly, can you add comments explaining how it works? I can generally
>>> appreciate what you are doing, but I'm not a Scheme programmer so I might
>>> not understand the exact detail correctly.
>>> Thanks
>>> Samuel
>>> On 4/05/2010, at 1:01 AM, Stephen Bloch wrote:
>>>
>>> Well, that particular algorithm relies very heavily on mutation, but here's
>>> a functional version.
>>> (define (door-open door)
>>>   (doh door 99))
>>> (define (doh door pass)
>>>   (cond [(zero? pass) true]
>>>         [(= (remainder door (+ pass 1)) pass)
>>>          (not (doh door (- pass 1)))]
>>>         [else
>>>          (doh door (- pass 1))]))
>>> (define doors (build-list 100 door-open))
>>>
>>>
>>> Somewhat shorter but more cryptic:
>>> (define (door-open door)
>>>   (doh door 99))
>>> (define (doh door pass)
>>>   (or (zero? pass)
>>>       (not (boolean=? (= (remainder door (+ pass 1)) pass)
>>>                       (doh door (- pass 1))))))
>>> (define doors (build-list 100 door-open))
>>>
>>>
>>> Even shorter, but takes some math (and illustrates how artificial this
>>> problem is :-) :
>>> (define (door-open door)
>>>    (integer? (sqrt (+ door 1))))
>>> (define doors (build-list 100 door-open))
>>>
>>>
>>> Stephen Bloch
>>> sbloch at adelphi.edu
>>>
>>>
>>>
>>>
>>> _________________________________________________
>>>  For list-related administrative tasks:
>>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>>
>>>
>
>


Posted on the users mailing list.