This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

conditional bindings


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]