polymorphism - Scheme define-macro and/or define-syntax -


i want create overloaded scheme macro simple form of polymorphism. is, macro smart enough expand differently when given params of different types, (look-up key container) "right" thing different kinds of containers.

(define-macro (look-up key container)   (cond     ((table? container) `(table-ref ,key ,container))     ((pair? container) `(assoc ,container ,key))       etc.     (else `(error "unknown type look-up)))) 

ideas?

i think chris right in not job macros. simple procedure might you're looking for:

(define (lookup key container)   (cond ((type1? container)            (type1-lookup key container))          .                                 ; repeat whichever types..          .         ((typen? container)            (typen-lookup key container))         (else 'undefined-lookup)))         ; or default value or ... 

or maybe need find out you're dealing once can build build more dedicated procedure on fly. make-lookup procedure might similar code above, except return procedure, rather call lookup right away:

(define (make-lookup container)   (cond ((type1? container)            type1-lookup)          .                                 ; repeat supported types..          .         ((typen? container)            typen-lookup)         (else default-lookup-procedure)))  (define lookup (make-lookup container)) 

you add optional argument make-lookup take procedure , use rather 1 of type-specific lookups defined.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -