emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

first-is (3 versions, Elisp hangup) (was: Re: we need *modularity* [last


From: Emanuel Berg
Subject: first-is (3 versions, Elisp hangup) (was: Re: we need *modularity* [last problem])
Date: Fri, 16 Aug 2024 11:35:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Here is one example. How to check if a word starts with
something? E.g., a "-" (not a dash anymore but
a "hyphen-minus", haha) then that should denote something
else, a line in this case, such situations.

How do you check that? And it cannot break for data that is
(not stringp), should just be nil then

I was doing something else, now I did this instead. I'm sure
you have a much better method that will make me look like
a fool, but ... it is like this all the time with Elisp.

Why isn't there just a (first-is THIS ALL) and it would not
crash, just eval to nil on type incompatibilities, other than
that it would work on arbitrary data? THIS could even be
a predicate that would take FRST as the argument.

Hey ... not bad! I should write that!

See the problem? :P

(defun elpat--first-is-3 (s str)
  (and (stringp s)
       (stringp str)
       (string= s (char-to-string (seq-first str)))))

(defun elpat--first-is-2 (s str)
  (and (stringp s)
       (stringp str)
       (string= s (substring str 0 1))))

(defun elpat--first-is (s str)
  (and (cl-every #'stringp (list s str))
       #1=(string-match s str)
       (zerop #1#)))

;; (elpat--first-is   "s" "same")
;; (elpat--first-is-2 "s" "same")
;; (elpat--first-is-3 "s" "same")

;; (elpat--first-is   "s" "lame")
;; (elpat--first-is-2 "s" "lame")
;; (elpat--first-is-3 "s" "lame")

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]