[racket] How to read procedure documentation?

From: Manfred Lotz (manfred.lotz at arcor.de)
Date: Sat Apr 20 10:40:17 EDT 2013

On Sat, 20 Apr 2013 10:19:54 -0400
Matthias Felleisen <matthias at ccs.neu.edu>
wrote:

> 
> On Apr 20, 2013, at 12:37 AM, Manfred Lotz wrote:
> 
> > My understanding is that parameter path-string? will be
> > checked at run time but only if the programmer who coded e.g.
> > file->string did call path-string?. 
> 
> 
> No, the function will check pathness. Try file->string with a string
> that contains \0.

Either I did not understand or I just did not express myself correctly.

file->string uses file->x
 
  (define (file->string f #:mode [mode 'binary])
    (file->x 'file->string f mode read-string string-append))
  .....
and file->x 

  (define (file->x who f file-mode read-x x-append)
    (check-path who f)
  .....

checks explicitly for path-string? via check-path

  (define (check-path who f)
    (unless (path-string? f)
      (raise-argument-error who "path-string?" f)))


If the programmer would have forgotten to code check-path in file->x
then there would be no check. Therefore my understanding is that the
language itself cannot enforce the predicate (as it has not a type
system like Haskell or Ocaml). This is that enforcement of the
predicate relies on proper programming.

Or did I miss anything?


-- 
Manfred
 







Posted on the users mailing list.