You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In determination and action on cases, the following list-structure approach is appealing for oMiser. The idea is to have cases represented by a form
[r1:c1, r2:c2, ..., rn:cn, d:]
where the ci are the ordered cases, and ri are the results. d is the default for "none-of-the-above."
The convention is for d to be a singleton.
A standard search for first-matching case is then something like the Frugalese for case(v) where
case(v) L=if is-singleton(L)
thenLelseif (.b .a L) = v
then .a Lelse case(v) .b L;
By convention, it is the ri:ci pair that is returned, or else d when none of the others are satisfied. In either case, .a of the returned result can be taken as the determined case.
An important variation is by having the ci be conditions rather than values. That is, they are scripts of procedures that determine whether a particular case has been matched. This is handled by the equivalent of Frugalese casep(v) where
casep(v) L=if is-singleton(L)
thenLelseif (.b .a L) v
then .a Lelse casep(v) .b L;
And, for either style, the resulting ri and .a(d) are often scripts for continuing based on the detected case.
I should make some explanations about the Frugalese pseudo-code that I use here and elsewhere, such as in #42.
For oFrugal, these descriptions are hand-compiled down to purely-ob applicative expressions. There are examples of that in combinators.txt. In the present case, an oFrugal definition of casep would be a hand-crafted compilation of the following mixture oFrugal/Frugalese.
casep = λ.v ρ.casepv λ.L
( if is-singleton(L)
thenLelseif (.b .a L) v
then .a Lelse casepv .b L
);
For oFrugal, the (if ... then ... else ...) Frugalese forms must be distilled down to canonical-form scripts. This leads to
!def ob ^casep // (6b)
=^λ.v ^ρ.casepv ^λ.L
( //if is-singleton(L)
.ev :: (.d :: L :: .b :: L)
:: `( //thenLL
::
//elseif (.b .a L) v
.ev :: ((.b :: .a :: L) :: ` v)
:: `( //then .a L
(.a :: L)
::
//else casepv .b L
casepv :: .b :: L
)
)
);
Having defined abstraction operations, ^λ and ^ρ, is invaluable. The result is not something we will want to be creating "by hand" other than to demonstrate the possibility:
Grasping all of this in one swallow is unnecessary. For now, it is enough to see that there are relatively-mechanical ways to go from the informal Frugalese to mixed oFrugal/Frugalese down to entirely oFrugal. That this is achievable is a consequence of the universality of obaptheory functions obap.ap and obap.eval. Further illustration is in Discussion #42.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In determination and action on cases, the following list-structure approach is appealing for oMiser. The idea is to have cases represented by a form
where the
ciare the ordered cases, andriare the results.dis the default for "none-of-the-above."The convention is for
dto be a singleton.A standard search for first-matching case is then something like the Frugalese for case(v) where
By convention, it is the
ri:cipair that is returned, or elsedwhen none of the others are satisfied. In either case,.aof the returned result can be taken as the determined case.An important variation is by having the
cibe conditions rather than values. That is, they are scripts of procedures that determine whether a particular case has been matched. This is handled by the equivalent of Frugalese casep(v) whereAnd, for either style, the resulting
riand.a(d)are often scripts for continuing based on the detected case.I should make some explanations about the Frugalese pseudo-code that I use here and elsewhere, such as in #42.
For oFrugal, these descriptions are hand-compiled down to purely-ob applicative expressions. There are examples of that in combinators.txt. In the present case, an oFrugal definition of
casepwould be a hand-crafted compilation of the following mixture oFrugal/Frugalese.For oFrugal, the (if ... then ... else ...) Frugalese forms must be distilled down to canonical-form scripts. This leads to
as demonstrated at casep.txt.
Having defined abstraction operations, ^λ and ^ρ, is invaluable. The result is not something we will want to be creating "by hand" other than to demonstrate the possibility:
Grasping all of this in one swallow is unnecessary. For now, it is enough to see that there are relatively-mechanical ways to go from the informal Frugalese to mixed oFrugal/Frugalese down to entirely oFrugal. That this is achievable is a consequence of the universality of obaptheory functions
obap.apandobap.eval. Further illustration is in Discussion #42.Beta Was this translation helpful? Give feedback.
All reactions