[This is like 5min into the future, so not sure it...
# thinking-together
h
[This is like 5min into the future, so not sure it qualifies as a topic in FutureOfCoding slack? Admins fell free to delete or move] A language construct terminology question: What is a good name for the “transposition” of a Case expression? (see below) Motivation: The idea is to integrate some more expressive language patterns into e.g. JavaScript using Continuation-Passing Style (CPS), in a friendly way by putting the CPS functionality in predictable places in readable constructs. The Case expression is similar to Haskell pattern matching in intended usage. The corresponding JavaScript syntax needs a few extra parens and commas. Clarification: By Case expression I intend:
Copy code
Case
    <pat p1> <fn succ1>
    <pat p2> <fn succ2>
    ...
    <fn failAll> -- optional
Success at p#n means choose succ#n. Failure at p#n means continue with clause n+1. By ‘transposition of Case’ I intend:
Copy code
CaseTransp
    <pat p1> <fn fail1>
    <pat p2> <fn fail2>
    ...
    <fn succAll> -- not optional
Failure at p#n means choose fail#n. Success at p#n means continue with p#(n+1). Note: <pat> are CPS constructs in the form of functions that can succeed or fail. <fail> and <succ> are ordinary functions.
i
I don't know what the acronym "CPS" stands for.
h
@Ivan Reese “Continuation-Passing Style” is the intention; didn’t mean to be unclear, the first non-abbrevitated wording fell out during editing; now reintroduced! Thanks! As an aside, there are two things that make CPS worthwhile and fun IMO: 1. One can implement any control structure in any language that has first-class functions. 2. CPS style is known to be mind-bening/not very readable, but can be turned the opposite using appropriate abstractions
w
By "can be turned the opposite using appropriate abstractions," what do mean? For more everyday programmers, if you say Callback-Passing Style, they'll at least understand how (1) is obvious. About (2) as one who was mind-bent as a young person by, I honestly can't remember whats hard abou,t say, callcc now.
k
@wtaysom I'm jealous. My mind gets bent all over again, every time I go back to it after a few years. Perhaps I didn't get exposed to it while my mind was supple.
a
I'm not sure a case expression or any derivatives thereof should so intimately involve a notion of "failure" or "success". From a mechanical standpoint, those are just human-friendly tags on regular ol' control flow paths. If you strip that away, the only difference I can see is that you've made the default case mandatory. If anything, I feel like you have syntactic sugar for a case expression where all cases but the default get wrapped in some domain-specific failure indicator.
j
I can see adding a keyword to let people avoid negating their patterns, if that is more convenient. I don't see a reason to enforce catchall. The coder might just prefer to state exhauative options negatively. I might just call it "not case."
w
Case expressions and failure? I think of destructuring pattern matching.
t
Seems similar to De Morgan's laws, whose generalizations are discussed here https://en.wikipedia.org/wiki/De_Morgan%27s_laws#Generalising_De_Morgan_duality