unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Would seq-range and seq-mapcat be useful?
@ 2015-01-29 16:54 Nicolas Petton
  2015-01-29 18:02 ` Artur Malabarba
                   ` (2 more replies)
  0 siblings, 3 replies; 34+ messages in thread
From: Nicolas Petton @ 2015-01-29 16:54 UTC (permalink / raw)
  To: emacs-devel

Hi guys,

While using seq.el, I often miss functions like seq-mapcat and
seq-range. Do you think adding such functions would be a good addition
to seq.el?

Cheers,
Nico
-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-29 16:54 Would seq-range and seq-mapcat be useful? Nicolas Petton
@ 2015-01-29 18:02 ` Artur Malabarba
  2015-01-29 22:03   ` Nicolas Petton
  2015-01-29 21:40 ` Stefan Monnier
  2015-01-30  8:20 ` What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?) Mark Oteiza
  2 siblings, 1 reply; 34+ messages in thread
From: Artur Malabarba @ 2015-01-29 18:02 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 472 bytes --]

As easy as it us to apply append mapcar, I do sometimes miss mapcat.

OTOH, as far as I can tell elisp only uses concat for strings. So I'm not
sure if the name fits.
On 29 Jan 2015 16:54, "Nicolas Petton" <nicolas@petton.fr> wrote:

> Hi guys,
>
> While using seq.el, I often miss functions like seq-mapcat and
> seq-range. Do you think adding such functions would be a good addition
> to seq.el?
>
> Cheers,
> Nico
> --
> Nicolas Petton
> http://nicolas-petton.fr
>
>
>

[-- Attachment #2: Type: text/html, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-29 16:54 Would seq-range and seq-mapcat be useful? Nicolas Petton
  2015-01-29 18:02 ` Artur Malabarba
@ 2015-01-29 21:40 ` Stefan Monnier
  2015-01-29 22:06   ` Nicolas Petton
  2015-01-30  8:20 ` What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?) Mark Oteiza
  2 siblings, 1 reply; 34+ messages in thread
From: Stefan Monnier @ 2015-01-29 21:40 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: emacs-devel

> While using seq.el, I often miss functions like seq-mapcat and
> seq-range. Do you think adding such functions would be a good addition
> to seq.el?

I have no idea what those names are supposed to evoke.  Can you tell us
what they'd do?


        Stefan



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-29 18:02 ` Artur Malabarba
@ 2015-01-29 22:03   ` Nicolas Petton
  0 siblings, 0 replies; 34+ messages in thread
From: Nicolas Petton @ 2015-01-29 22:03 UTC (permalink / raw)
  To: bruce.connor.am; +Cc: Nicolas Petton, emacs-devel


Artur Malabarba <bruce.connor.am@gmail.com> writes:

> As easy as it us to apply append mapcar, I do sometimes miss mapcat.
>
> OTOH, as far as I can tell elisp only uses concat for strings. So I'm not
> sure if the name fits.

There `vconcat' which applies to vectors :)

Nico


> On 29 Jan 2015 16:54, "Nicolas Petton" <nicolas@petton.fr> wrote:
>
>> Hi guys,
>>
>> While using seq.el, I often miss functions like seq-mapcat and
>> seq-range. Do you think adding such functions would be a good addition
>> to seq.el?
>>
>> Cheers,
>> Nico
>> --
>> Nicolas Petton
>> http://nicolas-petton.fr
>>
>>
>>

-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-29 21:40 ` Stefan Monnier
@ 2015-01-29 22:06   ` Nicolas Petton
  2015-01-30  6:09     ` Stefan Monnier
                       ` (2 more replies)
  0 siblings, 3 replies; 34+ messages in thread
From: Nicolas Petton @ 2015-01-29 22:06 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Nicolas Petton, emacs-devel


Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

> I have no idea what those names are supposed to evoke.  Can you tell us
> what they'd do?

Sure, `seq-range' would be a convenient way to create a sequence of
numbers. A simple implementation could be:

(defun seq-range (start end)
  (let ((lst nil))
    (while (< start end)
      (push end lst)
      (setq end (1- end)))
    lst))

`seq-mapcat' would apply `seq-concatenate' to the result of `seq-map':

(defun seq-mapcat (function seq &optional type)
  (apply #'seq-concatenate (or type 'list)
         (seq-map function seq)))

Cheers,
Nico
-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-29 22:06   ` Nicolas Petton
@ 2015-01-30  6:09     ` Stefan Monnier
  2015-01-30  8:00     ` Oleh Krehel
  2015-02-04 12:02     ` Ted Zlatanov
  2 siblings, 0 replies; 34+ messages in thread
From: Stefan Monnier @ 2015-01-30  6:09 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: emacs-devel

> (defun seq-range (start end)
[...]
> (defun seq-mapcat (function seq &optional type)

I don't know how useful these would be, but I don't see any problem in
adding them.


        Stefan



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-29 22:06   ` Nicolas Petton
  2015-01-30  6:09     ` Stefan Monnier
@ 2015-01-30  8:00     ` Oleh Krehel
  2015-01-30 10:21       ` Nicolas Petton
  2015-02-04 12:02     ` Ted Zlatanov
  2 siblings, 1 reply; 34+ messages in thread
From: Oleh Krehel @ 2015-01-30  8:00 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: Stefan Monnier, emacs-devel

Hi Nicolas,

On Thu, Jan 29, 2015 at 11:06 PM, Nicolas Petton <nicolas@petton.fr> wrote:

> Sure, `seq-range' would be a convenient way to create a sequence of
> numbers. A simple implementation could be:
>
> (defun seq-range (start end)
>   (let ((lst nil))
>     (while (< start end)
>       (push end lst)
>       (setq end (1- end)))
>     lst))

This is just `number-sequence' from subr.el.

Oleh



^ permalink raw reply	[flat|nested] 34+ messages in thread

* What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?)
  2015-01-29 16:54 Would seq-range and seq-mapcat be useful? Nicolas Petton
  2015-01-29 18:02 ` Artur Malabarba
  2015-01-29 21:40 ` Stefan Monnier
@ 2015-01-30  8:20 ` Mark Oteiza
  2015-01-30 10:25   ` Nicolas Petton
  2 siblings, 1 reply; 34+ messages in thread
From: Mark Oteiza @ 2015-01-30  8:20 UTC (permalink / raw)
  To: emacs-devel

Nicolas Petton <nicolas@petton.fr> writes:

> While using seq.el, I often miss functions like seq-mapcat and
> seq-range. Do you think adding such functions would be a good addition
> to seq.el?

Coincidentally, I had been thinking about additions to seq.el.  I'm
interested in having a function like Ruby's each_slice[0] method.  For
example,

    (defun seq-slice (seq n)
      "Return a list of subsequences of SEQ, each a sequence of
    length N.  The last subsequence may have less than N elements.
    
    If N is a negative integer or zero, a list containing SEQ is
    returned."
      (if (or (<= n 0)
              (>= n (seq-length seq)))
          (list seq)
        (let ((copy (seq-copy seq))
              (result '()))
          (while (not (seq-empty-p copy))
            (push (seq-take copy n) result)
            (setq copy (seq-drop copy n)))
          (nreverse result))))

I didn't think dash.el had it until I realized it is named something
else: -partition-all[1].

[0]: http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-each_slice
[1]: https://github.com/magnars/dash.el/blob/master/dash.el#L730



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30  8:00     ` Oleh Krehel
@ 2015-01-30 10:21       ` Nicolas Petton
  2015-01-30 15:38         ` Oleh Krehel
  0 siblings, 1 reply; 34+ messages in thread
From: Nicolas Petton @ 2015-01-30 10:21 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel


Oleh Krehel <ohwoeowho@gmail.com> writes:

> Hi Nicolas,
>
> On Thu, Jan 29, 2015 at 11:06 PM, Nicolas Petton <nicolas@petton.fr> wrote:
>
>> Sure, `seq-range' would be a convenient way to create a sequence of
>> numbers. A simple implementation could be:
>>
>> (defun seq-range (start end)
>>   (let ((lst nil))
>>     (while (< start end)
>>       (push end lst)
>>       (setq end (1- end)))
>>     lst))
>
> This is just `number-sequence' from subr.el.

Indeed :)

Nico
-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?)
  2015-01-30  8:20 ` What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?) Mark Oteiza
@ 2015-01-30 10:25   ` Nicolas Petton
  2015-01-30 11:09     ` seq-thread-first/last (was: What about seq-slice?) Michael Heerdegen
  2015-01-30 17:17     ` What about seq-slice? Mark Oteiza
  0 siblings, 2 replies; 34+ messages in thread
From: Nicolas Petton @ 2015-01-30 10:25 UTC (permalink / raw)
  To: Mark Oteiza; +Cc: emacs-devel

Hi Mark,

I'm not sure I understand how to use it. In which scenario would you
find `seq-slice' useful?

Nico


Mark Oteiza <mvoteiza@udel.edu> writes:

> Nicolas Petton <nicolas@petton.fr> writes:
>
>> While using seq.el, I often miss functions like seq-mapcat and
>> seq-range. Do you think adding such functions would be a good addition
>> to seq.el?
>
> Coincidentally, I had been thinking about additions to seq.el.  I'm
> interested in having a function like Ruby's each_slice[0] method.  For
> example,
>
>     (defun seq-slice (seq n)
>       "Return a list of subsequences of SEQ, each a sequence of
>     length N.  The last subsequence may have less than N elements.
>     
>     If N is a negative integer or zero, a list containing SEQ is
>     returned."
>       (if (or (<= n 0)
>               (>= n (seq-length seq)))
>           (list seq)
>         (let ((copy (seq-copy seq))
>               (result '()))
>           (while (not (seq-empty-p copy))
>             (push (seq-take copy n) result)
>             (setq copy (seq-drop copy n)))
>           (nreverse result))))
>
> I didn't think dash.el had it until I realized it is named something
> else: -partition-all[1].
>
> [0]: http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-each_slice
> [1]: https://github.com/magnars/dash.el/blob/master/dash.el#L730

-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* seq-thread-first/last (was: What about seq-slice?)
  2015-01-30 10:25   ` Nicolas Petton
@ 2015-01-30 11:09     ` Michael Heerdegen
  2015-01-30 11:59       ` Nicolas Petton
  2015-01-30 17:17     ` What about seq-slice? Mark Oteiza
  1 sibling, 1 reply; 34+ messages in thread
From: Michael Heerdegen @ 2015-01-30 11:09 UTC (permalink / raw)
  To: emacs-devel

Hello,

now that it's time for wishes: I really would like to see
seq-thread-first, seq-tread-last.  This is like thread-first/last, but
mapping over the sequence's elements.  I think it would be similarly
useful as plain thread-first/last.


Regards,

Michael




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last (was: What about seq-slice?)
  2015-01-30 11:09     ` seq-thread-first/last (was: What about seq-slice?) Michael Heerdegen
@ 2015-01-30 11:59       ` Nicolas Petton
  2015-01-30 12:08         ` seq-thread-first/last Michael Heerdegen
  2015-01-30 12:17         ` seq-thread-first/last David Kastrup
  0 siblings, 2 replies; 34+ messages in thread
From: Nicolas Petton @ 2015-01-30 11:59 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-devel

thread-first/last are not in elisp though, are they?

Nico

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Hello,
>
> now that it's time for wishes: I really would like to see
> seq-thread-first, seq-tread-last.  This is like thread-first/last, but
> mapping over the sequence's elements.  I think it would be similarly
> useful as plain thread-first/last.
>
>
> Regards,
>
> Michael

-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last
  2015-01-30 11:59       ` Nicolas Petton
@ 2015-01-30 12:08         ` Michael Heerdegen
  2015-01-30 12:21           ` seq-thread-first/last Nicolas Petton
  2015-01-30 12:17         ` seq-thread-first/last David Kastrup
  1 sibling, 1 reply; 34+ messages in thread
From: Michael Heerdegen @ 2015-01-30 12:08 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: emacs-devel

Nicolas Petton <nicolas@petton.fr> writes:

> thread-first/last are not in elisp though, are they?

Depends on your definition of "elisp".  They are in subr-x.


Michael.



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last
  2015-01-30 11:59       ` Nicolas Petton
  2015-01-30 12:08         ` seq-thread-first/last Michael Heerdegen
@ 2015-01-30 12:17         ` David Kastrup
  2015-01-30 12:25           ` seq-thread-first/last Nicolas Petton
  2015-01-30 12:33           ` seq-thread-first/last Michael Heerdegen
  1 sibling, 2 replies; 34+ messages in thread
From: David Kastrup @ 2015-01-30 12:17 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: Michael Heerdegen, emacs-devel

Nicolas Petton <nicolas@petton.fr> writes:

>> Michael Heerdegen <michael_heerdegen@web.de> writes:
>>
>>> Hello,
>>>
>>> now that it's time for wishes: I really would like to see
>>> seq-thread-first, seq-tread-last.  This is like thread-first/last, but
>>> mapping over the sequence's elements.  I think it would be similarly
>>> useful as plain thread-first/last.
>
> thread-first/last are not in elisp though, are they?

Hard to corroborate if the people mentioning their wishes don't bother
mentioning what their desired functions are supposed to do.

-- 
David Kastrup



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last
  2015-01-30 12:08         ` seq-thread-first/last Michael Heerdegen
@ 2015-01-30 12:21           ` Nicolas Petton
  0 siblings, 0 replies; 34+ messages in thread
From: Nicolas Petton @ 2015-01-30 12:21 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Nicolas Petton, emacs-devel


Michael Heerdegen <michael_heerdegen@web.de> writes:

> Nicolas Petton <nicolas@petton.fr> writes:
>
>> thread-first/last are not in elisp though, are they?
>
> Depends on your definition of "elisp".  They are in subr-x.

Oh, cool! I didn't know about it :)

Nico
-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last
  2015-01-30 12:17         ` seq-thread-first/last David Kastrup
@ 2015-01-30 12:25           ` Nicolas Petton
  2015-01-30 12:33           ` seq-thread-first/last Michael Heerdegen
  1 sibling, 0 replies; 34+ messages in thread
From: Nicolas Petton @ 2015-01-30 12:25 UTC (permalink / raw)
  To: David Kastrup; +Cc: Michael Heerdegen, Nicolas Petton, emacs-devel

David Kastrup <dak@gnu.org> writes:

>> thread-first/last are not in elisp though, are they?
>
> Hard to corroborate if the people mentioning their wishes don't bother
> mentioning what their desired functions are supposed to do.

Sorry about that. Here's the docstring of `thread-first' from subr-x.el:

Thread FORMS elements as the first argument of their successor.
Example:
    (thread-first
      5
      (+ 20)
      (/ 25)
      -
      (+ 40))
Is equivalent to:
    (+ (- (/ (+ 5 20) 25)) 40)
Note how the single `-' got converted into a list before
threading.

Cheers,
Nico
-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last
  2015-01-30 12:17         ` seq-thread-first/last David Kastrup
  2015-01-30 12:25           ` seq-thread-first/last Nicolas Petton
@ 2015-01-30 12:33           ` Michael Heerdegen
  2015-01-30 12:58             ` seq-thread-first/last Bozhidar Batsov
  1 sibling, 1 reply; 34+ messages in thread
From: Michael Heerdegen @ 2015-01-30 12:33 UTC (permalink / raw)
  To: David Kastrup; +Cc: Nicolas Petton, emacs-devel

David Kastrup <dak@gnu.org> writes:

> Hard to corroborate if the people mentioning their wishes don't bother
> mentioning what their desired functions are supposed to do.

Do you mean me?  I thought my explanation was clear.  Anyway, the
semantic would be like this:

--8<---------------cut here---------------start------------->8---

(defmacro seq-thread-first (seq &rest forms)
  (declare (indent 1))
  (let ((x (make-symbol "x")))
    `(seq-map (lambda (,x) (thread-first ,x ,@forms)) ,seq)))
--8<---------------cut here---------------end--------------->8---

though that's probably not the most efficient implementation.
seq-thread-last analog.

Example:

(seq-thread-first (number-sequence 1 3)
  (* 10) (+ 1))

==> (11 21 31)


Or was your critique about use cases?


Thanks,

Michael.



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last
  2015-01-30 12:33           ` seq-thread-first/last Michael Heerdegen
@ 2015-01-30 12:58             ` Bozhidar Batsov
  2015-01-30 14:02               ` seq-thread-first/last Artur Malabarba
  0 siblings, 1 reply; 34+ messages in thread
From: Bozhidar Batsov @ 2015-01-30 12:58 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Nicolas Petton, David Kastrup, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]

thread-first and thread-last have nothing to do with sequences, so I think
there's nothing to do about them in regards to seq.el.

On 30 January 2015 at 14:33, Michael Heerdegen <michael_heerdegen@web.de>
wrote:

> David Kastrup <dak@gnu.org> writes:
>
> > Hard to corroborate if the people mentioning their wishes don't bother
> > mentioning what their desired functions are supposed to do.
>
> Do you mean me?  I thought my explanation was clear.  Anyway, the
> semantic would be like this:
>
> --8<---------------cut here---------------start------------->8---
>
> (defmacro seq-thread-first (seq &rest forms)
>   (declare (indent 1))
>   (let ((x (make-symbol "x")))
>     `(seq-map (lambda (,x) (thread-first ,x ,@forms)) ,seq)))
> --8<---------------cut here---------------end--------------->8---
>
> though that's probably not the most efficient implementation.
> seq-thread-last analog.
>
> Example:
>
> (seq-thread-first (number-sequence 1 3)
>   (* 10) (+ 1))
>
> ==> (11 21 31)
>
>
> Or was your critique about use cases?
>
>
> Thanks,
>
> Michael.
>
>

[-- Attachment #2: Type: text/html, Size: 1591 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last
  2015-01-30 12:58             ` seq-thread-first/last Bozhidar Batsov
@ 2015-01-30 14:02               ` Artur Malabarba
  2015-01-30 14:15                 ` seq-thread-first/last Michael Heerdegen
  0 siblings, 1 reply; 34+ messages in thread
From: Artur Malabarba @ 2015-01-30 14:02 UTC (permalink / raw)
  To: Bozhidar Batsov
  Cc: Michael Heerdegen, Nicolas Petton, David Kastrup, emacs-devel

2015-01-30 12:58 GMT+00:00 Bozhidar Batsov <bozhidar@batsov.com>:
> thread-first and thread-last have nothing to do with sequences, so I think
> there's nothing to do about them in regards to seq.el.

+1



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: seq-thread-first/last
  2015-01-30 14:02               ` seq-thread-first/last Artur Malabarba
@ 2015-01-30 14:15                 ` Michael Heerdegen
  0 siblings, 0 replies; 34+ messages in thread
From: Michael Heerdegen @ 2015-01-30 14:15 UTC (permalink / raw)
  To: emacs-devel

Artur Malabarba <bruce.connor.am@gmail.com> writes:

> 2015-01-30 12:58 GMT+00:00 Bozhidar Batsov <bozhidar@batsov.com>:
> > thread-first and thread-last have nothing to do with sequences, so I think
> > there's nothing to do about them in regards to seq.el.
>
> +1

Ok, maybe it doesn't fit there so well.  Still thinking this would be
useful to add, then probably to subr-x.

Michael.




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30 10:21       ` Nicolas Petton
@ 2015-01-30 15:38         ` Oleh Krehel
  2015-01-30 15:59           ` Nicolas Richard
                             ` (2 more replies)
  0 siblings, 3 replies; 34+ messages in thread
From: Oleh Krehel @ 2015-01-30 15:38 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: Stefan Monnier, emacs-devel

On Fri, Jan 30, 2015 at 11:21 AM, Nicolas Petton <nicolas@petton.fr> wrote:
>
> Oleh Krehel <ohwoeowho@gmail.com> writes:
>
>> Hi Nicolas,
>>
>> On Thu, Jan 29, 2015 at 11:06 PM, Nicolas Petton <nicolas@petton.fr> wrote:
>>
>>> Sure, `seq-range' would be a convenient way to create a sequence of
>>> numbers. A simple implementation could be:
>>>
>>> (defun seq-range (start end)
>>>   (let ((lst nil))
>>>     (while (< start end)
>>>       (push end lst)
>>>       (setq end (1- end)))
>>>     lst))
>>
>> This is just `number-sequence' from subr.el.
>
> Indeed :)
>
> Nico
> --
> Nicolas Petton
> http://nicolas-petton.fr
>

I'd like to have this:

    (defun seq-group-by (fn lst)
      (nreverse
       (cl-reduce
        (lambda (acc it)
          (let* ((key (funcall fn it))
                 (cell (assoc key acc)))
            (if cell
                (setcdr cell (push it (cdr cell)))
              (push (list key it) acc))
            acc))
        lst
        :initial-value nil)))

    (seq-group-by
     #'car
     '(("a" 1)
       ("b" 2)
       ("b" 5)
       ("c" 1)))
    ;; (("a" ("a" 1))
    ;;  ("b" ("b" 5)
    ;;       ("b" 2))
    ;;  ("c" ("c" 1)))
    (seq-group-by
     #'cadr
     '(("a" 1)
       ("b" 2)
       ("b" 5)
       ("c" 1)))
    ;; ((1 ("c" 1)
    ;;     ("a" 1))
    ;;  (2 ("b" 2))
    ;;  (5 ("b" 5)))

Is this already somewhere?

Oleh



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30 15:38         ` Oleh Krehel
@ 2015-01-30 15:59           ` Nicolas Richard
  2015-01-30 16:04             ` Oleh Krehel
  2015-01-30 16:23           ` Nicolas Petton
  2015-02-02  0:11           ` Nicolas Petton
  2 siblings, 1 reply; 34+ messages in thread
From: Nicolas Richard @ 2015-01-30 15:59 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel

Oleh Krehel <ohwoeowho@gmail.com> writes:
> Is this already somewhere?

IDK, but I often wrote this kind of snippet for that purpose :

(defun yf/seq-group-by (fn lst)
  (let ((hash (make-hash-table :test 'equal)))
    (dolist (elm lst)
      (push elm (gethash (funcall fn elm) hash)))
    hash))

(yf/seq-group-by
 #'car
 '(("a" 1)
   ("b" 2)
   ("b" 5)
   ("c" 1)))
=> #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data
            ("a"
             (("a" 1))
             "b"
             (("b" 5)
              ("b" 2))
             "c"
             (("c" 1))))

-- 
Nicolas Richard



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30 15:59           ` Nicolas Richard
@ 2015-01-30 16:04             ` Oleh Krehel
  2015-01-30 16:05               ` Oleh Krehel
  2015-01-30 16:36               ` Nicolas Richard
  0 siblings, 2 replies; 34+ messages in thread
From: Oleh Krehel @ 2015-01-30 16:04 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel

On Fri, Jan 30, 2015 at 4:59 PM, Nicolas Richard
<theonewiththeevillook@yahoo.fr> wrote:
> Oleh Krehel <ohwoeowho@gmail.com> writes:
>> Is this already somewhere?
>
> IDK, but I often wrote this kind of snippet for that purpose :
>
> (defun yf/seq-group-by (fn lst)
>   (let ((hash (make-hash-table :test 'equal)))
>     (dolist (elm lst)
>       (push elm (gethash (funcall fn elm) hash)))
>     hash))
>
> (yf/seq-group-by
>  #'car
>  '(("a" 1)
>    ("b" 2)
>    ("b" 5)
>    ("c" 1)))
> => #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data
>             ("a"
>              (("a" 1))
>              "b"
>              (("b" 5)
>               ("b" 2))
>              "c"
>              (("c" 1))))
>
> --
> Nicolas Richard

Mine's faster:

    (defmacro util-timeit (expr)
      (let ((t-beg (float-time))
            (res (dotimes (i 10000)
                   (eval expr)))
            (t-end (float-time)))
        (/
         (- t-end t-beg)
         10000)))

    (util-timeit (yf/seq-group-by #'car tmp))
    0.0003461523771286011
    0.00033148398399353025
    0.00032957537174224856


    (util-timeit (seq-group-by #'car tmp))
    0.00019227066040039062
    0.00018899762630462645
    0.0001775247573852539



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30 16:04             ` Oleh Krehel
@ 2015-01-30 16:05               ` Oleh Krehel
  2015-01-30 16:36               ` Nicolas Richard
  1 sibling, 0 replies; 34+ messages in thread
From: Oleh Krehel @ 2015-01-30 16:05 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel

> Mine's faster:
>
>     (defmacro util-timeit (expr)
>       (let ((t-beg (float-time))
>             (res (dotimes (i 10000)
>                    (eval expr)))
>             (t-end (float-time)))
>         (/
>          (- t-end t-beg)
>          10000)))
>
>     (util-timeit (yf/seq-group-by #'car tmp))
>     0.0003461523771286011
>     0.00033148398399353025
>     0.00032957537174224856
>
>
>     (util-timeit (seq-group-by #'car tmp))
>     0.00019227066040039062
>     0.00018899762630462645
>     0.0001775247573852539

Forgot:

    (defvar tmp '(("a" ("a" 1))
                  ("b" ("b" 5)
                   ("b" 2))
                  ("c" ("c" 3))
                  ("a" ("a" 1))
                  ("b" ("b" 5)
                   ("b" 2))
                  ("c" ("c" 3))
                  ("a" ("a" 1))
                  ("b" ("b" 5)
                   ("b" 2))
                  ("c" ("c" 3))))



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30 15:38         ` Oleh Krehel
  2015-01-30 15:59           ` Nicolas Richard
@ 2015-01-30 16:23           ` Nicolas Petton
  2015-02-02  0:11           ` Nicolas Petton
  2 siblings, 0 replies; 34+ messages in thread
From: Nicolas Petton @ 2015-01-30 16:23 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel

seq-group-by seems like a good idea, thanks!

Nico


Oleh Krehel <ohwoeowho@gmail.com> writes:

> On Fri, Jan 30, 2015 at 11:21 AM, Nicolas Petton <nicolas@petton.fr> wrote:
>>
>> Oleh Krehel <ohwoeowho@gmail.com> writes:
>>
>>> Hi Nicolas,
>>>
>>> On Thu, Jan 29, 2015 at 11:06 PM, Nicolas Petton <nicolas@petton.fr> wrote:
>>>
>>>> Sure, `seq-range' would be a convenient way to create a sequence of
>>>> numbers. A simple implementation could be:
>>>>
>>>> (defun seq-range (start end)
>>>>   (let ((lst nil))
>>>>     (while (< start end)
>>>>       (push end lst)
>>>>       (setq end (1- end)))
>>>>     lst))
>>>
>>> This is just `number-sequence' from subr.el.
>>
>> Indeed :)
>>
>> Nico
>> --
>> Nicolas Petton
>> http://nicolas-petton.fr
>>
>
> I'd like to have this:
>
>     (defun seq-group-by (fn lst)
>       (nreverse
>        (cl-reduce
>         (lambda (acc it)
>           (let* ((key (funcall fn it))
>                  (cell (assoc key acc)))
>             (if cell
>                 (setcdr cell (push it (cdr cell)))
>               (push (list key it) acc))
>             acc))
>         lst
>         :initial-value nil)))
>
>     (seq-group-by
>      #'car
>      '(("a" 1)
>        ("b" 2)
>        ("b" 5)
>        ("c" 1)))
>     ;; (("a" ("a" 1))
>     ;;  ("b" ("b" 5)
>     ;;       ("b" 2))
>     ;;  ("c" ("c" 1)))
>     (seq-group-by
>      #'cadr
>      '(("a" 1)
>        ("b" 2)
>        ("b" 5)
>        ("c" 1)))
>     ;; ((1 ("c" 1)
>     ;;     ("a" 1))
>     ;;  (2 ("b" 2))
>     ;;  (5 ("b" 5)))
>
> Is this already somewhere?
>
> Oleh

-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30 16:04             ` Oleh Krehel
  2015-01-30 16:05               ` Oleh Krehel
@ 2015-01-30 16:36               ` Nicolas Richard
  2015-01-30 16:51                 ` Oleh Krehel
  1 sibling, 1 reply; 34+ messages in thread
From: Nicolas Richard @ 2015-01-30 16:36 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel

Le 30/01/2015 17:04, Oleh Krehel a écrit :
> Mine's faster:

I think it will depend on the number of keys.

(defmacro util-timeit (&rest expr)
  `(progn
     (garbage-collect) ;; avoid gc later. maybe.
     (let ((t-beg (float-time))
           (res (dotimes (i 500) ;; I reduced this a bit because I have a slow system.
                  ,@expr))
           (t-end (float-time)))
       (/
        (- t-end t-beg)
        500))))

(progn ;; use M-x compile-defun to eval this part
  (defun yf/seq-group-by (fn lst)
    (let ((hash (make-hash-table :test 'equal)))
      (dolist (elm lst)
        (push elm (gethash (funcall fn elm) hash)))
      hash))
  (defun seq-group-by (fn lst)
    (nreverse
     (cl-reduce
      (lambda (acc it)
        (let* ((key (funcall fn it))
               (cell (assoc key acc)))
          (if cell
              (setcdr cell (push it (cdr cell)))
            (push (list key it) acc))
          acc))
      lst
      :initial-value nil))))

(defun make-random-list (n)
  (let ((tmp))
    (dotimes (_ n)
      (push (cons (random 150) t) tmp)) ;; I guess only the keys matter
    tmp))

(let ((tmp (make-random-list 10)))
  (list
   (util-timeit (yf/seq-group-by #'car tmp))
   (util-timeit (seq-group-by #'car tmp))))
(3.778600692749023e-05 3.6581039428710935e-05)


(let ((tmp (make-random-list 100)))
  (list
   (util-timeit (yf/seq-group-by #'car tmp))
   (util-timeit (seq-group-by #'car tmp))))
(0.0002734408378601074 0.0005863599777221679)


(let ((tmp (make-random-list 1000)))
  (list
   (util-timeit (yf/seq-group-by #'car tmp))
   (util-timeit (seq-group-by #'car tmp))))
(0.00434891939163208 0.010494112968444824)

I wasn't really trying to compete though, just giving another point of
view.

-- 
Nico.



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30 16:36               ` Nicolas Richard
@ 2015-01-30 16:51                 ` Oleh Krehel
  0 siblings, 0 replies; 34+ messages in thread
From: Oleh Krehel @ 2015-01-30 16:51 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel

On Fri, Jan 30, 2015 at 5:36 PM, Nicolas Richard
<theonewiththeevillook@yahoo.fr> wrote:
> Le 30/01/2015 17:04, Oleh Krehel a écrit :
>> Mine's faster:
>
> I think it will depend on the number of keys.
>
> (defmacro util-timeit (&rest expr)
>   `(progn
>      (garbage-collect) ;; avoid gc later. maybe.
>      (let ((t-beg (float-time))
>            (res (dotimes (i 500) ;; I reduced this a bit because I have a slow system.
>                   ,@expr))
>            (t-end (float-time)))
>        (/
>         (- t-end t-beg)
>         500))))
>
> (progn ;; use M-x compile-defun to eval this part
>   (defun yf/seq-group-by (fn lst)
>     (let ((hash (make-hash-table :test 'equal)))
>       (dolist (elm lst)
>         (push elm (gethash (funcall fn elm) hash)))
>       hash))
>   (defun seq-group-by (fn lst)
>     (nreverse
>      (cl-reduce
>       (lambda (acc it)
>         (let* ((key (funcall fn it))
>                (cell (assoc key acc)))
>           (if cell
>               (setcdr cell (push it (cdr cell)))
>             (push (list key it) acc))
>           acc))
>       lst
>       :initial-value nil))))
>
> (defun make-random-list (n)
>   (let ((tmp))
>     (dotimes (_ n)
>       (push (cons (random 150) t) tmp)) ;; I guess only the keys matter
>     tmp))
>
> (let ((tmp (make-random-list 10)))
>   (list
>    (util-timeit (yf/seq-group-by #'car tmp))
>    (util-timeit (seq-group-by #'car tmp))))
> (3.778600692749023e-05 3.6581039428710935e-05)
>
>
> (let ((tmp (make-random-list 100)))
>   (list
>    (util-timeit (yf/seq-group-by #'car tmp))
>    (util-timeit (seq-group-by #'car tmp))))
> (0.0002734408378601074 0.0005863599777221679)
>
>
> (let ((tmp (make-random-list 1000)))
>   (list
>    (util-timeit (yf/seq-group-by #'car tmp))
>    (util-timeit (seq-group-by #'car tmp))))
> (0.00434891939163208 0.010494112968444824)
>
> I wasn't really trying to compete though, just giving another point of
> view.

You're right, of course, I was too fast to judge:).
Exactly this is why we need such a function in the ELPA / core: it
could be complex
enough to do either the alist or the hash-table approach in an optimal
way, since
the homebrew stuff is bound to be simple and work good only in some cases.

Oleh



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: What about seq-slice?
  2015-01-30 10:25   ` Nicolas Petton
  2015-01-30 11:09     ` seq-thread-first/last (was: What about seq-slice?) Michael Heerdegen
@ 2015-01-30 17:17     ` Mark Oteiza
  1 sibling, 0 replies; 34+ messages in thread
From: Mark Oteiza @ 2015-01-30 17:17 UTC (permalink / raw)
  To: emacs-devel


Nicolas Petton <nicolas@petton.fr> writes:
> Mark Oteiza <mvoteiza@udel.edu> writes:
>> Coincidentally, I had been thinking about additions to seq.el.  I'm
>> interested in having a function like Ruby's each_slice[0] method.  For
>> example,
>>
>>     (defun seq-slice (seq n)
>>       "Return a list of subsequences of SEQ, each a sequence of
>>     length N.  The last subsequence may have less than N elements.
>>     
>>     If N is a negative integer or zero, a list containing SEQ is
>>     returned."
>>       (if (or (<= n 0)
>>               (>= n (seq-length seq)))
>>           (list seq)
>>         (let ((copy (seq-copy seq))
>>               (result '()))
>>           (while (not (seq-empty-p copy))
>>             (push (seq-take copy n) result)
>>             (setq copy (seq-drop copy n)))
>>           (nreverse result))))
>>
>> I didn't think dash.el had it until I realized it is named something
>> else: -partition-all[1].
>>
>> [0]: http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-each_slice
>> [1]: https://github.com/magnars/dash.el/blob/master/dash.el#L730
>
> Hi Mark,
>
> I'm not sure I understand how to use it. In which scenario would you
> find `seq-slice' useful?

When one has a large number of things but is only "allowed" to use N of
them at a time.  For instance, a large number of usernames and an API
that limits the number of users in a single query.



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-30 15:38         ` Oleh Krehel
  2015-01-30 15:59           ` Nicolas Richard
  2015-01-30 16:23           ` Nicolas Petton
@ 2015-02-02  0:11           ` Nicolas Petton
  2015-02-02  7:49             ` Oleh Krehel
  2 siblings, 1 reply; 34+ messages in thread
From: Nicolas Petton @ 2015-02-02  0:11 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel

Oleh Krehel <ohwoeowho@gmail.com> writes:

> I'd like to have this:
>
>     (defun seq-group-by (fn lst)
>       (nreverse
>        (cl-reduce
>         (lambda (acc it)
>           (let* ((key (funcall fn it))
>                  (cell (assoc key acc)))
>             (if cell
>                 (setcdr cell (push it (cdr cell)))
>               (push (list key it) acc))
>             acc))
>         lst
>         :initial-value nil)))
>
>     (seq-group-by
>      #'car
>      '(("a" 1)
>        ("b" 2)
>        ("b" 5)
>        ("c" 1)))
>     ;; (("a" ("a" 1))
>     ;;  ("b" ("b" 5)
>     ;;       ("b" 2))
>     ;;  ("c" ("c" 1)))
>     (seq-group-by
>      #'cadr
>      '(("a" 1)
>        ("b" 2)
>        ("b" 5)
>        ("c" 1)))
>     ;; ((1 ("c" 1)
>     ;;     ("a" 1))
>     ;;  (2 ("b" 2))
>     ;;  (5 ("b" 5)))
>
> Is this already somewhere?

I don't think it is :)

I think I'm going with the following 3 additions to seq.el: `seq-mapcat',
`seq-group-by', and `seq-slice' (or `seq-partition'?).

What do you think?

Nico
-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-02-02  0:11           ` Nicolas Petton
@ 2015-02-02  7:49             ` Oleh Krehel
  2015-02-02  9:28               ` Nicolas Petton
  0 siblings, 1 reply; 34+ messages in thread
From: Oleh Krehel @ 2015-02-02  7:49 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: Stefan Monnier, emacs-devel

Nicolas Petton <nicolas@petton.fr> writes:

> Oleh Krehel <ohwoeowho@gmail.com> writes:
>
>> I'd like to have this:
>>
>>     (defun seq-group-by (fn lst)
>>       (nreverse
>>        (cl-reduce
>>         (lambda (acc it)
>>           (let* ((key (funcall fn it))
>>                  (cell (assoc key acc)))
>>             (if cell
>>                 (setcdr cell (push it (cdr cell)))
>>               (push (list key it) acc))
>>             acc))
>>         lst
>>         :initial-value nil)))
>>
>>     (seq-group-by
>>      #'car
>>      '(("a" 1)
>>        ("b" 2)
>>        ("b" 5)
>>        ("c" 1)))
>>     ;; (("a" ("a" 1))
>>     ;;  ("b" ("b" 5)
>>     ;;       ("b" 2))
>>     ;;  ("c" ("c" 1)))
>>     (seq-group-by
>>      #'cadr
>>      '(("a" 1)
>>        ("b" 2)
>>        ("b" 5)
>>        ("c" 1)))
>>     ;; ((1 ("c" 1)
>>     ;;     ("a" 1))
>>     ;;  (2 ("b" 2))
>>     ;;  (5 ("b" 5)))
>>
>> Is this already somewhere?
>
> I don't think it is :)
>
> I think I'm going with the following 3 additions to seq.el: `seq-mapcat',
> `seq-group-by', and `seq-slice' (or `seq-partition'?).
>
> What do you think?
>

I like `seq-group-by`.

I'm not sure about `seq-mapcat`, since there is `cl-mapcan` (although
it's destructive), I guess `seq-mapcat` would be fine.

And I would prefer the name `seq-partition` instead of `seq-slice`,
since `partition' is a Clojure name with same effect, and slice means
something different in Python.

Oleh



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-02-02  7:49             ` Oleh Krehel
@ 2015-02-02  9:28               ` Nicolas Petton
  2015-02-02 18:34                 ` Mark Oteiza
  0 siblings, 1 reply; 34+ messages in thread
From: Nicolas Petton @ 2015-02-02  9:28 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: Nicolas Petton, Stefan Monnier, emacs-devel


Oleh Krehel <ohwoeowho@gmail.com> writes:

> Nicolas Petton <nicolas@petton.fr> writes:
>
>> Oleh Krehel <ohwoeowho@gmail.com> writes:
>>
>>> I'd like to have this:
>>>
>>>     (defun seq-group-by (fn lst)
>>>       (nreverse
>>>        (cl-reduce
>>>         (lambda (acc it)
>>>           (let* ((key (funcall fn it))
>>>                  (cell (assoc key acc)))
>>>             (if cell
>>>                 (setcdr cell (push it (cdr cell)))
>>>               (push (list key it) acc))
>>>             acc))
>>>         lst
>>>         :initial-value nil)))
>>>
>>>     (seq-group-by
>>>      #'car
>>>      '(("a" 1)
>>>        ("b" 2)
>>>        ("b" 5)
>>>        ("c" 1)))
>>>     ;; (("a" ("a" 1))
>>>     ;;  ("b" ("b" 5)
>>>     ;;       ("b" 2))
>>>     ;;  ("c" ("c" 1)))
>>>     (seq-group-by
>>>      #'cadr
>>>      '(("a" 1)
>>>        ("b" 2)
>>>        ("b" 5)
>>>        ("c" 1)))
>>>     ;; ((1 ("c" 1)
>>>     ;;     ("a" 1))
>>>     ;;  (2 ("b" 2))
>>>     ;;  (5 ("b" 5)))
>>>
>>> Is this already somewhere?
>>
>> I don't think it is :)
>>
>> I think I'm going with the following 3 additions to seq.el: `seq-mapcat',
>> `seq-group-by', and `seq-slice' (or `seq-partition'?).
>>
>> What do you think?
>>
>
> I like `seq-group-by`.
>
> I'm not sure about `seq-mapcat`, since there is `cl-mapcan` (although
> it's destructive), I guess `seq-mapcat` would be fine.
>
> And I would prefer the name `seq-partition` instead of `seq-slice`,
> since `partition' is a Clojure name with same effect, and slice means
> something different in Python.

Yes, I felt the same.

Nico
-- 
Nicolas Petton
http://nicolas-petton.fr




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-02-02  9:28               ` Nicolas Petton
@ 2015-02-02 18:34                 ` Mark Oteiza
  2015-02-02 18:39                   ` Oleh Krehel
  0 siblings, 1 reply; 34+ messages in thread
From: Mark Oteiza @ 2015-02-02 18:34 UTC (permalink / raw)
  To: emacs-devel

Nicolas Petton <nicolas@petton.fr> writes:
> Oleh Krehel <ohwoeowho@gmail.com> writes:
>> I like `seq-group-by`.
>>
>> I'm not sure about `seq-mapcat`, since there is `cl-mapcan` (although
>> it's destructive), I guess `seq-mapcat` would be fine.
>>
>> And I would prefer the name `seq-partition` instead of `seq-slice`,
>> since `partition' is a Clojure name with same effect, and slice means
>> something different in Python.
>
> Yes, I felt the same.

Makes sense. Array slicing seems to be just taking a subsequence in a
lot of languages.  Perhaps aliasing seq-slice to seq-subseq would be
good to do.



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-02-02 18:34                 ` Mark Oteiza
@ 2015-02-02 18:39                   ` Oleh Krehel
  0 siblings, 0 replies; 34+ messages in thread
From: Oleh Krehel @ 2015-02-02 18:39 UTC (permalink / raw)
  To: Mark Oteiza; +Cc: emacs-devel

Mark Oteiza <mvoteiza@udel.edu> writes:

> Nicolas Petton <nicolas@petton.fr> writes:
>> Oleh Krehel <ohwoeowho@gmail.com> writes:
>>> I like `seq-group-by`.
>>>
>>> I'm not sure about `seq-mapcat`, since there is `cl-mapcan` (although
>>> it's destructive), I guess `seq-mapcat` would be fine.
>>>
>>> And I would prefer the name `seq-partition` instead of `seq-slice`,
>>> since `partition' is a Clojure name with same effect, and slice means
>>> something different in Python.
>>
>> Yes, I felt the same.
>
> Makes sense. Array slicing seems to be just taking a subsequence in a
> lot of languages.  Perhaps aliasing seq-slice to seq-subseq would be
> good to do.

The bad thing about aliases is that you have to remember both, so
they're not helping at all.  There will always be person A using alias A
and person B using alias B.  Both of them will have trouble to read each
others code.

This is why e.g. Python is so determined to have only way of doing
things.

Oleh



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Would seq-range and seq-mapcat be useful?
  2015-01-29 22:06   ` Nicolas Petton
  2015-01-30  6:09     ` Stefan Monnier
  2015-01-30  8:00     ` Oleh Krehel
@ 2015-02-04 12:02     ` Ted Zlatanov
  2 siblings, 0 replies; 34+ messages in thread
From: Ted Zlatanov @ 2015-02-04 12:02 UTC (permalink / raw)
  To: emacs-devel

On Thu, 29 Jan 2015 23:06:50 +0100 Nicolas Petton <nicolas@petton.fr> wrote: 

NP> Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> I have no idea what those names are supposed to evoke.  Can you tell us
>> what they'd do?

NP> Sure, `seq-range' would be a convenient way to create a sequence of
NP> numbers. A simple implementation could be:

NP> (defun seq-range (start end)
NP>   (let ((lst nil))
NP>     (while (< start end)
NP>       (push end lst)
NP>       (setq end (1- end)))
NP>     lst))

Take a look at rtree.el as well for range trees.

Ted




^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2015-02-04 12:02 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-29 16:54 Would seq-range and seq-mapcat be useful? Nicolas Petton
2015-01-29 18:02 ` Artur Malabarba
2015-01-29 22:03   ` Nicolas Petton
2015-01-29 21:40 ` Stefan Monnier
2015-01-29 22:06   ` Nicolas Petton
2015-01-30  6:09     ` Stefan Monnier
2015-01-30  8:00     ` Oleh Krehel
2015-01-30 10:21       ` Nicolas Petton
2015-01-30 15:38         ` Oleh Krehel
2015-01-30 15:59           ` Nicolas Richard
2015-01-30 16:04             ` Oleh Krehel
2015-01-30 16:05               ` Oleh Krehel
2015-01-30 16:36               ` Nicolas Richard
2015-01-30 16:51                 ` Oleh Krehel
2015-01-30 16:23           ` Nicolas Petton
2015-02-02  0:11           ` Nicolas Petton
2015-02-02  7:49             ` Oleh Krehel
2015-02-02  9:28               ` Nicolas Petton
2015-02-02 18:34                 ` Mark Oteiza
2015-02-02 18:39                   ` Oleh Krehel
2015-02-04 12:02     ` Ted Zlatanov
2015-01-30  8:20 ` What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?) Mark Oteiza
2015-01-30 10:25   ` Nicolas Petton
2015-01-30 11:09     ` seq-thread-first/last (was: What about seq-slice?) Michael Heerdegen
2015-01-30 11:59       ` Nicolas Petton
2015-01-30 12:08         ` seq-thread-first/last Michael Heerdegen
2015-01-30 12:21           ` seq-thread-first/last Nicolas Petton
2015-01-30 12:17         ` seq-thread-first/last David Kastrup
2015-01-30 12:25           ` seq-thread-first/last Nicolas Petton
2015-01-30 12:33           ` seq-thread-first/last Michael Heerdegen
2015-01-30 12:58             ` seq-thread-first/last Bozhidar Batsov
2015-01-30 14:02               ` seq-thread-first/last Artur Malabarba
2015-01-30 14:15                 ` seq-thread-first/last Michael Heerdegen
2015-01-30 17:17     ` What about seq-slice? Mark Oteiza

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).