esolang

Carol & Dave

Carol's stack and Dave's queue fight for attention: after every single step, control passes to the other one.

bforte · Turing complete: yes · ●●● hard

Tested with 4 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: A

The idea

bforte made Carol & Dave as a sibling of Alice & Bob, which is Brain-Flak with a stack and a queue. In Carol & Dave the active store switches by itself after every statement: every (), every {}, every bracketed group, also inside other groups. A loop switches once when it ends, not on every round. The switch <> still exists, but it switches once itself and once more as a statement, so it changes nothing.

Read the story

The way to write a program is the group <<><>>. It switches three times in all, an odd number, so written after a statement it cancels that statement's switch. TIO's Hello World is the Brain-Flak one with <<><>> after every statement.

The machine

The brackets mean what they mean in Alice & Bob: () is 1, (x) pushes, [] is the size, [x] negates, {} pops, {x} loops, <x> runs and gives 0. On Carol's side a loop runs while her top is not 0, on Dave's while his front is 0, depending on who is active when the loop checks.

Input numbers start on Carol's stack, first on top; TIO passes them as arguments; this implementation reads them from the input. At the end the active store is printed as characters modulo 128, top or front first. This implementation follows the Haskell interpreter at github.com/bforte/carol-dave.

Example

This is ({}{}) from Brain-Flak with the fixes put in.

This is ({}{}) from Brain-Flak with the fixes put in. It pops 30 and 35 from Carol's stack and pushes 65 back onto it, and the last <<><>> makes sure Carol is the one printed at the end. Without the fixes, ( and 65 () push 65 onto Dave's queue, and the program ends on Carol's empty stack and prints nothing.

Patterns it teaches

Further

Also in Hostile

Write your own in Run Convert a program from Carol & Dave

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: carol-dave.

Command line

shib run carol-dave -e '({}<<><>>{}<<><>>)<<><>>' --input '30 35'
shib manual carol-dave

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/carol-dave.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language