against and-let* Per Bothner (26 Jun 2020 17:00 UTC)
Re: against and-let* Panicz Maciej Godek (26 Jun 2020 18:25 UTC)
Re: against and-let* Per Bothner (26 Jun 2020 20:24 UTC)
Re: against and-let* Panicz Maciej Godek (26 Jun 2020 22:14 UTC)

Re: against and-let* Per Bothner 26 Jun 2020 20:24 UTC

On 6/26/20 11:25 AM, Panicz Maciej Godek wrote:
> pt., 26 cze 2020 o 19:00 Per Bothner <xxxxxx@bothner.com <mailto:xxxxxx@bothner.com>> napisał(a):

>     Instead, I (modestly) propose the Kawa approach, which I think is
>     both natural and flexible:
>
> I'd personally find it confusing, because the (? xxx) form in the context of match (at least in Wright-Cartwright-Shinn and Racket matchers) is interpreted so that "xxx" is a predicate. Apparently Kawa reverses this meaning in the context of "if", interpreting it as an identifier followed by a pattern.

No, the Kawa syntax is (? pattern expression). The pattern can be a simple identifier (which always succeeds),
in which case the identifier is bound to the result of evaluating the expression.  A common idiom is:
    (? var::type expression)
This evaluates expression.  If the result is compatible with type, then the match succeeds,
and var is bound to the result, after coercion/conversion to the type.
More complex patterns are possible:
     https://gnu.org/software/kawa/Variables-and-Patterns.htm
> My beef with this approach is that it might be surprising to the ones who are not familiar,

The specific of using the syntax (? pattern expression) is not essential to this approach.
You can use some other syntax and still have the same flexibility and (in my opinion) elegance.
The basic idea to have a test-or-match syntax non-terminal that includes boolean expressions and
pattern-match forms.  Then you redefine 'if' 'and' 'cond' etc in terms of test-or-match,
as in https://www.gnu.org/software/kawa/Conditionals.html . This avoids the need for and-let*.

> and is not compositional (you cannot use the "?" identifier for your own purpose, because it will clash in the context of "if"'s condition).

I don't understand this concern.  You can re-bind "?" just as much as you can re-bind "and".
Syntactic hygiene applies, as usual.  If you re-bind "?", that should not break "if".
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/