Questions tagged [equality]

15 questions
7
votes
1 answer

“(equal a b)⇒t” whereas “(equal b a)⇒error”

GNU Emacs Lisp Reference Manual, 2.8 Equality Predicates: Comparing circular lists may therefore cause deep recursion that leads to an error, and this may result in counterintuitive behavior such as (equal a b) returning t whereas (equal b a)…
shynur
  • 4,065
  • 1
  • 3
  • 23
6
votes
2 answers

How to make (make-symbol "foo") (make-symbol "foo") equal?

I'm curious why: (equal (make-symbol "foo") (make-symbol "foo")) ends up beeing nil. While (equal 'foo 'foo) is t. Do i have a misconception of symbols? Aren't they just strings without double-quotes?
lordnik22
  • 121
  • 7
6
votes
1 answer

More than two variable for equality predicates?

I see that = is great for "comparing" more than two (numerical) arguments, e.g., (= 1 1 1). But then eq, eql, and equal all only allow two arguments. And nesting is nonsense, i.e., the inner eq returns only nil or t to compare the next argument. Any…
147pm
  • 2,907
  • 1
  • 18
  • 39
5
votes
1 answer

Set difference for sets of strings

Why the following in emacs-lisp works as expected: (set-difference '(1 2) '(1)) => (2) But if strings used it doesn't: (set-difference '("foo" "bar") '("foo")) => ("foo" "bar") How do can I calculate set difference for sets of strings?
iLemming
  • 1,223
  • 9
  • 14
4
votes
3 answers

Why are there multiple ways to test for equality in elisp?

In Logic there is one and only one unambiguously(*) defined notion of equality: two things are equal if and only if they are the same thing. Programming languages of course try to emulate this concept but unfortunately the limitations imposed by the…
Ruy
  • 787
  • 4
  • 11
2
votes
1 answer

Strange behaviour involving `display` property

I noticed a rather peculiar behavior when using the display property (using emacs 28.2). I tried to boil things down to a minimal example: The code (defun finsert () (insert (propertize "." 'display "|"))) (switch-to-buffer…
dmw64
  • 155
  • 4
2
votes
2 answers

setf + alist-get but with "equal" instead of "eq"?

I got a suggestion to use setf to replace value in an alist: Replace element in a list / add in case of absence, with custom test/key functions The example was provided, but it doesn't work if key is a string: (let ((al (list (cons "a" 1) (cons "b"…
gavenkoa
  • 3,352
  • 19
  • 36
2
votes
1 answer

Check if buffername is equal to file name

I'm trying to autoexport a file from orgmode to html, so I decided to make a function to check the major mode of the buffer and check if the buffer has open the file that I want to export but when I try it the function export all the orgmode files…
rafaelleru
  • 381
  • 1
  • 13
1
vote
1 answer

How to use markers as keys in a hash map?

I'm creating a hash map and I'd like to use markers as keys. I set the hash map equality test to "equal", but the last line from the below code is returning ("bye" "fly") instead of ("bazooka" "joe"). Any idea what I'm doing wrong? (let* ((tmp…
rclark
  • 113
  • 5
1
vote
2 answers

How to compare an item against others, that's compatible with string-equal?

When comparing the last-command against multiple possible strings, it doesn't seem possible to use the member function. Is there a way to simplify this using something like member? (when (or (string-equal last-command 'foo) (string-equal…
ideasman42
  • 8,375
  • 1
  • 28
  • 105
1
vote
1 answer

Comparison of quoted symbols fails using equal

I'm trying to compare (quote foo) with 'foo using equal, but the equality is failing. Here is a trace of what is happening with my code. I don't understand why the comparison fails -- does it have something to do with the reader, or chained…
Kevin
  • 1,308
  • 8
  • 20
0
votes
1 answer

If-clause on content of variable

Question: I customized the variable user-mail-address on PC 1 and thought, I simply could ask for the content of this variable: (setq org-agenda-files (if (user-mail-address "Keks@Dose.org") '(("100-23" .…
Keks Dose
  • 508
  • 4
  • 19
0
votes
1 answer

Adding to a list when there is a match only

The following function replaces filenames and places the result in a list. Although the list gets filled, I do not want to add the filename when there is no match. How can I avoid sending non-matching situations from being added to the…
Dilna
  • 1,173
  • 3
  • 10
0
votes
1 answer

Function that returns the name of a Greek vowel

I'm trying to write a function that will return the name of a Greek vowel: alpha or epsilon etc. I was hoping this could be done by extracting it from the second group in the following regexp (in a function that determines whether a character is a…
Toothrot
  • 3,204
  • 1
  • 12
  • 30
0
votes
1 answer

Idiomatic boolean comparators

Are there idiomatic boolean comparators in emacs lisp? Something like: (my/bool< nil t) => t (my/bool< 1 2) => nil For example, a comparator that returns t if the first argument is nil and the second is truthy (per common association of '0' with…
ebpa
  • 7,319
  • 26
  • 53