Groups | Search | Server Info | Login | Register
Groups > comp.lang.lisp > #60675
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | tpeplt <tpeplt@gmail.com> |
| Newsgroups | comp.lang.lisp |
| Subject | Re: How to use constants in a case key form ? |
| Date | Tue, 26 Aug 2025 14:37:11 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 60 |
| Message-ID | <87plciylns.fsf@gmail.com> (permalink) |
| References | <108i78e$3ig75$1@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Tue, 26 Aug 2025 18:37:12 +0000 (UTC) |
| Injection-Info | dont-email.me; posting-host="2d2b084358757c6aaa44d4cdbce92484"; logging-data="234293"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FhM9zsQ+oy/r3lnTLhKlURkG1Lv6lJNw=" |
| User-Agent | Gnus/5.13 (Gnus v5.13) |
| Cancel-Lock | sha1:ICdLGgBAaNpZlRV2f+BwfvUQCdk= sha1:uG5IPXxF85VElAlw3TJGPZYogTU= |
| Xref | csiph.com comp.lang.lisp:60675 |
Show key headers only | View raw
"B. Pym" <Nobody447095@here-nor-there.org> writes:
>
> Testing with ABCL:
>
> (setq *enum* '(a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 2))
> (duplicate-value-check)
>
> CL-USER(3): Debugger invoked on condition of type SIMPLE-ERROR:
> key C has a value 3 duplicated
>
> It should have been:
> key i has a value 2 duplicated
>
> Gauche Scheme
>
> (define (dup-check plist)
> (let1 seen '()
> (do-plist ((k v) plist)
> (if (member v seen)
> (errorf "Key ~a has dup. value ~a." k v)
> (push! seen v)))))
>
> (dup-check '(a 2 b 3 c 4 d 3 e 6 f 7 g 8 h 3 i 42))
>
> *** ERROR: Key d has dup. value 3.
Because Common Lisp’s ‘loop’ macro supports iterating over
the CDRs of lists and destructuring, the CL version of
‘dup-check’ is similar:
(defvar *enum* '(a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 2))
(defun dup-check (plist)
"Verify that property list PLIST has no duplicate values. An error
is issued if any are found."
(loop
for (k v) on plist by #'cddr
if (member v unique) do
(error "key ~A has a value ~D duplicated" k v)
else
collect v into unique
finally (return 'no-duplicates)))
(dup-check *enum*)
;;=> Run-time error: "key I has a value 2 duplicated"
(dup-check '(a 2 b 3 c 4 d 3 e 6 f 7 g 8 h 3 i 42))
;;=> Run-time error: "key D has a value 3 duplicated"
(dup-check
'(a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9))
;;=> NO-DUPLICATES
See "The for-as-on-list subclause":
http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/sec_6-1-2-1-3.html
--
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.
Back to comp.lang.lisp | Previous | Next — Previous in thread | Find similar
Re: How to use constants in a case key form ? "B. Pym" <Nobody447095@here-nor-there.org> - 2025-08-25 17:41 +0000 Re: How to use constants in a case key form ? tpeplt <tpeplt@gmail.com> - 2025-08-26 14:37 -0400
csiph-web