all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: lawrence mitchell <wence@gmx.li>
Subject: Re: Help with elisp
Date: Thu, 31 Jul 2003 12:30:58 +0100	[thread overview]
Message-ID: <?fnord?u8yqfc4r1.fsf@ID-97657.usr.dfncis.de> (raw)
In-Reply-To: mailman.767.1059641390.8231.help-gnu-emacs@gnu.org

David Chadd wrote:

> Apologies for a question demonstrating beginner's total Elisp
> incompetence.  I want to make lists out of series of
> attribute-values in an xml file.  (The values are sigla of
> manuscripts.)  These are e.g. in the form:

>   wit="CAO-C Alb2 Hyd"

> Having found the string of values (CAO-C Alb2 Hyd) with a regexp
> search, I simple-mindedly thought I would be able to do something like

>   (setq wits (split-string (match-string 1)))

> This does indeed make a list --- (listp wits) returns T --- but the
> lists don't behave as I would expect.  For instance, they don't
> respond correctly to (set-difference), (intersection) etc.  And for
> reasons I can guess at, but don't know enough to do anything about,
> the lists are in the form ("CAO-C" "Alb2" "Hyd") rather than (CAO-C
> Alb2 Hyd).

> I'm obviously going totally the wrong way about this.  How should I be
> trying to make a conventional Lisp list out of a found string of this
> kind?  Advice and guidance gratefully received.

In fact, you're almost there.  The only thing you're missing is
the correct equality test.  You see, strings are not EQ, or EQL
in emacs lisp.

(eq "foo" "foo")
   => nil

(eql "foo" "foo")
   => nil

instead, you need to check for equality either with EQUAL, or,
if you know you are using strings, STRING=.

(equal "foo" "foo")
   => t

(string= "foo" "foo")
   => t

Now, the functions SET-DIFFERENCE and INTERSECTION by default
test for equality with EQ, so you need to tell them to use a
different testing function.  This can be done by supplying them
with a keyword argument.

(setq foo '("foo" "bar" "baz")
      bar '("bar" "baz" "quux"))

foo
   => ("foo" "bar" "baz")

bar
   => ("bar" "baz" "quux")

;; Default, comparison done with EQ.
(set-difference foo bar)
   => ("baz" "bar" "foo")

(intersection foo bar)
   => nil

;; Comparison done with STRING=
(set-difference foo bar :test 'string=)
   => ("foo")

(intersection foo bar :test 'string=)
   => ("baz" "bar")

Hope that clears things up a bit
-- 
lawrence mitchell <wence@gmx.li>

       reply	other threads:[~2003-07-31 11:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.767.1059641390.8231.help-gnu-emacs@gnu.org>
2003-07-31 11:30 ` lawrence mitchell [this message]
2003-07-31 11:59 ` Help with elisp Tom Capey
2003-07-31 15:59   ` Kevin Rodgers
2021-10-14 22:18 help with Elisp Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-14 22:21 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-14 22:23 ` Gregory Heytings
2021-10-14 22:24 ` Óscar Fuentes
  -- strict thread matches above, loose matches on Subject: below --
2003-07-31 18:13 Help with elisp David Chadd
2003-07-30 18:06 David Chadd

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='?fnord?u8yqfc4r1.fsf@ID-97657.usr.dfncis.de' \
    --to=wence@gmx.li \
    /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.