On Tue, 2009-09-29 at 15:51 -0700, Derick Eddington wrote:
> On Sun, 2009-09-27 at 16:59 -0500, Eduardo Cavazos wrote:
> > Now, it would be nice to be able to say:
> > 
> > (define-typed (abc #(seq "string"))
> >    (nth seq 2))
> 
> > But that has at least one problem.
> 
> > So, any suggestions for how to approach 'define-typed'?
> 
> Here's a way.  It requires coordination with the macros like nth.
> 
>   (define-syntax nth
>     [...]
>   (define-syntax define-typed
>     [...]

If I were really going to use this, I'd abstract-away the making of the
variable transformers:

  (define (make-arg-type-T id type)  ;; Needs to be in separate library.
    (make-variable-transformer
     (lambda (stx)
       (syntax-case stx (set!)
         ((_ m a ...)
          (quasisyntax (m #((unsyntax id) (unsyntax type)) a ...)))
         (_ (identifier? stx)
          id)
         ((set! _ val)
          (quasisyntax (set! (unsyntax id) val)))))))

  (define-syntax define-typed
    (lambda (stx)
      (syntax-case stx ()
        ((_ (name #(arg type) ...) . body)
         (with-syntax*
             (((t ...) (generate-temporaries (syntax (arg ...))))
              ((make ...)
               (map (lambda (x) (cons (syntax make-arg-type-T) x))
                    (syntax (((syntax t) (syntax type)) ...)))))
           (syntax
            (define (name t ...)
              (let-syntax ((arg make) ...) . body))))))))


[1] with-syntax* is:
  
  (define-syntax with-syntax*
    (syntax-rules ()
      ((_ (pc0 pc1 pc* ...) . b)
       (with-syntax (pc0)
         (with-syntax* (pc1 pc* ...) . b)))
      ((_ pc . b)
       (with-syntax pc . b))))


-- 
: Derick
----------------------------------------------------------------

Reply via email to