Grilled Cheese

ExploreLog inSign up
Terms of UsePrivacy PolicyCommunity StandardsHelpGet the app

Grilled Cheese is a product of Village Compute

Version devBuilt at: 2026-12-03 22:42:33 EST

PhotosVideosAllPeople
LatestRanked
// [B] [A] cons == [[B] A]
export const cons = define('cons', [ [B], [A] ], [ [[B], A] ],
  [ [], coup, sap ],
  [ [[], k], [], sPrime ],
  [ cake, [], k ]
);
import { A } from "../tooling/placeholders.common";
import { proper } from "../tooling/proper";

export const run = proper([ [A] ], [ A, [A] ], 'run');
/*
 * The Resplendent Quetzal is a fixed point combinator that adapts the Z combinator
 * to Concatenative Combinators. In classical combinatory logic, the Y combinator
 * has at its heart a lark, ƛf.ƛx.f(xx). To work in a call-by-value language, we make
 * one more parameter eplicit: ƛf.ƛx.ƛu.f(xx)u. That is the Z combinator.
 * 
 * In Concatenative Combinators, the lark is defined as [B] [A] lark == [[B] B] A. To
 * function as a call-by-value fixed point, we define the long-tailed-lark as
 * [C] [B] [A] longTailedLark == [C] [[B] B] A. The extra [C] serves the same function
 * as the `u` in the Z combinator.
 * 
 * When we make a Z combinator using a long-tailed-lark, we have a Resplendent QUetzal.
 */

// [C] [B] [A] longTailedLark == [C] [[B] B] A
export const longTailedLark = proper([ [C], [B], [A] ], [ [C], [[B], B], A ]);

export const resplendentQuetzal = construction([ [Fn] ], [ [longTailedLark], [mockingbird], bluebird ]);

displayAs({ 'long-tailed-lark': longTailedLark, 'resplendent-quetzal': resplendentQuetzal });

// ---------- test cases ----------

const isEven = construction([ [N] ], [
  [
    swap, dup, isZero,
      [
        [pred], cons,
        dup, isZero,
          [
            [pred], cons, thrush
          ],
          [ zap, zap, [F] ],
        cond
      ],
      [ zap, zap, [T] ],
    cond
  ], resplendentQuetzal
]);

test("resplendent-quetzal isEven", () => {
  expect(render([ [0], isEven ])).toEqual(render([ [T] ]));
  expect(render([ [1], isEven ])).toEqual(render([ [F] ]));
  expect(render([ [2], isEven ])).toEqual(render([ [T] ]));
  expect(render([ [3], isEven ])).toEqual(render([ [F] ]));
});