[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Short functions (was: [elpa] externals/consult 4aa49ee324 3/5: consult--
From: |
Stefan Monnier |
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 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
>> 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
- Re: [elpa] externals/consult 4aa49ee324 3/5: consult--async-pipeline: Convert to function, Stefan Monnier, 2025/01/06
- Re: [elpa] externals/consult 4aa49ee324 3/5: consult--async-pipeline: Convert to function, Daniel Mendler, 2025/01/06
- Short functions (was: [elpa] externals/consult 4aa49ee324 3/5: consult--async-pipeline: Convert to function),
Stefan Monnier <=
- Re: Short functions (was: [elpa] externals/consult 4aa49ee324 3/5: consult--async-pipeline: Convert to function), Daniel Colascione, 2025/01/06
- Re: Short functions, Stefan Monnier, 2025/01/06
- Re: Short functions, Daniel Colascione, 2025/01/06
- Re: Short functions, Daniel Mendler, 2025/01/06
- Re: Short functions, Daniel Colascione, 2025/01/06