emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]


From: Phillip Lord
Subject: Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]
Date: Tue, 12 May 2020 18:21:36 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.91 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> In Clojure, a function literal is written with `#(...)`, and it supports
>> `%n` for arguments, where n=1,2,3...
>
> IIRC there's a macro somewhere providing a similar facility.
> We can't use (# ...) because the reader doesn't like `#` on its own (it
> expects it to be followed by something like a vector, a hex/binary/octal
> number, etc...).

It's not hard to do in a cheesy way. Implemented with dash.el, entirely
from a sense of mischievousness.

(defmacro fn (&rest args)
  (let ((argsd
         (--tree-map
          (cl-case it
            ('% 'x)
            (t it))
          args)))
    `(lambda (x) ,@args)))

Obviously this is not fully functional, but it works for the trivial example.

(funcall (fn %) 10)
(funcall (fn (+ 10 (/ % 2))) 50)

I can't get it to work from first position though. So:

((lambda (x) x) 10)

works, while

((fn %) 10)

doesn't.

Phil



reply via email to

[Prev in Thread] Current Thread [Next in Thread]