[plt-scheme] define/public doesn't like my macro

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jun 8 06:34:15 EDT 2006

At Thu, 8 Jun 2006 11:17:30 +0100, "Paulo J. Matos" wrote:
> I usually have to define a function which depends on the type of the
> first argument so I sketched the following macro a long time ago which
> is part of my utils and have been using without problems:
> [...]>
> Now I'm trying to use it inside a method:
> [...]
> This works... a private method but this...
> (define/public test
>         (type-lambda (x)
>                      (string? (lambda () "String"))
>                      ((lambda (t) #t) (lambda () "Something else"))))
> 
> doesn't!

It works for me; below is the complete program that I ran (in MzScheme)
to try it. What's different in your run?

Matthew

----------------------------------------

(require (lib "list.ss")
	 (lib "class.ss"))

(define-syntax type-lambda
  (syntax-rules ()
    [(type-lambda (arg ...) (p l) ...)
     (lambda (arg ...)
       (let ([testarg (first (list arg ...))])
	 (let loop ([preds (list p ...)]
		    [thunks (list l ...)])
	   (cond [(null? preds)
		  (error 'type-lambda
			 "No predicate passed was able to handle: ~a~n"
			 testarg)]
		 [((first preds) testarg)
		  ((first thunks))]
		 [else
		  (loop (rest preds)
			(rest thunks))]))))]))

(define c%
  (class object%
    (define/public test
      (type-lambda (x)
		   (string? (lambda () "String"))
		   ((lambda (t) #t) (lambda () "Something else"))))
    (super-new)))

(send (new c%) test "Hi")



Posted on the users mailing list.