Hello,
Consider this 'nth' macro:
(define-syntax nth
(syntax-rules ()
((nth #(symbol "list") i)
(list-ref symbol i))
((nth #(symbol "vector") i)
(vector-ref symbol i))
((nth #(symbol "string") i)
(string-ref symbol i))))
As it's first argument, it expects a "type annotated" symbol. A few
examples:
(let ((seq '(a b c d e f)))
(nth #(seq "list") 2))
c
(let ((seq '#(a b c d e f)))
(nth #(seq "vector") 2))
c
(let ((seq "abcdef"))
(nth #(seq "string") 2))
#\c
In return for specifying the type, the dispatch happens at expand time.
Here's an example use inside a procedure definition:
(define (abc seq)
(nth #(seq "string") 2))
(abc "abcdef")
#\c
Now, it would be nice to be able to say:
(define-typed (abc #(seq "string"))
(nth seq 2))
Each instance of 'seq' in the body would have to expand to a type
annotated symbol. It seems like this should be possible with
identifier-syntax or make-variable-transformer.
A naive sketch of (one possible approach to) the expansion of a
'define-typed' macro is:
(define abc
(lambda (x)
(define-syntax y (identifier-syntax #(x "string")))
(nth y 2)))
But that has at least one problem. 'nth' itself is a macro and it seems
that 'y' isn't defined "in time".
So, any suggestions for how to approach 'define-typed'?
Ed