0

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 Greek vowel), but I don't know how, if at all, that is possible.

(defun greek-vowel-p (l)
  (eql (string-match "GREEK \\(SMALL\\|CAPITAL\\) LETTER \
\\(ALPHA\\|EPSILON\\|ETA\\|IOTA\\|OMICRON\\|UPSILON\\|OMEGA\\|RHO\\)"
                     (get-char-code-property l 'name))
       0))
  • How about?: (car (last (split-string (get-char-code-property ?α 'name)))) – lawlist Jul 2 '18 at 21:05
  • @lawlist, the name is not necessarily the last word. – Toothrot Jul 2 '18 at 21:08
  • The most common pattern for extracting whole matches or subgroups thereof is (and (string-match ...) (match-string ...)); see (elisp) Searching and Matching. – Basil Jul 2 '18 at 21:19
  • @Basil, thanks, I tried something like this, but missed the in-string bit. – Toothrot Jul 2 '18 at 21:33
  • In your case @Basil's comment translates to something like (defun my-greek-vowel (char) (and (greek-vowel-p char) (match-string 2 (get-char-code-property char 'name)))). Please write up an answer and accept it if you have a working version. BTW I am not so sure that I would use greek-vowel-p at all if that function is not made by myself. If the code of that function changes it may break your code. Example for a breaking change: Adding a save-match-data to greek-vowel-p. – Tobias Jul 2 '18 at 23:36
1

Based on comments,

(defun greek-vowel-name (c)
  "Return the name of the Greek vowel character C as a symbol.
The same name is returned regardless of case and diacritics.
If the argument is not a Greek vowel, the value is nil.
The semi-vowel rho is considered a vowel."
  (let ((u (get-char-code-property c 'name)))
    (and (string-match "GREEK \\(?:SMALL\\|CAPITAL\\) LETTER \
\\(ALPHA\\|EPSILON\\|ETA\\|IOTA\\|OMICRON\\|UPSILON\\|OMEGA\\|RHO\\)"
                       u)
         (intern (downcase (match-string 1 u))))))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.