This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
conditional bindings
- From: Per Bothner <per at bothner dot com>
- To: kawa mailing list <kawa at sourceware dot org>
- Date: Mon, 08 Dec 2014 21:48:42 -0800
- Subject: conditional bindings
- Authentication-results: sourceware.org; auth=none
I checked in a little feature, which you can think of as
a precursor to pattern matching.
The syntax (? NAME::TYPE VALUE) can be used in conditional forms:
if, and, cond, etc. First VALUE is evaluated. Then if the result
is an compatible with TYPE, then NAME is bound to the result
(possibly after conversion). The result is #t, but with the "side effect"
that NAME is lexically bound in "following forms". If VALUE doesn't
match TYPE then the ?-form is false.
You can you a ? form in an (and e1 e2 ...). Then a binding in e1
is visible e2 and so on. Similar in (if e1 e2 e3) any binding in e1
is visible in e2. For example:
(if (and (? x::integer e1) (? y::integer e2) (>= x 0) (>= y 0))
(+ x y)
(error))
In the future I intend to allow more general patterns: (? PATTERN VALUE)
If the VALUE is lazy, it is automatically forced (unless TYPE
is Object or implements gnu.mapping.Lazy).
--
--Per Bothner
per@bothner.com http://per.bothner.com/