﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	difficulty
1020	matchable: Add conversion pattern(s)	Moritz Heidkamp	Alex Shinn	"The attached patch adds two new pattern types to matchable:

   {{{(-> convert pat-1 … pat-n)}}}
   {{{(-?> convert pat-1 … pat-n)}}}

These patterns work like the {{{(? predicate pat-1 … pat-n)}}} pattern
in that {{{convert}}} must be an expression evaluating to a single
argument function which is applied to the corresponding
value. However, in contrast to {{{?}}}, the following patterns
{{{pat-1 … pat-n}}} are applied to the value _returned_ by
{{{convert}}}. In addition, {{{-?>}}} only matches when {{{convert}}}
does not return {{{#f}}}, so it can be expressed as combination of
{{{->}}} and {{{?}}} like this:

  {{{(-> convert (? (lambda (x) x) pat-1 … pat-n))}}}

The rationale is that it allows to match against a converted value and
at the same time being able to bind that value to a variable instead
of having to apply the conversion again in the body. One might argue
that {{{-?>}}} is not really necessary so I'd be happy with only
adding {{{->}}}, too. It should be noted that this patch is not
backwards compatible.


Some examples:

{{{
(match '(""foo"" ""10"")
  ((""foo"" (-> string->number x)) (+ x x)))

;; => 20


(match '(""foo"" ""bar"")
  ((""foo"" (-> string->number x)) (+ x x)))

;; Error: (+) bad argument type: #f


(match '(""foo"" ""10"")
  ((""foo"" (-?> string->number x)) (+ x x))
  (else 'nothing))

;; => 20


(match '(""foo"" ""bar"")
  ((""foo"" (-?> string->number x)) (+ x x))
  (else 'nothing))

;; => nothing
}}}"	enhancement	accepted	not urgent at all	someday	extensions	4.8.x		matchable		
