|
From: | Urs Liska |
Subject: | test if an element occurs in a list exactly once |
Date: | Thu, 28 Jun 2018 11:13:29 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
Hi,I have to validate symbol-lists in various ways. For example if it must contain exactly two values (in arbitrary order) I can do
(and (= (length mylist) 2)(memq 'val-a mylist) (memq 'val-b mylist))To test if only certain values are allowed (but may be there multiple times):
(every (lambda (elt) (memq elt '(val-a val-b))) mylist)Now I have a case where one value must be present once and another value at least once, so '(a b b) is valid as well as '(a b) but '(a a b) is invalid.
I can use (filter) and check if the resulting list has exactly one element, but is there a "native" function to either check if an element is in a list exactly once?
Thanks Urs
[Prev in Thread] | Current Thread | [Next in Thread] |