"The "sufficiently smart compiler" argument
 comes to mind: if the arglist of a function is known, then surely
the
 compiler should be able to automatically translate named/keyword
 arguments into an appropriate simple call?"

That is exactly what motivated me to write this macro.  I was pretty
sure keyword args could be optimized to exactly the same as positional
arguments without much difficulty (although this macro took me an
embarrassingly long time to write!).  I wish there was a way to hook
the reader so that the macro could be called implicitly.  It seems
that the metadata facility would be a perfect solution to this.  If I
tag some symbol with metadata {:interpreter named-call}, for example,
the reader should delegate to the macro named-call.

On Jul 16, 7:10 pm, Richard Newman <holyg...@gmail.com> wrote:
> > Even if the macro isn't all that valuable, I learned a lot
> > about Clojure in the process.  If anyone has any suggestions, I'd love
> > to hear them.
>
> This is definitely interesting to me.
>
> I currently use the keyword arg idiom -- (apply hash-map args) -- but  
> I'm painfully aware of all the additional work that goes in and might  
> not be optimized by the compiler. I also miss some of the  
> functionality of Common Lisp keyword arguments: default values (flawed  
> though they are), explicit keyword checking, and so on.
>
> Having worked on some performance-sensitive CL projects, I'm aware of  
> some patterns that tend to arise; things like
>
> (defun %some-function (x y z a b c d e)
>    ;; I have a horrible arglist, but I'm fast to call.
>    ;; My args are probably stack-allocated.
>    ...)
>
> (defun some-function (x &key y z a b c d e)
>    ;; I'm much prettier, but calling me in a loop can chew up 5%
>    ;; of your runtime just futzing with keyword args, particularly
>    ;; with more complex arglists.
>    ;; I probably call %some-function, maybe with some transformations.
>    ...)
>
> (define-compiler-macro some-function (&whole whole x &key y z a b c d e)
>    ;; Do constant analysis to turn simple calls into direct
>    ;; calls to %some-function instead of some-function.
>    `(%some-function x y z a b c d e))
>
> This gives you the expressiveness of keyword arguments, but improves  
> speed in the common case. The downside is that it's a headache  
> (writing compiler macros is challenging), verbose, and seems like it  
> should be unnecessary. The "sufficiently smart compiler" argument  
> comes to mind: if the arglist of a function is known, then surely the  
> compiler should be able to automatically translate named/keyword  
> arguments into an appropriate simple call?
>
> To me it seems like you've basically defined a kind of generic  
> compiler macro invoked by an expression at the call site (because  
> Clojure doesn't have such a thing). That technique is interesting, and  
> could certainly be useful within a single codebase, but unfortunately  
> I have doubts about its adoption.
>
> There's also the matter that CL's compiler macros are (AFAICS) more  
> expressive -- e.g., I believe CL's understanding of constant forms  
> within an environment gives it an edge, even being able to completely  
> compute a result. (I've written a compiler macro in the past that  
> actually does some textual parsing when the calling code is compiled,  
> rather than at runtime; in principle this could turn your code  
> directly into a function that errors, or even returns the only  
> possible answer, rather than doing any work. Pretty cool.)
>
> Great job though... I'd really value a lively discussion on this  
> topic :)
>
> -R
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to