[racket] Semaphore obscurities

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Wed Sep 26 17:09:06 EDT 2012

On 09/26/2012 04:46 PM, Norman Gray wrote:
>
> Greetings
>
> The behaviour of call-with-semaphore doesn't appear to match the
> documentation, or else I'm misunderstanding the documentation.
>
> Consider:
>
> (define (printit m)
>    (printf "msg begin:~a~%" m))
> (define try
>    (let ((sema (make-semaphore 1)))
>      (λ (msg)
>        (call-with-semaphore sema
>                             printit
>                             ;#f
>                             msg))))
> (try "second")
>
> With #f commented out, I get (with Racket 5.3):
>
> call-with-semaphore: procedure arity does not match extra-argument count
>    procedure: #<procedure:printit>
>    extra-argument count: 0
>>
>
> With #f uncommented, it works as expected:
>
> Welcome to DrRacket, version 5.3 [3m].
> Language: racket; memory limit: 128 MB.
> msg begin:second
>>
>
> The documentation says:
>
> (call-with-semaphore	 	sema	 	 	 	
>   	 	proc	 	 	 	
>   	 [	try-fail-thunk]	 	 	 	
>   	 	arg ...)	 	→	 	any
>
> However it appears that the try-fail-chunk argument is not in fact optional.

Here's what the documentation means: There must be at least two 
arguments. The first two arguments are 'sema' and 'proc'. If there are 
three or more arguments, the third argument is 'try-fail-thunk'. If 
there are four or more arguments, all arguments starting with the fourth 
argument are collected in a list for the 'args' rest argument.

> ----
>
> Separately, it appears that CALL-WITH-SEMAPHORE returns the value
> that (proc args…) returns.  However the documentation doesn't
> actually say that.  Is that just an oversight, or is the return value
> of CALL-WITH-SEMAPHORE undefined?

It's probably an oversight.

Ryan


Posted on the users mailing list.