Am Di., 3. März 2020 um 14:42 Uhr schrieb Lassi Kortela <xxxxxx@lassi.io>:
>     (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`?

I don't understand this either. `+' will be macro-expanded in that position inside `apply' and the code `(apply + '(1 2 3 4))' simply works.

 

> 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.

Fortunately, by design, it just works.  One can certainly say a few things against R6RS, but its macro system has been devised by ingenious people and is well-thought of.

The optimization above is completely transparent to the user of the procedure.
 

> 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).