all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Lists composed of equal number and kind of elements
Date: Tue, 28 Jul 2015 19:10:30 +0200	[thread overview]
Message-ID: <87si881a49.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.7450.1437981102.904.help-gnu-emacs@gnu.org

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> is there a handy way to check if two lists --results of (window-list)
> precisely-- are equal WRT to the kind and number elements?
>
> The order of elements should be ignored.

(require 'cl)
(setf lexical-binding t)

(defun* set-equal (a b &key (test (function eql)))
  (and (subsetp a b :test test)
       (subsetp b a :test test)))

(defun equivalence-classes (set equalf)
  (loop with classes = (quote ())
     for item in set
     for class = (car (member* item classes
                               :test equalf  :key (function second)))
     do (if class
            (push item (cdr class))
            (push (list :class item) classes))
     finally (return (mapcar (function cdr) classes))))

(defun* equal-wrt-kind-and-number-of-elements
    (list1 list2 &key (kind 'type-of) (test 'equal))
  (flet ((reduce-to-classes (list)
           (mapcar (lambda (class) (list (first class) (length class)))
                   (equivalence-classes (mapcar kind list) test))))
    (and (= (length list1) (length list2))
         (set-equal (reduce-to-classes list1)
                    (reduce-to-classes list2)
                    :test (lambda (c1 c2)
                            (and (= (second c1) (second c2))
                                 (funcall test (first c1) (first c2))))))))



(equal-wrt-kind-and-number-of-elements '("a" 1 2 b c d)
                                       '(x 3 y 4 z "zz"))
t

(equal-wrt-kind-and-number-of-elements '("a" 1 2 b c d)
                                       '(x 3 y 4 z xx))
nil

(equal-wrt-kind-and-number-of-elements '("a" 1 2 b c d)
                                       '(x 3 y 4 z "a" "b"))
nil



-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


       reply	other threads:[~2015-07-28 17:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.7450.1437981102.904.help-gnu-emacs@gnu.org>
2015-07-28 17:10 ` Pascal J. Bourguignon [this message]
2015-07-27  7:11 Lists composed of equal number and kind of elements Andreas Röhler
2015-07-27 13:17 ` Drew Adams
2015-07-27 15:35   ` Andreas Röhler
2015-07-27 23:31 ` Emanuel Berg
2015-07-27 23:52   ` John Mastro
2015-07-27 23:56     ` Emanuel Berg
     [not found]     ` <mailman.7498.1438041516.904.help-gnu-emacs@gnu.org>
2015-07-28 14:34       ` Barry Margolin
2015-07-28 21:11         ` Emanuel Berg
     [not found]         ` <mailman.7571.1438118111.904.help-gnu-emacs@gnu.org>
2015-07-28 21:37           ` Pascal J. Bourguignon
2015-07-29  2:16             ` Emanuel Berg
2015-07-29  7:21               ` Marcin Borkowski
2015-07-29 22:57                 ` Emanuel Berg
2015-07-29 23:04                 ` Emanuel Berg
     [not found]             ` <mailman.7584.1438136310.904.help-gnu-emacs@gnu.org>
2015-07-29  4:32               ` Pascal J. Bourguignon
2015-07-29  5:31                 ` Rusi
2015-07-29  5:43                   ` Pascal J. Bourguignon
2015-07-29  6:20                     ` Rusi
2015-07-29 15:45                       ` Pascal J. Bourguignon
2015-07-29  7:18                     ` Marcin Borkowski
2015-07-29 10:06                   ` Andreas Röhler
2015-07-29 22:45                 ` Emanuel Berg
2015-07-28  1:07   ` Drew Adams
2015-07-28 21:10     ` Emanuel Berg
     [not found]     ` <mailman.7570.1438117959.904.help-gnu-emacs@gnu.org>
2015-07-28 21:34       ` Pascal J. Bourguignon
2015-07-28 21:37         ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87si881a49.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.