Inverted syntax: Difference between revisions

Content added Content deleted
(add RPL)
Line 606: Line 606:


@inv println("Wow! Lucky Guess!") if true else println("Not!") end</syntaxhighlight>
@inv println("Wow! Lucky Guess!") if true else println("Not!") end</syntaxhighlight>

=={{header|Koka}}==
Using the byref function and infix operators we can get both inverted assignments as well as inverted conditionals in Koka! However, the branch to the conditional is evaluated prior to the condition unless you explicitly delay it or accept a closure.

<syntaxhighlight lang="koka">
fun (=:)(c: c, v: local-var<h, c>): <local<h>> ()
v := c

fun (?)(c: c, b: bool): e maybe<c>
if b then Just(c) else Nothing

fun main()
var x := 4
6 =: std/core/types/byref(x)
x.println
val res = "Yes" ? True
match res
Just(a) -> println(a)
Nothing -> throw("Nothing")
</syntaxhighlight>

{{out}}
<pre>
6
Yes
</pre>


=={{header|Kotlin}}==
=={{header|Kotlin}}==