[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: |
Alfred M. Szmidt |
Subject: |
Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs] |
Date: |
Sat, 09 May 2020 19:21:18 -0400 |
> I understand, and I wasn't really expecting an example so soon, so
> thank you for taking the time to do it. I was hoping for examples of
> the more complicated constructs, like the threading ones not the
> anaphoric variants.
I think I need your help here. About the threading ones, can you look
at the few examples at
https://github.com/magnars/dash.el#--x-optional-form-rest-more and
tell me what you need more?
They are very trivial examples, they don't really show how people use
it in actual code which is I think where we could have an interesting
comparison. I'd like to see something more "real world" -- something
that would be hard, or annoying to do in Emacs Lisp.
(-> '(2 3 5)) ;; => '(2 3 5)
'(2 3 5)
(-> '(2 3 5) (append '(8 13))) ;; => '(2 3 5 8 13)
(append '(2 3 5) '(8 13))
(-> '(2 3 5) (append '(8 13)) (-slice 1 -1)) ;; => '(3 5 8)
(subseq (append '(2 3 5) '(8 13)) 1 -1)
The threading macros are useful when you'll "cascade" arguments into a
bunch of function. See it as a better and more flexible `let*`, for
example:
(let* ((lst '(1 2 3))
(lst-square (-map 'square lst))
(lst-square-reverse (-reverse lst-square)))
(pp lst-square-reverse))
Why even use let*? (-reverse (-map 'square '(1 2 3)))
In these cases, I see absolutley no benefit of using ->, it just makes
it more "magical" for no particular reason.
And you can individually extract a form (which is useful when
debugging), and it will have some meaning, take (-slice 1 -1). The
function is described as (-slice LIST FROM &optional TO STEP) .. but 1
isn't a list!
> I guess it is because you are more used to the abstraction level. I
> find the later to be much more natural to write. It also lends it
> self much easier (I think) if you wish to modify it at some later
> point, e.g., you put the lambda in a function.
Yes, it's hard ot make this example shine because it's too simple. It
was probably a poor example to begin with, still my point was that
"(map-when pred rep list)" speaks more to me than "use mapcar and pass
a lambda containing an if to it". Just by seeing the signature I know
what to do.
Polish speaks more to me than English, we all have our preferences and
have to adjust when we speak or write in a different language. Which
is why it is important to see things through the intended lense -- in
this case, Emacs Lisp. Your example of using -slice instead of subseq
is one such example -- I cannot assume that the word miasto will exist
in English and mean city.
> Why even do that! You could just use `delq`:
>
> (delq 2 '("1" 2 "3" 4))
What if the list contains elements not comparable with `eq` or `=` ?
Everything is comparable using eq; but if you wish to strings content
or fixnums specifically then remove-if would be a better choice with
the correct predicate..
> flatten-list?
Nice. Why isn't this function findable using `C-h f` in Emacs 26.3? I
tested with emacs -Q, and I even tried to load `subr` and `subr-x`.
It was added in 27.1.
Anway, I hope you understand now that the point is not that Emacs
doesn't have such functions, is that there's no centralized place
where you have the exact short list of functions related to a topic.
That is the purpose of the Emacs Lisp manual.
Using prefixes like in dash or s.el allows for easy discoverability
using `C-h f`.
Prefixes can help in that, sometimes but not always, since sometimes
another prefix might make more sense. But neither `-' nor `s' is a
good prefix for discoverability.
We'd be getting close to it by writing some mode that parses
https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html
and grep for `-- function` and list these in a grouped manner like
dash/s.el does. I might get around to start doing this if time allows.
That would be great!
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], (continued)
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Philippe Vaucher, 2020/05/09
- discoveribility [Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]], Alfred M. Szmidt, 2020/05/09
- Re: discoveribility [Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]], Yuri Khan, 2020/05/09
- Re: discoveribility [Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]], Philippe Vaucher, 2020/05/09
- Re: discoveribility [Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]], Philippe Vaucher, 2020/05/09
- Re: discoveribility [Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]], Alfred M. Szmidt, 2020/05/09
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Richard Stallman, 2020/05/09
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Philippe Vaucher, 2020/05/09
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Alfred M. Szmidt, 2020/05/09
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Philippe Vaucher, 2020/05/09
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs],
Alfred M. Szmidt <=
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Joost Kremers, 2020/05/09
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Alfred M. Szmidt, 2020/05/09
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Dmitry Gutov, 2020/05/09
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Richard Stallman, 2020/05/10
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Joost Kremers, 2020/05/11
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], tomas, 2020/05/11
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Philippe Vaucher, 2020/05/11
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], tomas, 2020/05/11
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], Philippe Vaucher, 2020/05/11
- Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs], 조성빈, 2020/05/11