changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/std/macs/control.lisp

changeset 359: 0e00dec3de03
author: Richard Westhaver <ellis@rwest.io>
date: Wed, 22 May 2024 22:16:26 -0400
permissions: -rw-r--r--
description: macs/control macros, seq functions, ported cl-cookie, added uri/domain.lisp, fully ported http! next we should remove dependence on cl+ssl
1 ;;; std/macs/control.lisp --- Control Flow Macros
2 
3 ;;
4 
5 ;;; Code:
6 (in-package :std/macs)
7 
8 (defmacro xor (&rest datums)
9  "Evaluates its arguments one at a time, from left to right. If more than one
10 argument evaluates to a true value no further DATUMS are evaluated, and NIL is
11 returned as both primary and secondary value. If exactly one argument
12 evaluates to true, its value is returned as the primary value after all the
13 arguments have been evaluated, and T is returned as the secondary value. If no
14 arguments evaluate to true NIL is returned as primary, and T as secondary
15 value."
16  (with-gensyms (xor tmp true)
17  `(let (,tmp ,true)
18  (declare (ignorable ,tmp))
19  (block ,xor
20  ,@(mapcar (lambda (datum)
21  `(if (setf ,tmp ,datum)
22  (if ,true
23  (return-from ,xor (values nil nil))
24  (setf ,true ,tmp))))
25  datums)
26  (return-from ,xor (values ,true t))))))