June 25th, 2024

Continuations by Example

Continuations are powerful in control-flow constructs, enabling exceptions, search, threads, generators, and coroutines. They capture remaining computation steps, aiding in non-deterministic choices and efficient iteration over data structures.

Read original articleLink Icon
Continuations by Example

Continuations are a powerful but often misunderstood concept in control-flow constructs. They enable the implementation of features like exceptions, backtracking search, threads, generators, and coroutines. By using first-class continuations, programmers can introduce non-deterministic choice procedures like 'amb' in Scheme. This allows for solving problems like the Pythagorean theorem with ease. Continuations represent the remaining steps in a computation, and languages like Scheme provide mechanisms like call/cc to capture and manipulate continuations. Additionally, continuations can be used to implement generators for efficient iteration over complex data structures without the need for intermediate data storage. Furthermore, continuations facilitate cooperative multithreading, where threads must yield control manually. By understanding continuations and their applications, programmers can leverage their power to create more efficient and flexible code structures.

Related

F (2006)

F (2006)

F is a functional concatenative language with K3 list operations and Joy's dip combinator. It enforces one-time assignment, supports floating-point and symbolic datatypes, and emphasizes function-valence and -charge theories. The language is purely functional, prohibiting side-effects and reassignment, with various primitives for arithmetic, logic, and list operations. F also provides interactive commands for debugging and manipulation, focusing on simplicity, efficiency, and functional programming paradigms.

Cognate: Readable and concise concatenative programming

Cognate: Readable and concise concatenative programming

Cognate is a concise, readable concatenative programming language emphasizing simplicity and flexibility. It supports operators as functions, stack evaluation, control flow statements, list manipulation, recursion, and mutable variables through boxes.

Flambda2 Ep. 2: Loopifying Tail-Recursive Functions

Flambda2 Ep. 2: Loopifying Tail-Recursive Functions

Flambda2's Episode 2 explores Loopify, an optimization algorithm for tail-recursive functions in OCaml. It transforms recursion into loops, enhancing memory efficiency without compromising functional programming principles.

How GCC and Clang handle statically known undefined behaviour

How GCC and Clang handle statically known undefined behaviour

Discussion on compilers handling statically known undefined behavior (UB) in C code reveals insights into optimizations. Compilers like gcc and clang optimize based on undefined language semantics, potentially crashing programs or ignoring problematic code. UB avoidance is crucial for program predictability and security. Compilers differ in handling UB, with gcc and clang showing variations in crash behavior and warnings. LLVM's 'poison' values allow optimizations despite UB, reflecting diverse compiler approaches. Compiler responses to UB are subjective, influenced by developers and user requirements.

Atomic Operations Composition in Go

Atomic Operations Composition in Go

The article discusses atomic operations composition in Go, crucial for predictable results in concurrent programming without locks. Examples show both reliable and unpredictable outcomes, cautioning about atomics' limitations compared to mutexes.

Link Icon 3 comments
By @jacknews - 4 months
I don't find the description or the examples here very well explained. What does call/cc do? What does cc do? what is this code, or is it just a comment?

  (continuation of 3 \* (f() + 8))(result) ;
The descriptions are just hard to parse:

  The value passed to the continuation is the return value of the call.
  
  During the execution of the expression body, the variable current-continuation is bound to the current continuation. If invoked, current-continuation immediately returns from the call to call/cc ...
And the initial 'teaser' is explained later, but not demonstrated by showing actuial code for assert and amb.
By @JoelMcCracken - 4 months
I’m not super well versed in continuations, is right-now/go-when analogous to reset and shift, or are these different ideas?