Closed dfmorrison closed 8 years ago
ok, "otherwise" is a feature in optima, which is not implemented in trivia. The compatibility between optima and trivia is important, but I am reluctant to add the feature to trivia.
cl:otherwise
in cl:case
, it should be the latter. It however, introduces another complexity to the code in addition to the second case.Would you still really want it? if there is an urgent need I am ok with adding it (but probably without the error checking on the non-last clauses). Thanks for the report anyways.
Well, Trivia does advertise itself as follows:
Trivia is a pattern matching compiler that is compatible with Optima. It shares the same testing code with Optima and acts as a drop-in replacement.
A "drop-in replacement" says, at least to me, that if I have a bunch of code written against Optima that works, when I swap out Optima for Trivia it will still work the same. If that is not your goal, then I think you should probably change your blurb to something like "Trivia is similar to Optima, but in some cases has different semantics" [or, perhaps, you'd prefer to say "better semantics" :-)], and, ideally, document those differences.
As to the value of otherwise
, having a default clause at the end is frequently useful, and a lone underscore character is rather inscrutable there, at least to my eyes. From Optima's documentation I've always assumed it is strictly analogous to underscore, though I've never tried it elsewhere. And I do agree with you that it would be better as just something magic for use in the last clause, a la case
(though if that breaks compatibility, then probably not if you really want to be a drop-in replacement). As to complexity of implementation, I (as an end user) obviously think tidiness and usefulness of Trivia as a language trumps ease and tidiness of implementation, but your perspective may well be different.
Thanks!
ok, i should be strict and honest to what i advertize; I will add the feature. there are some differences between trivia and optima, still. its a kind of "do your Am486 has the same bug as i486 has?" kind of thing, though.
I newly added test cases for OTHERWISE
. It explicitly allows the use of OTHERWISE
in clauses other than the last one, which means it is completely analogous to _
.
One solution would be to have different packages: one that is fully compatible, the other that is simpler and purer.
Note that in this topic I did not intend to defend about not implementing OTHERWISE. I just tried to claim it is of less priority and is not necessary (untested, undefined, unreliable feature may not be implemented --- when it worked in optima previously, it just happened to work by luck, since there is no mean to test it.) I finally defined the behavior and implemented it. This is now documented in https://github.com/guicho271828/trivia/wiki/Known-Differences .
@fare , the idea sounds good. Isn't it about assoc
pattern issue though?