ann-arcana

Queen of Burgers 🍔

Writer, game designer, engineer, bisexual tranthing, FFXIV addict

OC: Anna Verde - Primal/Excalibur, Empyreum W12 P14

Mare: E6M76HDMVU
. . .



JoshJers
@JoshJers

The question here is "what's your favorite non-C-like flow control statement/construct that you've seen in a programming language" but I'm gonna start with a little preamble.


I'm very familiar with C-style flow control:

if (condition)
  { thing; }
else 
  { otherThing; }


// And, thanks to C++17:
if (auto v= initializer(); condition) 
  { thing(v); }
else 
  { otherThing(v); }
for (int i = 0; i < 5; i++)
  { thing(); }
for (var e : elements)
  { thing(e); }
while (condition)
  { thing(); }

(plus, ya know, do/while and goto)

I've seen a few others, like Rust's loop (basically a while(true)):

loop
{ 
  thing(); 
  if (something) 
    { break; }
}

and Swift's ranges, which are nice:

for i in 0..<4
  { thing(i); }

What I'm wondering is: what are your favorite bits of flow control logic (loops, jumps, conditionals, etc) that don't show up in C or C++? Are there loop forms that you think are truly elegant? Is there a switch-like construct that doesn't suck like C's switch statement does?


ann-arcana
@ann-arcana

So I have a whole talk about this, which I could link but I feel weird about linking it because it's pre-transition and an old version, so this is kind of a Cliff Notes version of that.

Heresy is a Lisp-1 dialect I created inspired by old-school BASIC, but designed originally to teach functional programming to people who'd only ever worked in old-school imperative languages, but later mostly to teach them to myself by implementing them.

As a pure functional language, this means there is no mutability in Heresy whatsoever, and only limited side effects (just file and console, basically). But you can't write BASIC without FOR loops right? And while you can write a functional FOR loop, it's actually not a control structure that's often useful except for the side effects it generates, otherwise you'd just use a map or filter.

So we need another solution, and that solution is recursion, and escape continuations.