Part of the Ochre language design, but hopefully applicable elsewhere.

Ochre

Code examples in Ochre unless specified otherwise.

Note: seems very similar to gleam’s use keyword https://tour.gleam.run/advanced-features/use/

What is it

The ? operator turns continuation passing style code like this:

foo(x => {
	print(x);
})

Into this (direct style):

print(foo?)

In other words, if you have an f: (T -> U) -> U, the ? operator can turn it into a f?: T.

Control Flow Scopes

Take the ? callable expression foo defined as such:

foo(cont) = 5;
foo(cont: ! -> I32): I32 = 5;

What do each of the following Ochre expressions return?

{ ( foo? ) + 1 }
{ { foo? } + 1 }

On the left, the expression evaluates to 5, because the ? doesn’t get caught until the outermost {}.

On the right, the ? is caught immediately by the inner {}, causing the expression to return 6.

Note: all ochre files are implicitly wrapped in {}, so the above code could have been re-written as follows:

Powered by Fruition