[plt-scheme] Re: Poacher turned gamekeeper

From: Laurent (laurent.orseau at gmail.com)
Date: Thu Nov 12 08:43:58 EST 2009

with string-append, you can perform a test (string?) beforehand to know if
it will crash or not (and avoid the crash).
with string->number, the test can "only" (means: this is the simplest way)
be done by that same function, so it can be used as either a tester or a
transformer, a bit like member for example.

On Thu, Nov 12, 2009 at 14:38, wooks <wookiz at hotmail.com> wrote:

>
>
> On Nov 12, 1:01 pm, Nadeem Abdul Hamid <nad... at acm.org> wrote:
> > You could try asking a student to be the function -- tell them you'll
> > give them a sequence of digits (or write them on the board) and they
> > have to read back to you the number. Try it with some 3 and 4 digit
> > numbers; then give them something like  "13z5". Hopefully, they'll say
> > something like "that's not a number"; Try with a couple more valid
> > sequences of digits; then another invalid one. Point out to them, that
> > when they are given something not a number, then they are deciding
> > somehow what a suitable response is -- "false" is just an easy,
> > abbreviated way of indicating the "not a number" case -- because it
> > wouldn't make sense to read back some arbitrary number if given
> > something like "13z5." I don't think you want to overkill this issue
> > at this point -- just make it seem intuitively sensible and move on.
>
> Hmmm. This will come right after the example of string-append that
> crashes when given a numeric argument.....
>
> I guess it's an early exposure to the need to look up a fucnctions
> contract specification - sometimes you can intuit and sometimes you
> need to look it up.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20091112/58d7f07f/attachment.html>

Posted on the users mailing list.