Re: Syntax for identifier syntax Lassi Kortela 03 Mar 2020 13:42 UTC
> (define-syntax + > (lambda (stx) > (syntax-case stx () > ((_ x y) #'(fast-binary-plus x y)) > (_ #'slow-general-plus)))) > > Except that it will now be impossible to use (apply + '(1 2 3 4)), > unless you have a non-standard Scheme that allows both syntax and > variable bindings for the same identifier. I don't understand this. If the identifier syntax expands to a lambda, does something in Scheme prevent you from passing that lambda to `apply`? Or is `+` not macro-expanded in that position inside `apply`? > Being able to apply > procedures to a programmatically generated list of arguments is a > standard and important part of functional languages. In addition, it > becomes impossible to put + into a data structure. Agree that these are extremely important. > CL has this feature, named "compiler macros"; they override a function > binding in the compiler, but do not affect any use of the function > object at run time. From what I understand, they are not heavily used. They are perhaps even more of a a last resort than macros in general. IIRC the SICL implementation bases a substantial part of its internals on compiler macros, but don't quote me (no pun intended).