[plt-scheme] create name with syntax-case
Hi Marijn,
> I would like to know how I should change the following snippet such that it
> will define the 4 functions implementation->eval-command
> implementation->interpret-command implementation->compile-command and
> implementation->run-compiled-command.
>
> (define-syntax define-accessor
> (lambda (x)
> (syntax-case ()
> ((_ field position)
> (define (implementation->field implementation)
> (let ((entry (hash-table-ref/default database implementation #f)))
> (if entry (vector-ref entry position) (error "no such
> implementation known!"))))))))
Something like:
(define-syntax (define-accessor stx)
(syntax-case stx ()
[(_ field position)
(identifier? #'field)
(with-syntax ([implementation->field
(datum->syntax-object
stx (string->symbol
(format "implementation->~a"
(syntax-e #'field))))])
#'(define (implementation->field implementation)
(let ((entry (hash-table-ref/default
database implementation #f)))
(if entry (vector-ref entry position)
(error "no such implementation known!")))))]))
But you forgot to post runnable test examples.
--
Jens Axel Søgaard