Summary

get-keyword fails to operate correctly if keywords in first and second arguments come from different environments

Metadata

Description

Run the following code in csi, and you'll get a failed assertion:

 (define-syntax keyword-from-syntax (syntax-rules () ((_) #:k)))
 (assert (get-keyword (keyword-from-syntax) '(h i j #:k l)))

This should return l, but instead it returns #f. The bug occurs when a keywords from different environments are compared; the #:k from the syntax-rules is not being treated as equal to the #:k from the normal code for some reason.

A working replacement (and the replacement I use in my code) could be as follows:

 (define (get-keyword kw args . default)
   (let (
     (tail (memq kw args))
   )
     (if (and tail (not (null? (cdr tail))))
       (cadr tail)
       (if (null? default)
         #f
         ((car default))
       )
     )
   )
 )