[plt-scheme] Scheme Programming Question (Making an error message)

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Oct 5 14:11:53 EDT 2008

Correct: this could be couched in the language of HtDP 7.5(?) on errors:

  Suppose you want to enforce the contract for reverse. You could  
proceed as in 7.5:

    ;; Any -> [Listof Any]
    ;; reverse the given list
    ;; effect: signal an error for non-lists
    (define (checked-reverse l)
      (cond
        [(list? l) (reverse-list l)]
        [else (error 'reverse "proper list expected, given ~e" l)]))

  This would, however, have the disadvantage that checked-reverse  
must traverse
  proper lists _twice_. Is it possible to issue the same error  
message without
  traversing the list twice? Put differently, design the function  
reverse as
  specified above without using list?.

-- Matthias







On Oct 5, 2008, at 12:59 PM, Prabhakar Ragde wrote:

> Shriram wrote:
>
>> PS: What I'd really like to know is what crackpot professor put out
>>     a question like this.  Any ideas?
>
> The basic concept of the question is fine, though it could be  
> phrased much better (clearly the author has not heard of HtDP). But  
> regardless of any infelicities, I'm sure the author would be  
> interested in knowing the ways in which their students are  
> attempting to solve the question... --PR
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.