I want to understand why
(when (string= issue "")
(error "Issue number missing"))
doesn't throw an error when issue
is empty, but
(when (= (length issue) 0)
(error "Issue number missing"))
works as expected.
Documentation of string=
states that it compares content of both strings and returns t
when they are identical. I'm pretty sure a string of length 0 and ""
have identical contents.
The value of issue
is set in the following code:
(string-match "\#\\([0-9]*\\)" text)
(setq issue (match-string 1 text))
I tried to replace when
with if
and added (print (concat "\"" issue "\""))
to the else clause, it printed "\"\""
as a result. I printed the POST query that uses issue
as one of its inputs and it generated empty string in its place (the code constructing the query shouldn't even execute if string=
returned the correct value). Not to mention that it's length is equal to 0. I'm certain that issue
is equal to "".
(let ((issue "")) (string= issue ""))
returnst
for me. Are you sureissue
is an empty string? – choroba Feb 02 '23 at 15:26issue
is set tonil
, not to""
. – NickD Feb 02 '23 at 15:59concat
turnsnil
into""
, try printing it withoutconcat
, too. – choroba Feb 02 '23 at 16:06elisp-macros
,let-binding
,lexical-binding
,...) - use those when appropriate. Be specific. – Drew Feb 03 '23 at 02:25