all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Daniel Mendler <mail@daniel-mendler.de>
Cc: emacs-devel@gnu.org
Subject: Short functions (was: [elpa] externals/consult 4aa49ee324 3/5: consult--async-pipeline: Convert to function)
Date: Mon, 06 Jan 2025 11:52:12 -0500	[thread overview]
Message-ID: <jwvbjwjgb0e.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87cygz7wl8.fsf@daniel-mendler.de> (Daniel Mendler's message of "Mon, 06 Jan 2025 17:09:39 +0100")

>> Hmm... Haskell/OCaml have `foldr` and `foldl`, maybe we should also have
>> `reduceR` and `reduceL`.
> Yes, please. seq-reduce-right/left would be nice to have. See also
> cl-reduce which has :from-end.

FWIW, I can never remember which is "right" and which is "left", so
I much prefer the "from end" kind of terminology.
Combined with the existence of `seq-reduce`, that would suggest the use
of `seq-reduce-from-end`.

[ This said, when the sequence is a list as is presumably the case here,
  as long as it's coded in ELisp I suspect the most efficient solution
  is to `reverse` and then do `seq-reduce`, just like you did.  To be
  more efficient, we'd want to avoid both heap allocation and recursion,
  but sadly from ELisp the only way to allocate non-heap memory is via
  recursion.  At the bytecode level there's some limited support for
  stack allocation but it's limited by the fact that the max size has to
  be declared in the bytecode object and that this max size is
  pre-allocated (so it can't be made ridiculously large).  ]

> There is also a lack in some combinators (flip, curry, uncurry, ...)
> which are occasionally useful. Also papply and rpapply, since
> apply-partially lacks conciseness and sometimes one wants apply the
> arguments to the right. Same with cl-constantly.
>
> (papply #'f x)
> (apply-partially #'f x)
> (lambda (y) (f x y))
> (lambda (y z) (f x y z))
>
> (lambda (_) x)
> (constantly x)
> (lambda (_ _) x)
> (cl-constantly x)

I think you're arguing for something like `llama`s ## or to expand #'
to allow things like:

    #'(f x _)
    #'(f x _ _)
    #'(f x . _)
    #'(_ → x)
    #'(_ _ → x)

Then again, there's

    (λ (y) (f x y))
    (λ (y z) (f x y z))
    (λ (_) x)
    (λ (_ _) x)

I'm interested to add new meanings to `function` (aka #') but mostly for
things like:

    #'(setf foo)
    #'(peg foo)

to refer to the setters or the peg-matchers of a given name.  It could
also be used for

    #'(cl-lambda ...)

instead of the hideous

    (cl-function (lambda ...))

tho this one completely depends on the reason (that completely escapes
me) for the use of a `cl-function` macro instead of a `cl-lambda` macro.


        Stefan




  reply	other threads:[~2025-01-06 16:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <173617561349.1583674.17727386803499537943@vcs3.savannah.gnu.org>
     [not found] ` <20250106150015.2A1DD1043A07@vcs3.savannah.gnu.org>
2025-01-06 15:55   ` [elpa] externals/consult 4aa49ee324 3/5: consult--async-pipeline: Convert to function Stefan Monnier
2025-01-06 16:09     ` Daniel Mendler via Emacs development discussions.
2025-01-06 16:52       ` Stefan Monnier [this message]
2025-01-06 16:57         ` Short functions (was: [elpa] externals/consult 4aa49ee324 3/5: consult--async-pipeline: Convert to function) Daniel Colascione
2025-01-06 17:25           ` Short functions Stefan Monnier
2025-01-06 17:32             ` Daniel Colascione
2025-01-06 17:02         ` Daniel Mendler via Emacs development discussions.
2025-01-06 17:13           ` Daniel Colascione

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvbjwjgb0e.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=mail@daniel-mendler.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.