A pattern matching directive was included as an alternative in the
original proposal, or to introduce a new switch directive with a new
name. I'm not married to any particular approach, I've just gone with
what I could get agreement upon.

Yes, one of the original reasons for switch was jump tables, but I
still find utility in it, otherwise I wouldn't have made the proposal.

A side-effect of re-using the switch directive in this way seems to be that
it may cause less confusion if it was decided to introduce a more powerful
directive in the future. You've probably given this more thought than I have,
since I noticed that you added an instanceof built-in in your codebase,
which is one of the features that pattern matching can be used for.

If there are further or second thoughts, then things can still change.
I'm not particularly the one to convince, I'm just trying to do my bit to help.

---
Many thanks
Simon Hartley






On Sunday, 11 February 2024 at 15:27:04 GMT, Jonathan Revusky 
<revu...@gmail.com> wrote: 





On Sat, Feb 10, 2024 at 5:48 PM Simon Hartley
<scrhart...@yahoo.co.uk.invalid> wrote:

> I've made an implementation of #on here:
>
> https://github.com/scrhartley/apache-freemarker/commit/cee8d076b02e8dbcae0b84eabc76814aaea8baf6
>
> * Fall-through does not occur when using #on.
> * #on supports multiple conditions
> * #default may be used with #on
> * This implementation doesn't allow mixing #case and #on.
> * When #on has been used in the #switch then #break and #continue are not
> supported, otherwise the legacy behavior is used. This means that the
> behavior in a #default depends upon whether an #on has been used.
>

I would say that if you're going to go for this, you should really
introduce an entirely new directive, like maybe #match, either #match/#case
or maybe #match/#on. And then just leave #switch alone.

That strikes me as cleaner, though what do I know? I'm just the guy who
implemented this in code all those years ago. Actually, now that I think
about it, this #switch/#case with default fall-through should really have
been deprecated and then later removed in the early 2000's. As far as I can
see, everybody would be better off without it! But now it's been there for
so many years...This kind of construct made sense in a system programming
language like C because the construct can be translated into a very
efficient jump table in machine code, but...

JR





>
> I've updated some of the tests, but I'm unsure if that's sufficient. I saw
> that switch.ftl exists, but since it's in the jython25 tests I left it
> alone. After my changes "gradlew check" still passes. I haven't updated the
> manual.
>
> I'm now looking for feedback and possibly next steps. What should happen
> to get this ready for merge request?
>
> ---
> Best regards,
> Simon Hartley
>
>
>
>
>
>
>
>
> On Saturday, 10 February 2024 at 09:31:32 GMT, Daniel Dekany <
> daniel.dek...@gmail.com> wrote:
>
>
>
>
>
> > Because there's not an explicit closing tag for #case or #on, the use of
> #break in the following avoids a trailing newline
>
>
> Yeah, but that's really a hack. I mean, we have the same whitespace issue
> with #else, and #elseif. So this is just not the feature where we address
> whitespace issues in general.
>
>

Reply via email to