[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#21782: 25.0.50; New functions nfront/front
From: |
Tino Calancha |
Subject: |
bug#21782: 25.0.50; New functions nfront/front |
Date: |
Fri, 30 Oct 2015 10:25:31 +0900 (JST) |
User-agent: |
Alpine 2.20 (LRH 67 2015-01-07) |
I think this is already available in core as seq-take, from the seq package.
Thank you, you are right. Indeed, I found seq-take very nice:
its more general because apply to sequences.
There is one small difference: seq-take has no optional arguments.
In addition, seq.el need to be loaded by the user. Yeah, not a big
deal, but IMO such fundamental operation on a list as nfront
implement, deserve to be available at the starting of the session.
Putting a dedicated function in subr.el we save to load many stuff from
seq.el that maybe we dont need.
I would like nfront/front would behave as nbutlast/butlast concerning
the N argument:
*) N nil giving same output as N = 1.
*) N <= 0 return the full list.
(I choose the name of the function to somehow reflect such symmetry).
I have modified my patch to accomplish such behaviour.
With the new patch
(let ((ltest '(1 2 3 4 5 6)))
(nbutlast ltest nil))
(1 2 3 4 5)
(let ((ltest '(1 2 3 4 5 6)))
(nfront ltest nil))
(1)
(require 'seq)
(let ((ltest '(1 2 3 4 5 6)))
(seq-take ltest nil)); error: second argument is not optional
(let ((ltest '(1 2 3 4 5 6)))
(nbutlast ltest 0))
(1 2 3 4 5 6)
(let ((ltest '(1 2 3 4 5 6)))
(nfront ltest 0))
(1 2 3 4 5 6)
(let ((ltest '(1 2 3 4 5 6)))
(seq-take ltest 0))
nil
(let ((ltest '(1 2 3 4 5 6)))
(nbutlast ltest -1))
(1 2 3 4 5 6)
(let ((ltest '(1 2 3 4 5 6)))
(nfront ltest -1))
(1 2 3 4 5 6)
(let ((ltest '(1 2 3 4 5 6)))
(seq-take ltest -1))
nil
(let ((ltest '(1 2 3 4 5 6)))
(nbutlast ltest 20))
nil
(let ((ltest '(1 2 3 4 5 6)))
(nfront ltest 20))
(1 2 3 4 5 6)
(let ((ltest '(1 2 3 4 5 6)))
(seq-take ltest 20))
(1 2 3 4 5 6)
subr-2.patch
Description: Text document
bug#21782: 25.0.50; New functions nfront/front, Tino Calancha, 2015/10/29
bug#21782: 25.0.50; New functions nfront/front, Richard Stallman, 2015/10/29