* remove sublist @ 2018-04-02 12:09 Emanuel Berg 2018-04-02 13:06 ` Yuri Khan ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Emanuel Berg @ 2018-04-02 12:09 UTC (permalink / raw) To: help-gnu-emacs Better/built-in/semi-built-in way to do: (cl-remove-if (lambda (s) (or (string= "a" s) (string= "b" s) )) '("0" "a" "b" "c" "d") ) (cl-remove-if (lambda (s) (pcase s ("a" t) ("b" t) )) '("0" "a" "b" "c" "d") ) ? -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: remove sublist 2018-04-02 12:09 remove sublist Emanuel Berg @ 2018-04-02 13:06 ` Yuri Khan [not found] ` <mailman.11507.1522674427.27995.help-gnu-emacs@gnu.org> 2018-04-07 22:55 ` Robert L. 2 siblings, 0 replies; 12+ messages in thread From: Yuri Khan @ 2018-04-02 13:06 UTC (permalink / raw) To: Emanuel Berg; +Cc: help-gnu-emacs On Mon, Apr 2, 2018 at 7:09 PM, Emanuel Berg <moasen@zoho.com> wrote: > Better/built-in/semi-built-in way to do: > > (cl-remove-if > (lambda (s) (or (string= "a" s) > (string= "b" s) )) > '("0" "a" "b" "c" "d") ) > > (cl-remove-if > (lambda (s) (pcase s > ("a" t) > ("b" t) )) > '("0" "a" "b" "c" "d") ) > > ? Maybe (cl-set-difference '("0" "a" "b" "c" "d") '("a" "b") :test 'string=) ? ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <mailman.11507.1522674427.27995.help-gnu-emacs@gnu.org>]
* Re: remove sublist [not found] ` <mailman.11507.1522674427.27995.help-gnu-emacs@gnu.org> @ 2018-04-02 13:28 ` Emanuel Berg 2018-04-02 14:05 ` Yuri Khan ` (3 more replies) 0 siblings, 4 replies; 12+ messages in thread From: Emanuel Berg @ 2018-04-02 13:28 UTC (permalink / raw) To: help-gnu-emacs Yuri Khan wrote: > Maybe > > (cl-set-difference '("0" "a" "b" "c" "d") > '("a" "b") > :test 'string=) > > ? Excellent, thanks! You got the right idea, "sublist" as in the math unordered set sense - and not "set" as in the serpent god of the paleo-pharaohs, here! And items in the sublist that do not appear should be dropped, as happens. Should the test function be hash-quoted? Only strange thing is the order is reversed, except for the empty list as sublist! I just said it was in the unordered sense, however one might just as well keep the order, especially since even/particularly in the math unordered set sense, {1 2 3} = {3 2 1}, right? So it should work both ways; and it might be useful for example if you have a list of functions, (f1 f2 f3 f4), and it is a priority list so if f1 is defined, run it, if not, try/run f2, etc., here, if the user dislikes f2 and f3, but have them defined for other purposes, s/he can remove them from the list without changing the priority! However how is that supposed to be done? What about (defun drop-sublist (l sl) (if sl (reverse (cl-set-difference l sl :test #'string-equal)) l)) ;; (drop-sublist '("0" "a" "b" "c" "d") '("a" "b" "x")) ;; (drop-sublist '("0" "a" "b" "c" "d") '(x)) ;; (drop-sublist '("0" "a" "b" "c" "d") '()) ? It sort of goes against grain to reverse to *preserve* the order, but I suppose this is what makes programming an engineering and not a scientific endeavor... -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: remove sublist 2018-04-02 13:28 ` Emanuel Berg @ 2018-04-02 14:05 ` Yuri Khan [not found] ` <mailman.11513.1522677945.27995.help-gnu-emacs@gnu.org> ` (2 subsequent siblings) 3 siblings, 0 replies; 12+ messages in thread From: Yuri Khan @ 2018-04-02 14:05 UTC (permalink / raw) To: Emanuel Berg; +Cc: help-gnu-emacs On Mon, Apr 2, 2018 at 8:28 PM, Emanuel Berg <moasen@zoho.com> wrote: >> (cl-set-difference '("0" "a" "b" "c" "d") >> '("a" "b") >> :test 'string=) > > Excellent, thanks! > > You got the right idea, "sublist" as in the > math unordered set sense - and not "set" as in > the serpent god of the paleo-pharaohs, here! Wasn’t that Seth? (oh, Wikipedia says both variants are used.) > Should the test function be hash-quoted? Probably. > Only strange thing is the order is reversed, > except for the empty list as sublist! For me it isn’t, but I’m on 25.1. It’s not strange though — it’s more efficient to traverse the original list first-to-last and build the result list last-to-first; and it’s even more efficient to detect that the second argument is empty and return the first argument as result. If you need to preserve the original list’s order, you should probably use remove-if, as nothing in the name or documentation of set-difference will or should guarantee order. (cl-remove-if (lambda (s) (member s '("a" "b"))) '("0" "a" "b" "c" "d")) (For different types of elements, take your choice of member, memq or memql.) ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <mailman.11513.1522677945.27995.help-gnu-emacs@gnu.org>]
* Re: remove sublist [not found] ` <mailman.11513.1522677945.27995.help-gnu-emacs@gnu.org> @ 2018-04-02 14:41 ` Emanuel Berg 0 siblings, 0 replies; 12+ messages in thread From: Emanuel Berg @ 2018-04-02 14:41 UTC (permalink / raw) To: help-gnu-emacs Yuri Khan wrote: > (cl-remove-if (lambda (s) (member s '("a" "b"))) > '("0" "a" "b" "c" "d")) `member'! I had forgotten about that. Now I can use my original code only with `member' instead of `if'/`pcase'... -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: remove sublist 2018-04-02 13:28 ` Emanuel Berg 2018-04-02 14:05 ` Yuri Khan [not found] ` <mailman.11513.1522677945.27995.help-gnu-emacs@gnu.org> @ 2018-04-02 16:51 ` Stefan Monnier [not found] ` <mailman.11527.1522687900.27995.help-gnu-emacs@gnu.org> 3 siblings, 0 replies; 12+ messages in thread From: Stefan Monnier @ 2018-04-02 16:51 UTC (permalink / raw) To: help-gnu-emacs > Only strange thing is the order is reversed, That'd be a bug (which I don't see here). Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <mailman.11527.1522687900.27995.help-gnu-emacs@gnu.org>]
* Re: remove sublist [not found] ` <mailman.11527.1522687900.27995.help-gnu-emacs@gnu.org> @ 2018-04-02 20:20 ` Emanuel Berg 0 siblings, 0 replies; 12+ messages in thread From: Emanuel Berg @ 2018-04-02 20:20 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier wrote: >> Only strange thing is the order is reversed, > > That'd be a bug (which I don't see here). OK, does that mean, what works for me (last), gets reversed for you? I'm on GNU Emacs 24.4.1 (arm-unknown-linux-gnueabihf, GTK+ Version 3.14.5) of 2015-03-10 on bm-wb-01, modified by Debian I think the `member' solution is better, more generic, but it can be interesting to track the bug nonetheless. BTW if it fixed in 25.1 but not in 24.4, how about running diff(1) on cl-seq.el and check it out around line ~835? Second, emacs-24 is the most recent version I get from deb [arch=armhf] http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi (yanking /etc/apt/sources.list ) Because it is still what is offered from the main repos, does that mean bugs are bothered with even tho there is a newer version? Boy, that sounds like a handful of work :) Or perhaps just bugs which are considered critical? Or not at all? Sounds like very demoralizing work to say the least, fixing bugs that are already fixed, and can introduce new bugs or be dependent on ever newer material, not available at that version, and so on forever, like everyone else is using the new versions, only one or two guys never get there as stuck, they just fix bugs in obsolete version all day long. Ha ha ha :D (require 'cl-lib) (defun drop-sublist (l sl) (if sl (reverse (cl-set-difference l sl :test #'string-equal)) l)) ;; (drop-sublist '("0" "a" "b" "c" "d") '("a" "b" "x")) ;; (drop-sublist '("0" "a" "b" "c" "d") '(x)) ;; (drop-sublist '("0" "a" "b" "c" "d") '()) ;; (drop-sublist '() '(x)) -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: remove sublist 2018-04-02 12:09 remove sublist Emanuel Berg 2018-04-02 13:06 ` Yuri Khan [not found] ` <mailman.11507.1522674427.27995.help-gnu-emacs@gnu.org> @ 2018-04-07 22:55 ` Robert L. 2018-04-12 9:36 ` Robert L. 2 siblings, 1 reply; 12+ messages in thread From: Robert L. @ 2018-04-07 22:55 UTC (permalink / raw) To: help-gnu-emacs On 4/2/2018, Emanuel Berg wrote: > > (cl-remove-if > (lambda (s) (or (string= "a" s) > (string= "b" s) )) > '("0" "a" "b" "c" "d") ) (defun remove-these (targets xs) (let (result) (dolist (x xs (reverse result)) (unless (member x targets) (push x result))))) (remove-these '(a e) '(a b e f o a g)) ===> (b f o g) -- [Amazon bans history book after it received 300 5-star reviews.] http://archive.org/details/nolies ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: remove sublist 2018-04-07 22:55 ` Robert L. @ 2018-04-12 9:36 ` Robert L. 2018-04-12 15:10 ` Emanuel Berg 0 siblings, 1 reply; 12+ messages in thread From: Robert L. @ 2018-04-12 9:36 UTC (permalink / raw) To: help-gnu-emacs On 4/7/2018, Robert L. wrote: > On 4/2/2018, Emanuel Berg wrote: > > > > > (cl-remove-if > > (lambda (s) (or (string= "a" s) > > (string= "b" s) )) > > '("0" "a" "b" "c" "d") ) > > (defun remove-these (targets xs) > (let (result) > (dolist (x xs (reverse result)) > (unless (member x targets) > (push x result))))) > > (remove-these '(a e) '(a b e f o a g)) > ===> > (b f o g) (defun remove-these (targets xs) (if targets (remove-these (cdr targets) (remove (car targets) xs)) xs)) (remove-these '(a e) '(a b e f o a g)) ===> (b f o g) -- When the Israeli bombers and torpedo-planes were sent to attack and destroy the ship, the Jewish commander, seeing that it was an American vessel, had misgivings and reported to the High Command, which simply repeated the orders to attack and sink the Liberty. I have a graphic from ... the oldest daily newspaper of Israel, ... Haaretz.... The headline reads, "But, sir, it's an American ship." "Never mind. Hit her." http://archive.org/details/nolies ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: remove sublist 2018-04-12 9:36 ` Robert L. @ 2018-04-12 15:10 ` Emanuel Berg 2018-04-12 15:28 ` Eli Zaretskii [not found] ` <mailman.12153.1523546882.27995.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 12+ messages in thread From: Emanuel Berg @ 2018-04-12 15:10 UTC (permalink / raw) To: help-gnu-emacs Robert L. wrote: > (defun remove-these (targets xs) > (if targets > (remove-these (cdr targets) (remove (car targets) xs)) > xs)) > > (remove-these '(a e) '(a b e f o a g)) > ===> > (b f o g) (require 'cl-lib) (defun drop-sublist (l subl) "Every element of L that isn't also in SUBL." (cl-remove-if (lambda (e) (member e subl)) l) ) -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: remove sublist 2018-04-12 15:10 ` Emanuel Berg @ 2018-04-12 15:28 ` Eli Zaretskii [not found] ` <mailman.12153.1523546882.27995.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 12+ messages in thread From: Eli Zaretskii @ 2018-04-12 15:28 UTC (permalink / raw) To: help-gnu-emacs > From: Emanuel Berg <moasen@zoho.com> > Date: Thu, 12 Apr 2018 17:10:21 +0200 > > Robert L. wrote: > > > (defun remove-these (targets xs) > > (if targets > > (remove-these (cdr targets) (remove (car targets) xs)) > > xs)) > > > > (remove-these '(a e) '(a b e f o a g)) > > ===> > > (b f o g) > > (require 'cl-lib) > (defun drop-sublist (l subl) > "Every element of L that isn't also in SUBL." > (cl-remove-if (lambda (e) (member e subl)) l) ) The future is here: (require 'seq) (seq-difference '(a b e f o a g) '(a e)) => (b f o g) ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <mailman.12153.1523546882.27995.help-gnu-emacs@gnu.org>]
* Re: remove sublist [not found] ` <mailman.12153.1523546882.27995.help-gnu-emacs@gnu.org> @ 2018-04-12 17:43 ` Emanuel Berg 0 siblings, 0 replies; 12+ messages in thread From: Emanuel Berg @ 2018-04-12 17:43 UTC (permalink / raw) To: help-gnu-emacs Eli Zaretskii wrote: >> (require 'cl-lib) >> (defun drop-sublist (l subl) >> "Every element of L that isn't also in SUBL." >> (cl-remove-if (lambda (e) (member e subl)) l) ) > > The future is here: > > (require 'seq) > (seq-difference '(a b e f o a g) '(a e)) > => (b f o g) Added "drop drop-sublist" to my TODO file. -- underground experts united http://user.it.uu.se/~embe8573 ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2018-04-12 17:43 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-04-02 12:09 remove sublist Emanuel Berg 2018-04-02 13:06 ` Yuri Khan [not found] ` <mailman.11507.1522674427.27995.help-gnu-emacs@gnu.org> 2018-04-02 13:28 ` Emanuel Berg 2018-04-02 14:05 ` Yuri Khan [not found] ` <mailman.11513.1522677945.27995.help-gnu-emacs@gnu.org> 2018-04-02 14:41 ` Emanuel Berg 2018-04-02 16:51 ` Stefan Monnier [not found] ` <mailman.11527.1522687900.27995.help-gnu-emacs@gnu.org> 2018-04-02 20:20 ` Emanuel Berg 2018-04-07 22:55 ` Robert L. 2018-04-12 9:36 ` Robert L. 2018-04-12 15:10 ` Emanuel Berg 2018-04-12 15:28 ` Eli Zaretskii [not found] ` <mailman.12153.1523546882.27995.help-gnu-emacs@gnu.org> 2018-04-12 17:43 ` Emanuel Berg
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.