Email list hosting service & mailing list manager

fixnum macros vs procedures Per Bothner (15 May 2017 05:22 UTC)
Re: fixnum macros vs procedures John Cowan (15 May 2017 15:29 UTC)
Re: fixnum macros vs procedures Per Bothner (15 May 2017 16:28 UTC)
Re: fixnum macros vs procedures John Cowan (15 May 2017 16:40 UTC)
Re: fixnum macros vs procedures Shiro Kawai (15 May 2017 22:27 UTC)
Re: fixnum macros vs procedures Alex Shinn (17 May 2017 10:34 UTC)
Re: fixnum macros vs procedures John Cowan (17 May 2017 12:00 UTC)

Re: fixnum macros vs procedures Per Bothner 15 May 2017 16:27 UTC

On 05/15/2017 08:29 AM, John Cowan wrote:
>
> On Mon, May 15, 2017 at 1:22 AM, Per Bothner <xxxxxx@bothner.com <mailto:xxxxxx@bothner.com>> wrote:
>
>     Why would anyone ever want to use fx+ *except* in a procedure call?
>
>
> I think an obvious candidate would be:
>
> (s16-vector-map fx+ a-long-vector-of-shorts another-long-vector-of-shorts>
> where you want to eliminate the dispatch overhead of + on a system without type inference.

That would be useful - but it would be even harder to optimize.  Though if s16-vector-map
is inlined to a loop, then the fx+ call could be optimized.

> I've been thinking more and more and I think (contrary to my general preference for conservative, particularizing solutions) that what we need for operations like fx+ is Common Lisp's define-compiler-macro.  This allows the user to declare a syntax keyword for an identifier that already has an ordinary definition.  In keyword position, the macro is used; in any other position, the variable is used.  This basically allows users to write their own compiler optimizations.

That wouldn't help optimize the s16-vector-map call above.

Kawa does have a mechanism for optimizing calls to known functions at a later
stage, when type information is available, using a 'validate-apply' procedure property.
It's more work to write custom "validate" function, but not too bad.  (See some
examples in kawa/lib/compile_misc.scm and compile_map.scm.)

If there were Kawa validate-apply functions for fx+ *and* for s16-vector-map then Kawa
would be able to inline the above s16-vector-map.  (Some of the existing map procedures
are already inlined to loops, so an optimizer for s16-vector-map would be easy.)

> After brainstorming with a cow orker, we like the name "define-overloaded-syntax".  I don't think it's necessary to have local versions of this, but I don't object to having them.

The idea is useful - not sure about the name.

I'd want to be able to use the macro to define the function:

(define-overloaded-syntax fx+ ...)
(define (fx+ x y) (fx+ x y))

--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/