Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active January 27, 2026 02:07
Show Gist options
  • Select an option

  • Save kenwebb/a3e08c9caf59947e9f3a73ac748f79b3 to your computer and use it in GitHub Desktop.

Select an option

Save kenwebb/a3e08c9caf59947e9f3a73ac748f79b3 to your computer and use it in GitHub Desktop.
Lambda Calculus - 2025 Dec 30
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Mon Jan 26 2026 21:07:03 GMT-0500 (Eastern Standard Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Lambda Calculus - 2025 Dec 30
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: a3e08c9caf59947e9f3a73ac748f79b3
Keywords:
My Notes
--------
2025 Dec 30
### TODO
Dec 31, Jan 1
- I should only need primitive Lambda Calculus functions as in GM book
- instead of long functions, name and use the shorter primitive functions
- do this in a new Lambda node
- do exactly what's in the book
- use refs[2,3] to help get the primitive Lambdas working
- "Pair" is a key concept for Lambda Calculus and for Xholon, and in Xholon Bigraph notation
2026 Jan 5
- DONE I've added Aaa_p73_Jan5 Lambda node for Recursion
- TODO combine all that I've done so far into one Lambda node
-
2026 Jan 6
- SICP book pair p.79
- see Lambda SICPjs 01 in the CSH of this workbook
- each pair could also have Xholon properties in it, or a complete Xholon object
- type, role, other attributes, ptr to XholonClass, etc
-
http://127.0.0.1:8080/Xholon.html?app=Lambda+Calculus+-+2025+Dec+30&src=lstr&gui=clsc
http://127.0.0.1:8080/Xholon.html?app=a3e08c9caf59947e9f3a73ac748f79b3&src=gist&gui=clsc
### References
(1) Greg Michaelson, Functional Programming through Lambda Calculus, 2011
(2) https://wal.sh/research/lambda-calculus-in-javascript.html
Lambda Calculus Implementation in JavaScript, Introduction
This org-mode file contains a Lambda Calculus implementation in JavaScript. Each section includes self-contained code blocks that can be run independently in a JavaScript environment.
LOTS OF EXAMPLES
(3) https://github.com/jwalsh/lambda-calculus-polyglot
Lambda Calculus implementations in 20+ programming languages: functional, imperative, and logic paradigms
Created by Claude (Anthropic, PBC)
(4) https://rosettacode.org/wiki/Y_combinator#JavaScript
Y Combinator in javascript
can be used for recursion
(5) Harold Abelson, et al, Structure and Interpretation of Computer Programs - JAVASCRIPT EDITION, 2022
(6) https://sourceacademy.org/sicpjs/
) https://sourceacademy.org/playground/
(7) https://www.youtube.com/watch?v=eis11j_iGMs
Lambda Calculus, by Prof. Graham Hutton
1,068,679 views Jan 27, 2017
The basis of almost all functional programming, Professor Graham Hutton explains Lambda Calculus.
This video was filmed and edited by Sean Riley.
Computer Science at the University of Nottingham: http://bit.ly/nottscomputer
Computerphile is a sister project to Brady Haran's Numberphile. More at http://www.bradyharan.com
(8) https://www.youtube.com/watch?v=9T8A89jgeTI
Essentials: Functional Programming's Y Combinator - Computerphile
342,336 views Aug 16, 2017
Encoding recursion in the Lambda calculus, one of Professor Graham Hutton's favourite functions.
(9) https://www.youtube.com/@Computerphile
(10) https://rosettacode.org/wiki/Y_combinator#JavaScript
(11) LOGO - A Language for Learning
Virginia Carter Grammer, E. Paul Goldenberg, Leigh Klotz Jr. Terrapin 1982, 1983
MIT 1981
this is a book I have had for a long time, it came with my Commodore 64
() https://www.youtube.com/watch?v=KuVUfbWoROw
Smallest Pure Functional Language in C
Tsoding Daily 189K subscribers
47,942 views Dec 16, 2025
() https://github.com/tsoding/lamb/blob/main/README.md
Tiny Pure Functional Programming Language in C. Based on Untype Lambda Calculus with Normal Order reduction.
() https://en.wikipedia.org/wiki/Lambda_calculus_definition#Notation
The lambda calculus is a formal mathematical system consisting of constructing lambda terms and
performing reduction operations on them.
The definition of a lambda term is simply a variable, a lambda abstraction, or a function application,
but a formal presentation can be somewhat lengthy.
The focus of this article is to present a full and complete definition of the lambda calculus,
specifically the pure untyped lambda calculus without extensions,
although a lambda calculus extended with numbers and arithmetic is used for explanatory purposes.
() https://www.mathstat.dal.ca/~selinger/papers/lambdanotes.pdf
Lecture Notes on the Lambda Calculus
Peter Selinger
Department of Mathematics and Statistics
Dalhousie University, Halifax, Canada
Abstract
This is a set of lecture notes that developed out of courses on the lambda
calculus that I taught at the University of Ottawa in 2001 and at Dalhousie
University in 2007 and 2013. Topics covered in these notes include the un-
typed lambda calculus, the Church-Rosser theorem, combinatory algebras,
the simply-typed lambda calculus, the Curry-Howard isomorphism, weak
and strong normalization, polymorphism, type inference, denotational se-
mantics, complete partial orders, and the language PCF.
() https://homepage.cs.uiowa.edu/~slonnegr/plf/Book/Chapter5.pdf
Chapter 5 THE LAMBDA CALCULUS
() https://plato.stanford.edu/archives/win2025/entries/lambda-calculus/
First published Wed Dec 12, 2012; substantive revision Tue Jul 25, 2023
The λ-calculus is, at heart, a simple notation for functions and application.
The main ideas are applying a function to an argument and forming functions by abstraction.
The syntax of basic λ-calculus is quite sparse, making it an elegant,
focused notation for representing functions.
Functions and arguments are on a par with one another.
The result is a non-extensional theory of functions as rules of computation,
contrasting with an extensional theory of functions as sets of ordered pairs.
Despite its sparse syntax, the expressiveness and flexibility of the λ-calculus
make it a cornucopia of logic and mathematics.
This entry develops some of the central highlights of the field and prepares the reader for
further study of the subject and its applications in philosophy, linguistics, computer science, and logic.
()
α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω
Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω
]]></Notes>
<markdown><![CDATA[
### quotes from ref[5 6] p.73-74
**Pairs**
To enable us to implement the concrete level of our data abstraction, our JavaScript environment provides a compound structure called a pair, which can be constructed with the primitive functionpair. This function takes two arguments and returns a compound data object that contains the two arguments as parts. Given a pair, we can extract the parts using the primitive functionshead and tail. Thus, we can use pair,head, and tail as follows:
Notice that a pair is a data object that can be given a name and manipulated, just like a primitive data object. Moreover, pair can be used to form pairs whose elements are pairs, and so on
this ability to combine pairs means that pairs can be used as general-purpose building blocks to create all sorts of complex data structures. The single compound-data primitive pair, implemented by the functionspair,head, and tail, is the only glue we need. Data objects constructed from pairs are called list-structured data.
### Ollama prompts and responses
ken@Mac ~ % ollama run gemma3:12b
>>>
>>> ["Cytoplasm",
... [
... ["Hexokinase",
... ["PhosphoGlucoIsomerase",
... ["PhosphoFructokinase",
... ["Aldolase",
... ["TriosePhosphateIsomerase",
... ["Glyceraldehyde_3_phosphateDehydrogenase",
... ["PhosphoGlycerokinase",
... ["PhosphoGlyceromutase",
... ["Enolase",
... ["PyruvateKinase", null
... ]]]]]]]]]],
... ["Cytosol",
... [
... ["Glucose",
... ["Glucose_6_Phosphate",
... ["Fructose_6_Phosphate",
... ["Fructose_1x6_Biphosphate",
... ["DihydroxyacetonePhosphate",
... ["Glyceraldehyde_3_Phosphate",
... ["X1x3_BisphosphoGlycerate",
... ["X3_PhosphoGlycerate",
... ["X2_PhosphoGlycerate",
... ["PhosphoEnolPyruvate",
... ["Pyruvate", null
... ]]]]]]]]]]],
... null
... ]
... ]
... ]
... ]
Okay, let's break down this data structure. It seems to represent a hierarchical view of the glycolysis pathway, including enzymes and
metabolites, organized by location (Cytoplasm and Cytosol).
Here's a more readable interpretation, emphasizing the relationships:
**Overall Structure:**
* The entire structure represents the **Glycolysis Pathway**.
* It is primarily located within the **Cytoplasm**. A section also details the cytosol specifically.
* The pathway is built from a series of enzymes which work on metabolites.
* The "null" at the very end indicates the final metabolite (Pyruvate).
**Detailed Breakdown:**
1. **Cytoplasm (Main Pathway)**: This section lists the enzymes involved in Glycolysis in sequence. Each enzyme is a node, and
where there's a metabolite associated with it (e.g. "Glucose"), the metabolite is a child. Let's trace the sequence:
* **Hexokinase:** Begins the process.
* **PhosphoGlucoIsomerase:** Converts Glucose-6-Phosphate.
* **PhosphoFructokinase:** Another crucial regulatory step.
* **Aldolase:** Splits a 6-carbon molecule.
* **TriosePhosphateIsomerase:** Interconverts triose phosphates.
* **Glyceraldehyde_3_phosphateDehydrogenase:** A key oxidation step.
* **PhosphoGlycerokinase:** Phosphorylates a molecule.
* **PhosphoGlyceromutase:** Rearranges a phosphate group.
* **Enolase:** Another rearrangement.
* **PyruvateKinase:** The final enzymatic step.
* **null**: End of the pathway - Pyruvate.
2. **Cytosol (Metabolite Flow)**: This section is dedicated to tracing the flow of metabolites.
* **Glucose:** The initial substrate.
* **Glucose_6_Phosphate:** Formed by Hexokinase.
* **Fructose_6_Phosphate:** A key intermediate.
* **Fructose_1x6_Biphosphate:** Phosphorylated intermediate.
* **DihydroxyacetonePhosphate:** A byproduct of the aldolase cleavage.
* **Glyceraldehyde_3_Phosphate:** One of the triose phosphate products.
* **X1x3_BisphosphoGlycerate:** (Likely a typo, should be 1,3-BisphosphoGlycerate)
* **X3_PhosphoGlycerate:** (Likely a typo, should be 3-PhosphoGlycerate)
* **X2_PhosphoGlycerate:** (Likely a typo, should be 2-PhosphoGlycerate)
* **PhosphoEnolPyruvate:** A high-energy intermediate.
* **Pyruvate:** The final product.
* **null**: End of Metabolite Path
**Data Structure Notes:**
* **Nested Lists:** The data uses nested lists to represent the hierarchical relationship. Each list represents a node (enzyme or
metabolite).
* **Children:** The elements within a list are the 'children' of the parent node. This indicates a sequential step or a
transformation.
* **"null":** Indicates the end of a branch or the final product/output.
* **Typographical Errors:** There appear to be some minor typos in the metabolite names (e.g. "X1x3_BisphosphoGlycerate" should be
"1,3-BisphosphoGlycerate" and similarly for others).
**Purpose and Use:**
This kind of structure is useful for:
* **Visualization:** Can be used to create a diagram or interactive representation of the glycolysis pathway.
* **Algorithm Representation:** Can be used to build algorithms for simulating or analyzing the pathway (e.g., flux balance
analysis).
* **Data Storage and Retrieval:** Provides a structured way to store information about the pathway's components and their
relationships.
* **Educational Tool:** Helps to understand the order and relationships between enzymes and metabolites in glycolysis.
To help me further, can you tell me:
1. What is the intended use of this data structure?
2. Are the "X" prefixed names meant to represent something specific?
3. Is there an expected way to process this data (e.g., to generate a visualization or a set of data)?
>>> The format I have used is called "box notation". It has been used in Lisp and Scheme programming, and in the SICP book.
Okay, that's incredibly helpful! Knowing it's "box notation" from the SICP tradition makes everything much clearer. It explains the
unusual formatting and the hierarchical structure's purpose.
Here's a reinterpretation of the data, now viewed through the lens of box notation, along with how it's typically used and what
implications it has for processing it:
**Understanding Box Notation in the Context of SICP**
* **Data as Structure:** Box notation emphasizes that data *is* a structure. The key idea is to represent relationships between
things explicitly within the data itself, rather than relying on external conventions or pointers.
* **Pairs and Lists:** The core building blocks are pairs (often represented as `(item1 item2)`) and lists (`(item1 item2 ...
itemN)`). The first element of a pair is often called the 'car' (or first), and the second is called the 'cdr' (or rest). Lists are
essentially linked pairs.
* **Recursive Definition:** Box notation inherently encourages recursive thinking. A structure can be defined in terms of itself.
This makes it very suitable for representing hierarchical data.
* **No External References:** Data objects within a box structure *only* refer to other data objects within the same structure. No
pointers to external memory locations. This contributes to the structure's self-contained nature.
**Reinterpreting the Glycolysis Data in Box Notation**
Let's analyze the structure you provided, understanding that each part represents a nested list/pair:
```
[ "Cytoplasm",
[
[ "Hexokinase",
[ "PhosphoGlucoIsomerase",
[ "PhosphoFructokinase",
[ "Aldolase",
[ "TriosePhosphateIsomerase",
[ "Glyceraldehyde_3_phosphateDehydrogenase",
[ "PhosphoGlycerokinase",
[ "PhosphoGlyceromutase",
[ "Enolase",
[ "PyruvateKinase", null ]
]
]
]
]
]
]
]
]
],
[ "Cytosol",
[
[ "Glucose",
[ "Glucose_6_Phosphate",
[ "Fructose_6_Phosphate",
[ "Fructose_1x6_Biphosphate",
[ "DihydroxyacetonePhosphate",
[ "Glyceraldehyde_3_Phosphate",
[ "X1x3_BisphosphoGlycerate",
[ "X3_PhosphoGlycerate",
[ "X2_PhosphoGlycerate",
[ "PhosphoEnolPyruvate",
[ "Pyruvate", null ]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
```
* **The Top-Level List:** `["Cytoplasm", ...]` represents the root of the structure. The first element is a string label
("Cytoplasm"), and the second is a list containing the children of "Cytoplasm."
* **Enzyme/Metabolite Nodes:** Each enzyme (e.g., `"Hexokinase"`) or metabolite (e.g., `"Glucose"`) is represented as a string
*within* a list.
* **"Car" and "Cdr":** For example, `["Hexokinase", ["PhosphoGlucoIsomerase", ...]]` means that "Hexokinase" is the 'car' of the
pair, and the list starting with "PhosphoGlucoIsomerase" is the 'cdr' (the rest of the pair). The 'cdr' represents the children of
"Hexokinase."
* **`null`:** The `null` signifies the end of the list (the 'cdr' is empty).
**How to Process Box Notation in a SICP-style Language (Lisp/Scheme)**
In a Lisp or Scheme interpreter, you'd use functions like `car`, `cdr`, and recursion to traverse and process this structure:
```scheme
;; (Assuming you've loaded the data into a variable called 'glycolysis)
(define (print-path path)
(cond
[(null? path) '()] ; Base case: end of the list
[(string? (car path)) ; If it's a string (enzyme/metabolite)
(display (car path))
(display " -> ")
(print-path (cdr path)) ; Recursive call on the 'cdr'
)
[else ; It's a list (a node with children)
(print-path (cdr path)) ; Process the children first
]
)
)
(print-path glycolysis)
```
This simple Scheme function would recursively traverse the structure, printing the enzyme/metabolite names as it goes.
**Advantages of this Representation with Box Notation:**
* **Explicit Structure:** The relationships are directly encoded in the data.
* **Natural Recursion:** Easy to write recursive functions to process the data.
* **Minimal External Dependencies:** The data is self-contained.
* **Easy serialization:** Can be easily encoded as strings for storage and transmission.
Do you want me to:
1. Write an example in Scheme/Lisp that processes this data in a more complex way (e.g., to create a data structure representing the
pathway's connections)?
2. Help you translate this into a different format, if you have a specific end-goal in mind?
3. Elaborate on any aspect of box notation or its processing?
>>> Send a message (/? for help)
]]></markdown>
<_-.XholonClass>
<PhysicalSystem/>
<Lambda superClass="Script"/>
</_-.XholonClass>
<xholonClassDetails>
<Lambda><Color>indigo</Color></Lambda>
<Avatar><Color>red</Color></Avatar>
</xholonClassDetails>
<PhysicalSystem>
<Lambda roleName="Aaa_p31"><![CDATA[
var beh = {};
(() => {
const identity = x => x // λx.x
const apply = func => arg => func(arg) // λfunc.λarg(func arg)
const self_apply = s => s(s) // λs.(s s)
const identity2 = x => apply(identity)(x) // λx ((apply identity) x)
const select_first = first => second => first // λfirst.λsecond.first
const select_second = first => second => second // λfirst.λsecond.second
// NO const make_pair = first => second => func => func(first)(second) // λfirst.λsecond.λfunc.((func first) second)
// ============================================================
//testing
console.log(identity("Hello Lambda"));
const double = x => x*2
const myval = 23
console.log(double(myval));
console.log(self_apply(identity));
console.log(self_apply(double));
console.log(apply(double)(myval));
console.log(apply(identity)(identity));
console.log(identity2(identity));
console.log(apply(identity2)(identity));
console.log(select_first(1)(22));
console.log(select_second(1)(22));
// NO console.log(make_pair(333)(4444)(identity));
})()
//# sourceURL=Aaa_p31.js
]]></Lambda>
<Lambda roleName="Bbb_walsh"><![CDATA[
var beh = {};
// https://wal.sh/research/lambda-calculus-in-javascript.html
// Lambda Expressions
// ------------------
const step1 = (title) => {
console.log(title);
// Step 1: Understand Lambda Expressions
const identity = x => x;
console.log(identity(5));
// Output: 5
};
step1("STEP 1");
// Church Booleans
// ---------------
const step2 = (title) => {
console.log(title);
// Step 2: Implement Church Booleans
const lcTrue = x => y => x;
const lcFalse = x => y => y;
const lcIf = condition => then => else_ => condition(then)(else_);
console.log(lcIf(lcTrue)("yes")("no"));
// Output: yes
};
step2("STEP 2");
// Basic Combinators
// -----------------
const step3 = (title) => {
console.log(title);
// Step 3: Implement Basic Combinators
const I = x => x;
const K = x => y => x;
const KI = x => y => y;
console.log(I(5));
console.log(K(3)(4));
console.log(KI(3)(4));
// Output:
// 5
// 3
// 4
};
step3("STEP 3");
// Church Numerals
// ---------------
const step4 = (title) => {
console.log(title);
// Step 4: Create Church Numerals
const lcZero = f => x => x;
const lcSucc = n => f => x => f(n(f)(x));
const churchToInt = n => n(x => x + 1)(0);
const lcOne = lcSucc(lcZero);
const lcTwo = lcSucc(lcOne);
console.log(churchToInt(lcZero));
console.log(churchToInt(lcOne));
console.log(churchToInt(lcTwo));
// Output:
// 0
// 1
// 2
};
step4("STEP 4");
// Basic Arithmetic
// ----------------
const step5 = (title) => {
console.log(title);
// Step 5: Implement Basic Arithmetic
const lcZero = f => x => x;
const lcSucc = n => f => x => f(n(f)(x));
const churchToInt = n => n(x => x + 1)(0);
const lcAdd = m => n => f => x => m(f)(n(f)(x));
const lcMult = m => n => f => m(n(f));
const lcOne = lcSucc(lcZero);
const lcTwo = lcSucc(lcOne);
const lcThree = lcSucc(lcTwo);
console.log(churchToInt(lcAdd(lcOne)(lcTwo)));
console.log(churchToInt(lcMult(lcTwo)(lcThree)));
// Output:
// 3
// 6
};
step5("STEP 5");
// Pairs
// -----
const step6 = (title) => {
console.log(title);
// Step 6: Implement Pairs
const lcPair = x => y => f => f(x)(y);
const lcFirst = p => p(x => y => x);
const lcSecond = p => p(x => y => y);
const myPair = lcPair(3)(4);
console.log(lcFirst(myPair));
console.log(lcSecond(myPair));
// Output:
// 3
// 4
};
step6("STEP 6");
// Lists
// -----
const step7 = (title) => {
console.log(title);
// Step 7: Build Lists Using Pairs
const lcTrue = x => y => x;
const lcFalse = x => y => y;
const lcPair = x => y => f => f(x)(y);
const lcFirst = p => p(x => y => x);
const lcSecond = p => p(x => y => y);
const lcNil = x => lcTrue;
const lcCons = lcPair;
const lcIsNil = l => l(h => t => lcFalse);
const lcHead = lcFirst;
const lcTail = lcSecond;
// Helper function to convert JavaScript array to Church-encoded list
const listToChurch = arr => {
if (arr.length === 0) return lcNil;
return lcCons(arr[0])(listToChurch(arr.slice(1)));
};
// Helper function to convert Church-encoded list to JavaScript array
const churchToList = l => {
const result = [];
let current = l;
while (lcIsNil(current)(false)(true)) {
result.push(lcHead(current));
current = lcTail(current);
}
return result;
};
const myList = listToChurch([1, 2, 3]);
console.log(churchToList(myList));
console.log(lcHead(myList));
console.log(churchToList(lcTail(myList)));
console.log(lcIsNil(myList)(true)(false));
console.log(lcIsNil(lcNil)(true)(false));
// Output:
// [1, 2, 3]
// 1
// [2, 3]
// false
// true
};
step7("STEP 7");
// Comparison Operations
// ---------------------
const step8 = (title) => {
console.log(title);
// Step 8: Implement Comparison Operations
const lcZero = f => x => x;
const lcSucc = n => f => x => f(n(f)(x));
const lcTrue = x => y => x;
const lcFalse = x => y => y;
const lcIsZero = n => n(x => lcFalse)(lcTrue);
const lcLeq = m => n => lcIsZero(lcSub(m)(n));
const lcEq = m => n => lcAnd(lcLeq(m)(n))(lcLeq(n)(m));
const lcAnd = x => y => x(y)(lcFalse);
const lcSub = m => n => n(n => f => x => n(g => h => h(g(f)))(y => x)(y => y))(m);
const lcOne = lcSucc(lcZero);
const lcTwo = lcSucc(lcOne);
console.log(lcIsZero(lcZero)(true)(false));
console.log(lcIsZero(lcOne)(true)(false));
console.log(lcLeq(lcOne)(lcTwo)(true)(false));
console.log(lcEq(lcOne)(lcOne)(true)(false));
console.log(lcEq(lcOne)(lcTwo)(true)(false));
// Output:
// true
// false
// true
// true
// false
};
step8("STEP 8");
//# sourceURL=Bbb_walsh.js
]]></Lambda>
<LambdaFAILS roleName="Ccc_walsh"><![CDATA[
var beh = {};
// Higher-Order List Operations
// ----------------------------
const step9 = (title) => {
console.log(title);
// Step 9: Implement Higher-Order List Operations
const lcZero = f => x => x;
const lcSucc = n => f => x => f(n(f)(x));
const lcTrue = x => y => x;
const lcFalse = x => y => y;
const lcPair = x => y => f => f(x)(y);
const lcFirst = p => p(x => y => x);
const lcSecond = p => p(x => y => y);
const lcNil = x => lcTrue;
const lcCons = lcPair;
const lcIsNil = l => l(h => t => lcFalse);
const lcHead = lcFirst;
const lcTail = lcSecond;
// KSW fails
const lcIf = condition => then => else_ => condition(then)(else_);
const lcMap = f => l => lcIf(lcIsNil(l))
(lcNil)
(() => lcCons(f(lcHead(l)))(lcMap(f)(lcTail(l))))();
// KSW fails
const lcFilter = p => l => lcIf(lcIsNil(l))
(lcNil)
(() => lcIf(p(lcHead(l)))
(() => lcCons(lcHead(l))(lcFilter(p)(lcTail(l))))
(() => lcFilter(p)(lcTail(l))))();
const lcFold = f => acc => l => lcIf(lcIsNil(l))
(acc)
(() => lcFold(f)(f(acc)(lcHead(l)))(lcTail(l)))();
const listToChurch = arr => {
if (arr.length === 0) return lcNil;
return lcCons(arr[0])(listToChurch(arr.slice(1)));
};
// KSW fails
const churchToList = l => {
const result = [];
let current = l;
while (lcIsNil(current)(false)(true)) {
result.push(lcHead(current));
current = lcTail(current);
}
return result;
};
const myList = listToChurch([1, 2, 3]);
const doubledList = lcMap(x => x * 2)(myList);
//console.log("Doubled list:", churchToList(doubledList)); // KSW fails
//const filteredList = lcFilter(x => x > 1)(myList); // KSW fails
//console.log("Filtered list:", churchToList(filteredList)); // KSW fails
const sumList = lcFold(x => y => x + y)(0)(myList);
console.log("Sum of list:", sumList);
// Output:
// Doubled list: [2, 4, 6]
// Filtered list: [2, 3]
// Sum of list: 6
};
step9("STEP 9");
//# sourceURL=Ccc_walsh.js
]]></LambdaFAILS>
<Lambda roleName="Ddd_walsh"><![CDATA[
// Recursion and Fixed-Point Combinators
// -------------------------------------
const step10 = (title) => {
console.log(title);
// Step 10: Explore Recursion and Fixed-Point Combinators
const lcZero = f => x => x;
const lcSucc = n => f => x => f(n(f)(x));
const lcTrue = x => y => x;
const lcFalse = x => y => y;
const lcIf = condition => then => else_ => condition(then)(else_);
const lcIsZero = n => n(x => lcFalse)(lcTrue);
const lcSub = m => n => n(n => f => x => n(g => h => h(g(f)))(y => x)(y => y))(m);
const lcMult = m => n => f => m(n(f));
const churchToInt = n => n(x => x + 1)(0);
const lcOne = lcSucc(lcZero);
const Y = f => (x => f(y => x(x)(y)))(x => f(y => x(x)(y)));
const factorial = Y(f => n => lcIf(lcIsZero(n))
(lcOne)
(() => lcMult(n)(f(lcSub(n)(lcOne))))());
const lcFive = lcSucc(lcSucc(lcSucc(lcSucc(lcOne))));
console.log(lcFive);
//console.log("Factorial of 5:", churchToInt(factorial(lcFive))); // KSW fails
// Output:
// Factorial of 5: 120
};
step10("STEP 10");
//# sourceURL=Ddd_walsh.js
]]></Lambda>
<Lambda roleName="Aaa_p31_Jan1"><![CDATA[
var beh = {};
(() => {
const identity = x => x // λx.x
const apply = func => arg => func(arg) // λfunc.λarg(func arg)
const self_apply = s => s(s) // λs.(s s)
const identity2 = x => apply(identity)(x) // λx ((apply identity) x)
const select_first = first => second => first // λfirst.λsecond.first
const select_second = first => second => second // λfirst.λsecond.second
// this is the same as lcPair from ref[2]
const make_pair = first => second => func => func(first)(second) // λfirst.λsecond.λfunc((func first) second)
// from ref[2]
const lcPair = x => y => f => f(x)(y);
const lcFirst = p => p(x => y => x); // get the first from a pair; this is different from select_first
const lcSecond = p => p(x => y => y); // get the second from a pair; this is different from select_second
const lcFirst2 = p => p(select_first);
const lcSecond2 = p => p(select_second);
const lcTrue = x => y => x; // same as select_first
const lcFalse = x => y => y; // same as select_second
// ============================================================
//testing
console.log(identity("Hello Lambda"));
const double = x => x*2
const myval = 23
console.log(double(myval));
console.log(self_apply(identity));
console.log(self_apply(double));
console.log(apply(double)(myval));
console.log(apply(identity)(identity));
console.log(identity2(identity));
console.log(apply(identity2)(identity));
console.log(select_first(1)(22));
console.log(select_second(1)(22));
const myPair = lcPair(3)(4);
console.log(lcFirst(myPair)); // OK
console.log(lcSecond(myPair)); // OK
//console.log(make_pair(333)(4444)(identity)); // NO
const myPair2 = make_pair(333)(4444);
console.log(lcFirst(myPair2)); // OK
console.log(lcSecond(myPair2)); // OK
console.log(lcFirst2(myPair2)); // OK
console.log(lcSecond2(myPair2)); // OK
// GM book p. 50 2026 Jan 1
// conditional expression in C: <condition>?<expression>:expression
const cond = e1 => e2 => c => c(e1)(e2);
const trew = select_first;
const fals = select_second;
const gte = x => y => x >= y;
const maxx = cond(5)(6)(gte);
console.log(maxx);
const max = cond;
console.log(max(6)(5)(gte));
//const absx = cond;
//console.log(absx()()()); // ???
// p. 51 - 52
//const not = x => cond(false)(true)(x); // maybe use lcTrue and lcFalse ???
//console.log(not(() => true)); // ???
// def not = λx.((x false) true)
const not = x => x ? false : true;
console.log(not(true));
console.log(not(false));
console.log(not(1 === 1));
// def and = λx.λy.((x y) false)
//const and = x => y => ??? // maybe use lcTrue and lcFalse ???
})()
//# sourceURL=Aaa_p31_Jan1.js
]]></Lambda>
<!-- all of this works! -->
<Lambda roleName="Aaa_p73_Jan5"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
// 4.1 p. 66-68 an iterative algorithm
const eatI = (n) => {
let count = n;
while (count > 0) {
console.log("gobble an appleI " + count);
count--;
}
}
eatI(2);
// 4.1 p. 66-68 a recursive algorithm
// console.log("gobble an apple");
// I cannot get this to work
//const eat = (n) => n === 0 ? n : eat(n-1) && console.log("gobble an apple " + n);
// this works!
//const eatx = function(n) {
// console.log("gobble an apple " + n);
// if (n === 0) {
// return n;
// } else {
// //console.log("gobble an apple " + n);
// return eat(n - 1);
// }
//}
// this works!
//const eatxx = function(n) {
// console.log("gobble an apple " + n);
// return (n === 0) ? n : eat(n - 1);
//}
// this works!
//const eatxxx = (n) => {
// console.log("gobble an apple " + n);
// return (n > 1) ? eat(n - 1) : null;
//}
// this works!
const eat = (n) => (n > 0) ? console.log("gobble an apple " + n + " " + eat(n - 1)) : null;
eat(5);
eat(3);
const identity = x => x // λx.x
const apply = func => arg => func(arg) // λfunc.λarg(func arg)
const zero = () => 0;
const iszero = x => x == 0 ? true : false;
const succ = x => x + 1;
const pred = x => x - 1;
const addd = a => b => a + b;
const multt = a => b => a * b;
const one = () => succ(zero());
const two = () => succ(one());
const three = () => succ(two());
console.log(addd(11)(22));
console.log(multt(21)(2));
console.log(zero());
console.log(iszero(0), iszero(3));
console.log(pred(5), 5, succ(5));
/* GM book p. 68 4.2 Recursion
def add x y =
if iszero y
then x
else add (succ x) (pred y)
*/
const add = x => y => iszero(y) ? x : add(succ(x))(pred(y));
console.log(add(11)(22));
console.log(add(0)(0));
console.log(add(13)(0));
console.log(add(0)(17));
/* GM book p. 73 4.5 Recursion function
def mult x y =
if iszero y
then zero
else add x (mult x (pred y))
*/
// y must be a non-negative integer; y must be a number
const mult = x => y => iszero(y) ? zero() : addd(x)(mult(x)(pred(y)));
console.log(mult(3)(2));
console.log(mult(21)(2));
console.log(mult(two())(three()));
console.log(mult(44)(55)); // 2420
console.log(mult(zero())(zero()));
console.log(mult(zero())(5));
console.log(mult(7)(zero()));
console.log(mult(-5)(5));
console.log(mult(-13.45)(3));
// p.74 :We would like to have a function 'recursive' ...
// TODO
// def recursive f = <'f' and copy>
// see also ref[4] Y Combinator
})("Aaa_p73_Jan5 Recursion")
//# sourceURL=Aaa_p73_Jan5.js
]]></Lambda>
<Lambda roleName="SICPjs_01"><![CDATA[
var beh = {};
// SICP JS book p.79+ Chapter 2 "Building Abstractions with Data"
((title) => {
console.log(title);
this.println(title);
const pair = (x, y) => (m) => m === 0
? x
: m === 1
? y
: error(m, "arg not 0 or 1 -- pair");
const head = z => z(0);
const tail = z => z(1);
const display = x => console.log(x);
const pair2 = pair(33, 444);
const head2 = head(pair2);
const tail2 = tail(pair2);
display(pair2); // function pair(m)
display(head2); // 33
const root = $wnd.xh.root();
const xhpair01 = pair(root.first(), root.first().first());
console.log(head(xhpair01).name(), tail(xhpair01).name());
})("SICPjs_01")
//# sourceURL=SICPjs_01.js
]]></Lambda>
<Lambda roleName="SICPjs_02"><![CDATA[
var beh = {};
// SICP JS book p.79+ Chapter 2 "Building Abstractions with Data" Xholon
((title) => {
console.log(title);
this.println(title);
// obj contains Xholon-type attributes/properties
const pair = (x, y, obj = {name: "testing"}) => (m) => m === 0
? x
: m === 1
? y
: m === 2
? obj
: error(m, "arg not 0 or 1 or 2 -- pair");
const head = z => z(0);
const tail = z => z(1);
const obj = z => z(2);
const display = x => console.log(x);
const pair2 = pair(33, 444);
const head2 = head(pair2);
const tail2 = tail(pair2);
display(pair2); // function pair(m)
display(head2); // 33
display(obj(pair2));
const root = $wnd.xh.root();
const xhpair01 = pair(root.first(), root.first().first(), {id: root.id(), role: root.role(), xhc: root.xhc().name()});
console.log(head(xhpair01).name(), tail(xhpair01).name(), obj(xhpair01));
})("SICPjs_02")
//# sourceURL=SICPjs_02.js
]]></Lambda>
<Lambda roleName="SICPjs_03"><![CDATA[
var beh = {};
// SICP JS book p.80 Chapter 2 "Building Abstractions with Data" Exercise 2.4
/*
Exercise 2.4
Here is an alternative functional representation of pairs. For this representation, verify that head(pair(x, y)) yields x for any objects x and y.
function pair(x, y) {
return m => m(x, y);
}
function head(z) {
return z((p, q) => p);
}
What is the corresponding definition of tail? (Hint: To verify that this works, make use of the substitution model of section 1.1.5.)
*/
((title) => {
console.log(title);
this.println(title);
const pair = (x, y) => m => m(x, y); // this works!
// this is a variant of Michaelson ref[1] p.36 make_pair
// const make_pair = first => second => func => func(first)(second) // def make_pair = λfirst.λsecond.λfunc.((func first) second)
const pairGM = x => y => m => m(x, y); // this works!
//const pairGM = x => y => m => m(x)(y); // NO
const head = z => z((p, q) => p);
const tail = z => z((p, q) => q);
//const obj = z(p, q, r) => ???
const display = x => console.log(x);
// YES
const pair2 = pair(33, 444);
const head2 = head(pair2);
const tail2 = tail(pair2);
display(pair2); // function pair(m)
display(head2); // 33
display(tail2); // 444
// YES curried args
const pair3 = pairGM(55)(666);
const head3 = head(pair3);
const tail3 = tail(pair3);
display(pair3); // function pair(m)
display(head3); // 55
display(tail3); // 666
})("SICPjs_03")
//# sourceURL=SICPjs_03.js
]]></Lambda>
<Lambda roleName="SICPjs_Sequences"><![CDATA[
var beh = {};
/*
SICP 2.2 Hierarchical Data and the Closure Prperty
Figure 2.3 Two ways to combine 1, 2, 3 and 4 using pairs
2.2.1 Representing Sequences
TODO:
- write a list function that converts a csv list into a sequence of pairs
- write a recursive function that will stringify/boxify a pair, sequence, list, tree as nested brackets (JS array)
[[1,2][3,4]]
p.86 calls this "box notation"
*/
((title) => {
console.log(title);
this.println(title);
const pair = (x, y) => m => m(x, y); // this works!
const pairGM = x => y => m => m(x, y); // this works!
const head = z => z((p, q) => p);
const tail = z => z((p, q) => q);
//const obj = z(p, q, r) => ???
const display = x => console.log(x);
//const pair0 = pair(1, 2);
const pair0 = pairGM(1)(2);
const head0 = head(pair0);
const tail0 = tail(pair0);
display(pair0);
display(head0);
display(tail0);
//const pair1 = pair(3, 4);
const pair1 = pairGM(3)(4);
const head1 = head(pair1);
const tail1 = tail(pair1);
display(pair1);
display(head1);
display(tail1);
//const pair3 = pair(pair0, pair1);
const pair3 = pairGM(pair0)(pair1);
display("pair3:");
display(pair3); // function pair(m)
display(head(pair3)); // function pair(m)
display(tail(pair3)); // function pair(m)
display(head(head(pair3))); // 1
display(tail(head(pair3))); // 2
display(head(tail(pair3))); // 3
display(tail(tail(pair3))); // 4
//const pair4 = pair(pair(1,2), pair(3,4)); // see Figure 2.3 p.85 [[1,2],[3,4]]
//const pair5 = pair(pair(1, pair(2,3)), 4); // [[1, [2,3]], 4]
const pair4 = pairGM(pairGM(1)(2))(pairGM(3)(4)); // see Figure 2.3 p.85
const pair5 = pairGM(pairGM(1)(pairGM(2)(3)))(4);
// Figure 2.4 The sequence 1, 2, 3, 4 represented as a chain of pairs
//const seq1 = pair(1, pair(2, pair(3, pair(4, null))));
const seq1 = pairGM(1)(pairGM(2)(pairGM(3)(pairGM(4)(null))));
// this can also be expressed as list(1,2,3,4)
// boxify this works!
const boxify = pr => typeof pr === "function"
? "[" + boxify(head(pr)) + ", " + boxify(tail(pr)) + "]"
: pr
display(boxify(pair0)); // [1, 2]
display(boxify(pair1)); // [3, 4]
display(boxify(pair3)); // [[1, 2], [3, 4]]
display(boxify(pair4)); // [[1, 2], [3, 4]]
display(boxify(pair5)); // [[1, [2, 3]], 4]
display(boxify(seq1)); // [1, [2, [3, [4, null]]]]
display(boxify(pairGM("one")("two"))); // [one, two]
// xholonify turn the structure into Xholon XML TODO
const xholonify = pr => typeof pr === "function"
? "<" + xholonify(head(pr)) + " " + xholonify(tail(pr)) + "/>"
: pr
display(xholonify(pair0)); //
})("SICPjs_Sequences")
//# sourceURL=SICPjs_Sequences.js
]]></Lambda>
<Lambda roleName="SICPjs_list"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
const pair = (x, y) => m => m(x, y); // this works!
const pairGM = x => y => m => m(x, y); // this works!
const head = z => z((p, q) => p);
const tail = z => z((p, q) => q);
const display = x => console.log(x);
const boxify = pr => typeof pr === "function"
? "[" + boxify(head(pr)) + ", " + boxify(tail(pr)) + "]"
: JSON.stringify(pr)
// the goal list for input "1,2,3,4"
const seq1 = pair(1, pair(2, pair(3, pair(4, null))));
/*
* list - a recursive function that generates a list from an array
* @param arr ex: [1,2,3,4]
* @result ex: pair(1, pair(2, pair(3, pair(4, null))))
*/
const list = arr => arr.length > 0
? pair(arr.pop(), list(arr))
: null
/*
* listArgs - generates a list from the function arguments
* @param args ex: 1,2,3,4
* @result ex: pair(1, pair(2, pair(3, pair(4, null))))
*/
const listArgs = (...args) => list(args.reverse())
display(boxify(listArgs(66,77,88,99,"hundred",true)));
const ab = "1,2,3,4".split(",").reverse();
const abc = (list(ab));
display(abc);
display(tail(abc));
display(boxify(abc)); // [1, [2, [3, [4, null]]]]
display(boxify(tail(abc))); // [2, [3, [4, null]]]
const de = "one,two,three,4,five".split(",").reverse();
display(de);
const def = (list(de));
display(def);
display(tail(def));
display(boxify(def)); // [one, [two, [three, [4, [five, null]]]]]
display(boxify(tail(def))); // [two, [three, [4, [five, null]]]]
display(boxify(pair("zero", tail(def))));
// p.87 List operations
const list_ref = (items, n) => n === 0
? head(items)
: list_ref(tail(items), n - 1)
display(list_ref(def, 3));
const is_null = thing => thing === null;
// p.88 length
const list_length = items => {
const length_iter = (a, count) => is_null(a)
? count
: length_iter(tail(a), count + 1)
return length_iter(items, 0);
}
const length = (items, count = 0) => is_null(items)
? count
: length(tail(items), count + 1)
display(list_length(def));
const list1 = list([1,2,3,4,5,6,7,8,9,10]);
display(list_ref(list1, 5));
display(list_length(list1));
display(length(list1));
//p.88 append
const append = (list1, list2) => is_null(list1)
? list2
: pair(head(list1), append(tail(list1), list2))
list2 = list([22,23,24,25]);
list3 = append(list1, list2);
display(list_length(list3));
display(boxify(list3));
// p.90
const scale_list = (items, factor) => is_null(items)
? null
: pair(head(items) * factor, scale_list(tail(items), factor))
display(boxify(scale_list(list3, 10)));
// p. 91
const map = (fun, items) => is_null(items)
? null
: pair(fun(head(items)), map(fun, tail(items)))
const abs = n => Math.abs(n);
display(abs(-17));
const list4 = list([-10, 2.5, -1.6, 17]);
display(boxify(list4));
display(boxify(map(abs, list4)));
display(boxify(map(x => x * x, list([1,2,3,4]))));
const scale_list2 = (items, factor) => map(x => x * factor, items)
display(boxify(scale_list2(list3, 9)));
// 2.2.2 Hierarchical Structures p.93
const tlist1 = pair(listArgs(1,2), listArgs(3,4));
display(boxify(tlist1));
// assume that an object is a pair if the head function can act on it NO
const is_pair = x => (typeof x === "function") && head(x) ? true : false
const count_leaves = x => is_null(x)
? 0
: ! is_pair(x)
? 1
: count_leaves(head(x)) + count_leaves(tail(x))
display(count_leaves(list3)); // 14
display(count_leaves(list4)); // 4
// Exercise 2.24
const tlist2 = listArgs(1, listArgs(2, listArgs(3,4)));
display(boxify(tlist2)); // [1, [[2, [[3, [4, null]], null]], null]]
// Exercise 2.25
const tlist3 = listArgs(1, 3, listArgs(5, 7), 9);
display(boxify(tlist3)); // [1, [3, [[5, [7, null]], [9, null]]]]
// Exercise 2.26
const tlist4 = listArgs(1, 2, 3);
const tlist5 = listArgs(4, 5, 6);
display(boxify(append(tlist4, tlist5))); // [1, [2, [3, [4, [5, [6, null]]]]]]
display(boxify(pair(tlist4, tlist5))); // [[1, [2, [3, null]]], [4, [5, [6, null]]]]
display(boxify(listArgs(tlist4, tlist5))); // [[1, [2, [3, null]]], [[4, [5, [6, null]]], null]]
// Exercise 2.27 deep reverse
// Exercise 2.28 fringe
// Exercise 2.29 a binary mobile with two branches
// Mapping over trees p.96
// test using a JS Object, in addtion to JS number and string and true|false this works!
const objlist1 = pair(listArgs(1,{thing: 222}), listArgs(3,{thing1: 333, thing2: "three33", thing3: [3,33,333]}));
display(boxify(objlist1)); // [[1, [{"thing":222}, null]], [3, [{"thing1":333,"thing2":"three33","thing3":[3,33,333]}, null]]]
const xhlist1 = pair(listArgs({id: 1, xhc: "One", role: "un", color: "red"},{id:2}), listArgs({id:3},{id:4}));
display(boxify(xhlist1));
// ---------------------------------------
// reverse list
// created by ollama run gemma3:12b
/* REVERSE early versions, now commented out
// this works!
const reverse = (lst) => {
if (is_null(lst)) {
return null;
}
const reverseHelper = (lst, acc) => {
if (is_null(lst)) {
return acc;
}
return reverseHelper(tail(lst), pair(head(lst), acc));
};
return reverseHelper(lst, null);
};
// this works!
const reverseHelper2 = (lst, acc) => is_null(lst)
? acc
: reverseHelper2(tail(lst), pair(head(lst), acc))
const reverse2 = lst => is_null(lst)
? null
: reverseHelper2(lst, null)
// this works!
const reverse3 = (lst) => {
if (is_null(lst)) {
return null;
}
const reverseHelper = (lst, acc) => is_null(lst)
? acc
: reverseHelper(tail(lst), pair(head(lst), acc))
return reverseHelper(lst, null);
};
*/
// this works!
const reverse = (lst, acc = null) => is_null(lst)
? acc
: reverse(tail(lst), pair(head(lst), acc))
// Example usage:
const myList = list([1, 2, 3, 4, 5].reverse());
display(boxify(myList));
//const reversedList = reverse(myList);
//display(boxify(reversedList)); // Output: [5, [4, [3, [2, [1, null]]]]]
const reversedList4 = reverse(myList);
display(boxify(reversedList4)); // Output: [5, [4, [3, [2, [1, null]]]]]
// another test
const myList2 = list(["a", "b", "c"].reverse());
//const reversedList2 = reverse(myList2);
//display(boxify(reversedList2)); // Output: ["c", ["b", ["a", null]]]
const reversedList4b = reverse(myList2);
display(boxify(reversedList4b)); // Output: ["c", ["b", ["a", null]]]
//test with empty list
const emptyList = null;
//const reversedEmptyList = reverse(emptyList);
//display(boxify(reversedEmptyList)); // Output: null
const reversedEmptyList4 = reverse(emptyList);
display(boxify(reversedEmptyList4)); // Output: null
// test using listArgs()
const rlist1 = listArgs(4,5,6,7);
display(boxify(rlist1));
//display(boxify(reverse(rlist1))); // OK
//display(boxify(reverse2(rlist1))); // OK
//display(boxify(reverse3(rlist1))); // OK
display(boxify(reverse(rlist1))); // OK
const rlist2 = listArgs(4, "five", {six: 66}, 7);
display(boxify(rlist2));
//display(boxify(reverse(rlist2))); // OK
//display(boxify(reverse2(rlist2))); // OK
//display(boxify(reverse3(rlist2))); // OK
display(boxify(reverse(rlist2))); // OK
const rlist3 = listArgs(4,5,listArgs(6,66,666),7);
display(boxify(rlist3));
//display(boxify(reverse(rlist3))); // OK
//display(boxify(reverse2(rlist3))); // OK
//display(boxify(reverse3(rlist3))); // OK
display(boxify(reverse(rlist3))); // OK
// end reverse list
// ---------------------------------------
// Xholon
const first = node => head(node)
const next = node => head(tail(node))
const xh01 = listArgs(2,3,4,5);
display(boxify(xh01));
display(boxify(first(xh01))); // 2
display(boxify(next(xh01))); // 3
const xh02 = listArgs(xh01, 6, 7);
display(boxify(xh02));
display(boxify(first(xh02))); //
display(boxify(next(xh02))); //
const xh03 = pair(
pair(pair(1,2), pair(3,4)),
pair(pair(5,6), pair(7,8))
)
display(boxify(xh03));
const xh04 = pair(
pair(
pair(
pair(
pair(1,2),
pair(3,4)
),
pair(
pair(21,22),
pair(23,24)
)
),
pair(
pair(
pair(5,6),
pair(7,8)
),
pair(
pair(25,26),
pair(27,28)
)
)
),
pair(
pair(
pair(
pair(9,10),
pair(11,12)
),
pair(
pair(31,32),
pair(33,34)
)
),
pair(
pair(
pair(13,14),
pair(15,16)
),
pair(
pair(35,36),
pair(37,38)
)
)
)
)
display(boxify(xh04));
// 2026 Jan 14
// last butlast
const last = lst => head(reverse(lst));
const butlast = lst => reverse(tail(reverse(lst)));
const list101 = listArgs(1,9,2,8,3,7,4,6,5);
display(boxify(list101));
display(last(list101));
display(boxify(butlast(list101)));
// null list
const list102 = listArgs();
const emptyq = lst => lst === null ? true : false;
display(boxify(list102));
display(emptyq(list101));
display(emptyq(list102));
})("SICPjs_list")
//# sourceURL=SICPjs_list.js
]]></Lambda>
<Lambda roleName="FamousPairs"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
const pair = (x, y) => m => m(x, y); // this works!
const pairGM = x => y => m => m(x, y); // this works!
const head = z => z((p, q) => p);
const tail = z => z((p, q) => q);
const display = x => console.log(x);
const fpair = (a, b) => {
const pr = pair(a,b);
return `${head(pr)} ${tail(pr)}`;
}
display(fpair(true, false));
display(fpair("car", "cdr"));
display(fpair("left", "right"));
display(fpair("first", "next"));
display(fpair("firstChild", "nextSibling"));
display(fpair(1, 0));
display(fpair("first", "second"));
//display(fpair("", ""));
display(fpair("", ""));
})("FamousPairs")
//# sourceURL=FamousPairs.js
]]></Lambda>
<Lambda roleName="Lisp_01"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
const pair = (x, y) => m => m(x, y)
const pairGM = x => y => m => m(x, y)
const head = z => z((p, q) => p)
const tail = z => z((p, q) => q)
const display = x => console.log(x)
const boxify = pr => typeof pr === "function" ? "[" + boxify(head(pr)) + ", " + boxify(tail(pr)) + "]" : JSON.stringify(pr)
const list = arr => arr.length > 0 ? pair(arr.pop(), list(arr)) : null
const listArgs = (...args) => list(args.reverse())
const append = (list1, list2) => is_null(list1) ? list2 : pair(head(list1), append(tail(list1), list2))
const is_null = thing => thing === null
const length = (items, count = 0) => is_null(items) ? count : length(tail(items), count + 1)
const reverse = (lst, acc = null) => is_null(lst) ? acc : reverse(tail(lst), pair(head(lst), acc))
// Lisp function names
const CONS = pair;
const CAR = head;
const CDR = tail;
const LIST = listArgs;
const APPEND = append;
const LENGTH = length;
const REVERSE = reverse;
// OK
const pr01 = CONS(1, 2);
const hd01 = CAR(pr01);
const tl01 = CDR(pr01);
display(boxify(pr01));
display(hd01);
display(tl01);
const pr02 = CONS(CONS(1,2), CONS(3,4))
display(boxify(pr02));
const ls01 = LIST(11,22,33,44,55);
display(boxify(ls01));
display(boxify(APPEND(ls01, ls01)));
display(LENGTH(APPEND(ls01, ls01)));
display(boxify(REVERSE(ls01)));
})("Lisp_01")
//# sourceURL=Lisp_01.js
]]></Lambda>
<Lambda roleName="Logo"><![CDATA[
var beh = {};
// see ref[11]
/* Logo primitives - Words and Lists
=
BUTFIRST BF
BUTLAST BL
COUNT
EMPTY?
FIRST
FPUT
ITEM
LAST
LIST
LIST?
LPUT
MEMBER?
SENTENCE SE
WORD
WORD?
(see A-145 in book)
*/
((title) => {
console.log(title);
this.println(title);
console.log("Logo");
//const list = arr => arr.length > 0 ? pair(arr.pop(), list(arr)) : null
const xhlambda = $wnd.xh.xhlambda;
console.log(xhlambda);
const BUTFIRST = xhlambda.tail;
const BUTLAST = xhlambda.butlast;
const COUNT = xhlambda.length;
const EMPTYq = xhlambda.emptyq;
const FIRST = xhlambda.head;
const FPUT = "TODO";
const ITEM = "TODO";
const LAST = xhlambda.last;
const LIST = xhlambda.listArgs;
// ...
const display = xhlambda.display; // DOES NOT WORK
const boxify = xhlambda.boxify;
const list1 = LIST(1,2,3,4,5);
console.log(list1);
console.log(boxify(list1));
console.log(COUNT(list1));
console.log(COUNT(LIST(1,2,3,4,5)));
console.log(LAST(list1));
console.log(boxify(BUTLAST(list1)));
console.log(EMPTYq(list1));
console.log(EMPTYq(LIST()));
})("Logo")
//# sourceURL=Logo.js
]]></Lambda>
<Lambda roleName="YCombinator"><![CDATA[
var beh = {};
// see ref[10]
((title) => {
console.log(title);
this.println(title);
/*
Y = λf.(λx.f(x x))(λx.f(x x))
rec = λf. (λx. f (x x)) (λx. f (x x))
The standard version of the Y combinator does not use lexically bound local variables (or any local variables at all),
which necessitates adding a wrapper function and some code duplication
- the remaining locale variables are only there to make the relationship to the previous implementation more explicit:
*/
function Y(f) {
var g = f((function(h) {
return function() {
var g = f(h(h));
return g.apply(this, arguments);
}
})(function(h) {
return function() {
var g = f(h(h));
return g.apply(this, arguments);
}
}));
return g;
}
var fac = Y(function(f) {
return function (n) {
return n > 1 ? n * f(n - 1) : 1;
};
});
var fib = Y(function(f) {
return function(n) {
return n > 1 ? f(n - 1) + f(n - 2) : n;
};
});
console.log(fac(0), fac(1), fac(2), fac(3), fac(4)); // OK 1 1 2 6 24
console.log(fib(0), fib(1), fib(2), fib(3), fib(4), fib(5), fib(6), fib(7), fib(8), fib(9), fib(10)); // OK 0 1 1 2 3 5 8 13 21 34 55
// using arrow functions
const YY = f=>((g=>(f((...x)=>g(g)(...x))))
(g=>(f((...x)=>g(g)(...x)))))
var fac2 = YY(f => n => n > 1 ? n * f(n-1) : 1);
console.log(fac2(0), fac2(1), fac2(2), fac2(3), fac2(4));
// A minimalist version:
var YYY = f => (x => x(x))(y => f(x => y(y)(x)));
var facc = YYY(f => n => n > 1 ? n * f(n-1) : 1);
console.log(facc(0), facc(1), facc(2), facc(3), facc(4));
var fibb = YYY(f => n => n > 1 ? f(n - 1) + f(n - 2) : n);
console.log(fibb(0), fibb(1), fibb(2), fibb(3), fibb(4), fibb(5), fibb(6), fibb(7), fibb(8), fibb(9), fibb(10)); //
})("Y Combinator")
//# sourceURL=YCombinator.js
]]></Lambda>
// this works, but Cytoplasm should go before all the enzymes
<Lambda roleName="CellModel"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
console.log("CellModel");
const xhlambda = $wnd.xh.xhlambda;
// Newick format uses commas
const Test01 = `one,
two,
three,
four`.split(/,\r?\n|\r|\n/g); //.map(item => item.trim()).reverse()
console.log(Test01);
// const re = /\s*(?:;|$)\s*/;
// const nameList = names.split(re);
// str.split(/\r?\n/);
// from Newick export of Xholon Cell Model
const Cytosol = xhlambda.list( `Glucose,
Glucose_6_Phosphate,
Fructose_6_Phosphate,
Fructose_1x6_Biphosphate,
DihydroxyacetonePhosphate,
Glyceraldehyde_3_Phosphate,
X1x3_BisphosphoGlycerate,
X3_PhosphoGlycerate,
X2_PhosphoGlycerate,
PhosphoEnolPyruvate,
Pyruvate`.split(/,\r?\n|\r|\n/g).reverse());
console.log("Cytosol:");
console.log(xhlambda.boxify(Cytosol));
// SExpression format
const Cytoplasm = xhlambda.listArgs("Cytoplasm", xhlambda.list(`Hexokinase
PhosphoGlucoIsomerase
PhosphoFructokinase
Aldolase
TriosePhosphateIsomerase
Glyceraldehyde_3_phosphateDehydrogenase
PhosphoGlycerokinase
PhosphoGlyceromutase
Enolase
PyruvateKinase`.split(/\r?\n|\r|\n/g).reverse()), "Cytosol", Cytosol);
console.log("Cytoplasm:");
console.log(xhlambda.boxify(Cytoplasm));
/* result: with my manual spacing added
["Cytoplasm",
[
["Hexokinase",
["PhosphoGlucoIsomerase",
["PhosphoFructokinase",
["Aldolase",
["TriosePhosphateIsomerase",
["Glyceraldehyde_3_phosphateDehydrogenase",
["PhosphoGlycerokinase",
["PhosphoGlyceromutase",
["Enolase",
["PyruvateKinase", null
]]]]]]]]]],
["Cytosol",
[
["Glucose",
["Glucose_6_Phosphate",
["Fructose_6_Phosphate",
["Fructose_1x6_Biphosphate",
["DihydroxyacetonePhosphate",
["Glyceraldehyde_3_Phosphate",
["X1x3_BisphosphoGlycerate",
["X3_PhosphoGlycerate",
["X2_PhosphoGlycerate",
["PhosphoEnolPyruvate",
["Pyruvate", null
]]]]]]]]]]],
null
]
]
]
]
*/
})("CellModel")
//# sourceURL=CellModel.js
]]></Lambda>
<Lambda roleName="CellModel2"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
console.log("CellModel");
const xhlambda = $wnd.xh.xhlambda;
// Newick format uses commas
const Test01 = `one,
two,
three,
four`.split(/,\r?\n|\r|\n/g); //.map(item => item.trim()).reverse()
console.log(Test01);
// const re = /\s*(?:;|$)\s*/;
// const nameList = names.split(re);
// str.split(/\r?\n/);
// from Newick export of Xholon Cell Model
const Cytosol = xhlambda.list( `Glucose,
Glucose_6_Phosphate,
Fructose_6_Phosphate,
Fructose_1x6_Biphosphate,
DihydroxyacetonePhosphate,
Glyceraldehyde_3_Phosphate,
X1x3_BisphosphoGlycerate,
X3_PhosphoGlycerate,
X2_PhosphoGlycerate,
PhosphoEnolPyruvate,
Pyruvate`.split(/,\r?\n|\r|\n/g).reverse());
console.log("Cytosol:");
console.log(xhlambda.boxify(Cytosol));
// SExpression format
const Cytoplasm = xhlambda.listArgs("Cytoplasm", "Cytosol", Cytosol, xhlambda.list(`Hexokinase
PhosphoGlucoIsomerase
PhosphoFructokinase
Aldolase
TriosePhosphateIsomerase
Glyceraldehyde_3_phosphateDehydrogenase
PhosphoGlycerokinase
PhosphoGlyceromutase
Enolase
PyruvateKinase`.split(/\r?\n|\r|\n/g).reverse()));
console.log("Cytoplasm:");
console.log(xhlambda.boxify(Cytoplasm));
/* result: with my manual spacing added
["Cytoplasm",
[
["Hexokinase",
["PhosphoGlucoIsomerase",
["PhosphoFructokinase",
["Aldolase",
["TriosePhosphateIsomerase",
["Glyceraldehyde_3_phosphateDehydrogenase",
["PhosphoGlycerokinase",
["PhosphoGlyceromutase",
["Enolase",
["PyruvateKinase", null
]]]]]]]]]],
["Cytosol",
[
["Glucose",
["Glucose_6_Phosphate",
["Fructose_6_Phosphate",
["Fructose_1x6_Biphosphate",
["DihydroxyacetonePhosphate",
["Glyceraldehyde_3_Phosphate",
["X1x3_BisphosphoGlycerate",
["X3_PhosphoGlycerate",
["X2_PhosphoGlycerate",
["PhosphoEnolPyruvate",
["Pyruvate", null
]]]]]]]]]]],
null
]
]
]
]
*/
const pair = xhlambda.pair;
console.log("CytosolP using pair()");
const CytosolP = pair("Glucose", pair("Glucose_6_Phosphate", pair("Fructose_6_Phosphate", pair("Fructose_1x6_Biphosphate", pair("DihydroxyacetonePhosphate", pair("Glyceraldehyde_3_Phosphate", pair("X1x3_BisphosphoGlycerate", pair("X3_PhosphoGlycerate", pair("X2_PhosphoGlycerate", pair("PhosphoEnolPyruvate", pair("Pyruvate", null)))))))))));
console.log(xhlambda.boxify(CytosolP));
/* result
["Glucose", ["Glucose_6_Phosphate", ["Fructose_6_Phosphate", ["Fructose_1x6_Biphosphate", ["DihydroxyacetonePhosphate", ["Glyceraldehyde_3_Phosphate", ["X1x3_BisphosphoGlycerate", ["X3_PhosphoGlycerate", ["X2_PhosphoGlycerate", ["PhosphoEnolPyruvate", ["Pyruvate", null]]]]]]]]]]]
*/
const EnzymesP = pair("Hexokinase", pair("PhosphoGlucoIsomerase", pair("PhosphoFructokinase", pair("Aldolase", pair("TriosePhosphateIsomerase", pair("Glyceraldehyde_3_phosphateDehydrogenase", pair("PhosphoGlycerokinase", pair("PhosphoGlyceromutase", pair("Enolase", pair("PyruvateKinase", null))))))))));
console.log(xhlambda.boxify(EnzymesP));
/* result
["Hexokinase", ["PhosphoGlucoIsomerase", ["PhosphoFructokinase", ["Aldolase", ["TriosePhosphateIsomerase", ["Glyceraldehyde_3_phosphateDehydrogenase", ["PhosphoGlycerokinase", ["PhosphoGlyceromutase", ["Enolase", ["PyruvateKinase", null]]]]]]]]]]
*/
//const CytoplasmP = pair("CytoplasmP", pair( pair(EnzymesP, pair("Cytosol", CytosolP)), null));
//console.log(xhlambda.boxify(CytoplasmP));
/* result
["CytoplasmP", [[["Hexokinase", ["PhosphoGlucoIsomerase", ["PhosphoFructokinase", ["Aldolase", ["TriosePhosphateIsomerase", ["Glyceraldehyde_3_phosphateDehydrogenase", ["PhosphoGlycerokinase", ["PhosphoGlyceromutase", ["Enolase", ["PyruvateKinase", null]]]]]]]]]], ["Cytosol", ["Glucose", ["Glucose_6_Phosphate", ["Fructose_6_Phosphate", ["Fructose_1x6_Biphosphate", ["DihydroxyacetonePhosphate", ["Glyceraldehyde_3_Phosphate", ["X1x3_BisphosphoGlycerate", ["X3_PhosphoGlycerate", ["X2_PhosphoGlycerate", ["PhosphoEnolPyruvate", ["Pyruvate", null]]]]]]]]]]]]], null]]
*/
const CytoplasmP = pair("CytoplasmP", pair( pair("Cytosol", pair(CytosolP, null)), EnzymesP ));
console.log(xhlambda.boxify(CytoplasmP));
/* result NO
["CytoplasmP", [["Cytosol", ["Glucose", ["Glucose_6_Phosphate", ["Fructose_6_Phosphate", ["Fructose_1x6_Biphosphate", ["DihydroxyacetonePhosphate", ["Glyceraldehyde_3_Phosphate", ["X1x3_BisphosphoGlycerate", ["X3_PhosphoGlycerate", ["X2_PhosphoGlycerate", ["PhosphoEnolPyruvate", ["Pyruvate", null]]]]]]]]]]]], ["Hexokinase", ["PhosphoGlucoIsomerase", ["PhosphoFructokinase", ["Aldolase", ["TriosePhosphateIsomerase", ["Glyceraldehyde_3_phosphateDehydrogenase", ["PhosphoGlycerokinase", ["PhosphoGlyceromutase", ["Enolase", ["PyruvateKinase", null]]]]]]]]]]]]
*/
console.log("fromXh01");
//const fromXh01 =
/*pair("Cytoplasm", pair(*/
pair("Cytosol", pair(
pair("Glucose",
pair("Glucose_6_Phosphate",
pair("Fructose_6_Phosphate",
pair("Fructose_1x6_Biphosphate",
pair("DihydroxyacetonePhosphate",
pair("Glyceraldehyde_3_Phosphate",
pair("X1x3_BisphosphoGlycerate",
pair("X3_PhosphoGlycerate",
pair("X2_PhosphoGlycerate",
pair("PhosphoEnolPyruvate",
pair("Pyruvate", null)
)
)
)
)
)
)
)
)
)
)
), null) // I manually added |, null)| here
/*
pair("Hexokinase",
pair("PhosphoGlucoIsomerase",
pair("PhosphoFructokinase",
pair("Aldolase",
pair("TriosePhosphateIsomerase",
pair("Glyceraldehyde_3_phosphateDehydrogenase",
pair("PhosphoGlycerokinase",
pair("PhosphoGlyceromutase",
pair("Enolase",
pair("PyruvateKinase", null)
)
)
)
)
)
)
)
)
)
)
)
)*/
//console.log(xhlambda.boxify(fromXh01));
console.log("fromXh02");
const fromXh02 = pair("one", pair(2, 3));
console.log(xhlambda.boxify(fromXh02)); // ["one", [2, 3]]
console.log("fromXh03");
const fromXh03 = pair("HelloWorldSystem", pair(
pair("Hello",
pair("World", null)
)
)
)
console.log(xhlambda.boxify(fromXh03)); // ["HelloWorldSystem", [["Hello", ["World", null]], undefined]]
console.log("fromXh04");
const fromXh04 = pair("HelloWorldSystem", pair(pair("Hello", "World"), null));
console.log(xhlambda.boxify(fromXh04));
// ["HelloWorldSystem", [["Hello", "World"], undefined]] NO
// ["HelloWorldSystem", [["Hello", "World"], null]]
// Uncaught SyntaxError: missing ) after argument list ???
// fixed by adding a comma after the long string of end parenthese
const ctrnn = pair("Robot", pair(
pair("SensorR",
pair("SensorL",
pair("Ctrnn", pair(
pair("Neuron0",
pair("Neuron1",
pair("Neuron2",
pair("Neuron3",
pair("Neuron4",
pair("Connection_0_2",
pair("Connection_1_2",
pair("Connection_2_2",
pair("Connection_1_3",
pair("Connection_2_3",
pair("Connection_3_3",
pair("Connection_0_4",
pair("Connection_2_4",
pair("Connection_4_4", null))))))))))))))),
pair("MotorR",
pair("MotorL", null))))))
);
console.log(xhlambda.boxify(ctrnn));
// ["Robot", [["SensorR", ["SensorL", ["Ctrnn", [["Neuron0", ["Neuron1", ["Neuron2", ["Neuron3", ["Neuron4", ["Connection_0_2", ["Connection_1_2", ["Connection_2_2", ["Connection_1_3", ["Connection_2_3", ["Connection_3_3", ["Connection_0_4", ["Connection_2_4", ["Connection_4_4", null]]]]]]]]]]]]]], undefined]]]], undefined]]
// all of these are OK
//const ctrnn2 = pair("Robot"); // ["Robot", undefined]
//const ctrnn2 = pair("Robot", null); // ["Robot", null]
const ctrnn2 = pair("Robot", pair("MotorL", null)); // ["Robot", ["MotorL", null]]
console.log(xhlambda.boxify(ctrnn2));
// Uncaught SyntaxError: missing ) after argument list ???
const ctrnn3 = pair("Robot", pair(pair("SensorR", pair("SensorL",pair("Ctrnn", pair(pair("Neuron0",pair("Connection_4_4", null))), pair("MotorR", pair("MotorL", null)))))));
console.log(xhlambda.boxify(ctrnn3)); // ["Robot", [["SensorR", ["SensorL", ["Ctrnn", [["Neuron0", ["Connection_4_4", null]], undefined]]]], undefined]]
console.log("after appending comma after endBracks");
const new01 = pair("HelloWorldSystem", pair(
pair("Hello",
pair("World", null))),
)
console.log(xhlambda.boxify(new01));
const new02 = pair("Robot", pair(
pair("SensorR",
pair("SensorL",
pair("Ctrnn", pair(
pair("Neuron0",
pair("Neuron1",
pair("Neuron2",
pair("Neuron3",
pair("Neuron4",
pair("Connection_0_2",
pair("Connection_1_2",
pair("Connection_2_2",
pair("Connection_1_3",
pair("Connection_2_3",
pair("Connection_3_3",
pair("Connection_0_4",
pair("Connection_2_4",
pair("Connection_4_4", null))))))))))))))),
pair("MotorR",
pair("MotorL", null)))))),
)
console.log(xhlambda.boxify(new02));
// ["Robot", [["SensorR", ["SensorL", ["Ctrnn", [["Neuron0", ["Neuron1", ["Neuron2", ["Neuron3", ["Neuron4", ["Connection_0_2", ["Connection_1_2", ["Connection_2_2", ["Connection_1_3", ["Connection_2_3", ["Connection_3_3", ["Connection_0_4", ["Connection_2_4", ["Connection_4_4", null]]]]]]]]]]]]]], undefined]]]], undefined]]
const new03 =
pair("ExtraCellularSpace", pair(
pair("ExtraCellularSolution", pair(pair("Glucose", null), null),
pair("EukaryoticCell", pair(
pair("CellMembrane", pair(
pair("CellBilayer", null)),
pair("Cytoplasm", pair(
pair("Cytosol", pair(
pair("Glucose",
pair("Glucose_6_Phosphate",
pair("Fructose_6_Phosphate",
pair("Fructose_1x6_Biphosphate",
pair("DihydroxyacetonePhosphate",
pair("Glyceraldehyde_3_Phosphate",
pair("X1x3_BisphosphoGlycerate",
pair("X3_PhosphoGlycerate",
pair("X2_PhosphoGlycerate",
pair("PhosphoEnolPyruvate",
pair("Pyruvate", null)))))))))))),
pair("Hexokinase",
pair("PhosphoGlucoIsomerase",
pair("PhosphoFructokinase",
pair("Aldolase",
pair("TriosePhosphateIsomerase",
pair("Glyceraldehyde_3_phosphateDehydrogenase",
pair("PhosphoGlycerokinase",
pair("PhosphoGlyceromutase",
pair("Enolase",
pair("PyruvateKinase", null)))))))))))),
null))),
null))),
)
console.log(xhlambda.boxify(new03));
// ["ExtraCellularSpace", [["ExtraCellularSolution", [["Glucose", null], undefined]], undefined]]
// THIS FAILS
const new04 = pair("Cytoplasm", pair(
pair("Cytosol", pair(
pair("Glucose",
pair("Glucose_6_Phosphate",
pair("Fructose_6_Phosphate",
pair("Fructose_1x6_Biphosphate",
pair("DihydroxyacetonePhosphate",
pair("Glyceraldehyde_3_Phosphate",
pair("X1x3_BisphosphoGlycerate",
pair("X3_PhosphoGlycerate",
pair("X2_PhosphoGlycerate",
pair("PhosphoEnolPyruvate",
pair("Pyruvate", null)))))))))))),
pair("Hexokinase",
pair("PhosphoGlucoIsomerase",
pair("PhosphoFructokinase",
pair("Aldolase",
pair("TriosePhosphateIsomerase",
pair("Glyceraldehyde_3_phosphateDehydrogenase",
pair("PhosphoGlycerokinase",
pair("PhosphoGlyceromutase",
pair("Enolase",
pair("PyruvateKinase", null)))))))))))),
)
console.log(xhlambda.boxify(new04));
// ["Cytoplasm", [["Cytosol", [["Glucose", ["Glucose_6_Phosphate", ["Fructose_6_Phosphate", ["Fructose_1x6_Biphosphate", ["DihydroxyacetonePhosphate", ["Glyceraldehyde_3_Phosphate", ["X1x3_BisphosphoGlycerate", ["X3_PhosphoGlycerate", ["X2_PhosphoGlycerate", ["PhosphoEnolPyruvate", ["Pyruvate", null]]]]]]]]]]], undefined]], undefined]]
})("CellModel2")
//# sourceURL=CellModel2.js
]]></Lambda>
<Lambda roleName="LAST"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
console.log("LAST");
})("LAST")
//# sourceURL=LAST.js
]]></Lambda>
<Lambda roleName="CellModel3_Jan19"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
const xhlambda = $wnd.xh.xhlambda;
const pair = xhlambda.pair;
const boxify = xhlambda.boxify;
const list = xhlambda.list;
const listArgs = xhlambda.listArgs;
// each line that consists of 'pair(' needs a matching line that consists of "),"
const pairs01 =
pair("Cytoplasm",
pair(
pair("Cytosol",
pair(
pair("Glucose",
pair("Glucose_6_Phosphate",
pair("Fructose_6_Phosphate",
pair("Fructose_1x6_Biphosphate",
pair("DihydroxyacetonePhosphate",
pair("Glyceraldehyde_3_Phosphate",
pair("X1x3_BisphosphoGlycerate",
pair("X3_PhosphoGlycerate",
pair("X2_PhosphoGlycerate",
pair("PhosphoEnolPyruvate",
pair("Pyruvate", null
)
)
)
)
)
)
)
)
)
)
)
),
pair("Hexokinase",
pair("PhosphoGlucoIsomerase",
pair("PhosphoFructokinase",
pair("Aldolase",
pair("TriosePhosphateIsomerase",
pair("Glyceraldehyde_3_phosphateDehydrogenase",
pair("PhosphoGlycerokinase",
pair("PhosphoGlyceromutase",
pair("Enolase",
pair("PyruvateKinase", null
)
)
)
)
)
)
)
)
)
)
)
),
);
console.log(pairs01);
console.log(boxify(pairs01));
/* the result is incorrect; it lacks the siblings starting with "Hexokinase"
/*
["Cytoplasm", [["Cytosol", [["Glucose", ["Glucose_6_Phosphate", ["Fructose_6_Phosphate", ["Fructose_1x6_Biphosphate", ["DihydroxyacetonePhosphate", ["Glyceraldehyde_3_Phosphate", ["X1x3_BisphosphoGlycerate", ["X3_PhosphoGlycerate", ["X2_PhosphoGlycerate", ["PhosphoEnolPyruvate", ["Pyruvate", null]]]]]]]]]]], undefined]], undefined]]
*/
const arr01 = [
"Cytoplasm",
"Cytosol",
"Glucose",
"Glucose_6_Phosphate",
"Fructose_6_Phosphate",
"Fructose_1x6_Biphosphate",
"DihydroxyacetonePhosphate",
"Glyceraldehyde_3_Phosphate",
"X1x3_BisphosphoGlycerate",
"X3_PhosphoGlycerate",
"X2_PhosphoGlycerate",
"PhosphoEnolPyruvate",
"Pyruvate",
"Hexokinase",
"PhosphoGlucoIsomerase",
"PhosphoFructokinase",
"Aldolase",
"TriosePhosphateIsomerase",
"Glyceraldehyde_3_phosphateDehydrogenase",
"PhosphoGlycerokinase",
"PhosphoGlyceromutase",
"Enolase",
"PyruvateKinase"
];
const list01 = list(arr01.reverse());
console.log(list01); // a pair function
console.log(boxify(list01)); // OK
const arr02 = [
"Cytoplasm",
[
"Cytosol",
[
"Glucose",
"Glucose_6_Phosphate",
"Fructose_6_Phosphate",
"Fructose_1x6_Biphosphate",
"DihydroxyacetonePhosphate",
"Glyceraldehyde_3_Phosphate",
"X1x3_BisphosphoGlycerate",
"X3_PhosphoGlycerate",
"X2_PhosphoGlycerate",
"PhosphoEnolPyruvate",
"Pyruvate",
],
"Hexokinase",
"PhosphoGlucoIsomerase",
"PhosphoFructokinase",
"Aldolase",
"TriosePhosphateIsomerase",
"Glyceraldehyde_3_phosphateDehydrogenase",
"PhosphoGlycerokinase",
"PhosphoGlyceromutase",
"Enolase",
"PyruvateKinase"
]
];
const list02 = list(arr02.reverse());
console.log(list02); // a pair function
console.log(boxify(list02)); // OK
/*
["Cytoplasm", [["Cytosol",["Glucose","Glucose_6_Phosphate","Fructose_6_Phosphate","Fructose_1x6_Biphosphate","DihydroxyacetonePhosphate","Glyceraldehyde_3_Phosphate","X1x3_BisphosphoGlycerate","X3_PhosphoGlycerate","X2_PhosphoGlycerate","PhosphoEnolPyruvate","Pyruvate"],"Hexokinase","PhosphoGlucoIsomerase","PhosphoFructokinase","Aldolase","TriosePhosphateIsomerase","Glyceraldehyde_3_phosphateDehydrogenase","PhosphoGlycerokinase","PhosphoGlyceromutase","Enolase","PyruvateKinase"], null]]
*/
// manually reformatted:
/*
["Cytoplasm",
[
["Cytosol",
[
"Glucose",
"Glucose_6_Phosphate",
"Fructose_6_Phosphate",
"Fructose_1x6_Biphosphate",
"DihydroxyacetonePhosphate",
"Glyceraldehyde_3_Phosphate",
"X1x3_BisphosphoGlycerate",
"X3_PhosphoGlycerate",
"X2_PhosphoGlycerate",
"PhosphoEnolPyruvate",
"Pyruvate"
],
"Hexokinase",
"PhosphoGlucoIsomerase",
"PhosphoFructokinase",
"Aldolase",
"TriosePhosphateIsomerase",
"Glyceraldehyde_3_phosphateDehydrogenase",
"PhosphoGlycerokinase",
"PhosphoGlyceromutase",
"Enolase",
"PyruvateKinase"
],
null
]
]
*/
// this is valid JSON
// https://jsonlint.com/
// this is a manually created array of arrays
const arr03 =
[
"ExtraCellularSpace",
[
"ExtraCellularSolution",
[
"Glucose",
null
]
],
[
"EukaryoticCell",
[
"CellMembrane",
[
"CellBilayer",
null
]
],
[
"Cytoplasm",
[
"Cytosol",
[
"Glucose",
"Glucose_6_Phosphate",
"Fructose_6_Phosphate",
"Fructose_1x6_Biphosphate",
"DihydroxyacetonePhosphate",
"Glyceraldehyde_3_Phosphate",
"X1x3_BisphosphoGlycerate",
"X3_PhosphoGlycerate",
"X2_PhosphoGlycerate",
"PhosphoEnolPyruvate",
"Pyruvate",
],
"Hexokinase",
"PhosphoGlucoIsomerase",
"PhosphoFructokinase",
"Aldolase",
"TriosePhosphateIsomerase",
"Glyceraldehyde_3_phosphateDehydrogenase",
"PhosphoGlycerokinase",
"PhosphoGlyceromutase",
"Enolase",
"PyruvateKinase"
]
]
]
];
const list03 = list(arr03.reverse());
console.log(list03); // a pair function
console.log(boxify(list03)); // OK
/* boxified NO each list must be embedded ex: list(list())
["ExtraCellularSpace", [["ExtraCellularSolution",["Glucose",null]], [["EukaryoticCell",["CellMembrane",["CellBilayer",null]],["Cytoplasm",["Cytosol",["Glucose","Glucose_6_Phosphate","Fructose_6_Phosphate","Fructose_1x6_Biphosphate","DihydroxyacetonePhosphate","Glyceraldehyde_3_Phosphate","X1x3_BisphosphoGlycerate","X3_PhosphoGlycerate","X2_PhosphoGlycerate","PhosphoEnolPyruvate","Pyruvate"],"Hexokinase","PhosphoGlucoIsomerase","PhosphoFructokinase","Aldolase","TriosePhosphateIsomerase","Glyceraldehyde_3_phosphateDehydrogenase","PhosphoGlycerokinase","PhosphoGlyceromutase","Enolase","PyruvateKinase"]]], null]]]
*/
// valid JSON
// list3 boxified, validated and prettified online: THIS SHOULD BE CORRECT BOX NOTATION
/*
[
"ExtraCellularSpace",
[
[
"ExtraCellularSolution",
[
"Glucose",
null
]
],
[
[
"EukaryoticCell",
[
"CellMembrane",
[
"CellBilayer",
null
]
],
[
"Cytoplasm",
[
"Cytosol",
[
"Glucose",
"Glucose_6_Phosphate",
"Fructose_6_Phosphate",
"Fructose_1x6_Biphosphate",
"DihydroxyacetonePhosphate",
"Glyceraldehyde_3_Phosphate",
"X1x3_BisphosphoGlycerate",
"X3_PhosphoGlycerate",
"X2_PhosphoGlycerate",
"PhosphoEnolPyruvate",
"Pyruvate"
],
"Hexokinase",
"PhosphoGlucoIsomerase",
"PhosphoFructokinase",
"Aldolase",
"TriosePhosphateIsomerase",
"Glyceraldehyde_3_phosphateDehydrogenase",
"PhosphoGlycerokinase",
"PhosphoGlyceromutase",
"Enolase",
"PyruvateKinase"
]
]
],
null
]
]
]
*/
// TODO try list or listArgs
const lyst01 = listArgs("one", "two", "three", "four");
console.log(lyst01);
console.log(boxify(lyst01)); // OK ["one", ["two", ["three", ["four", null]]]]
const lyst02 = listArgs("one", "two", listArgs("three", "four"));
console.log(lyst02);
console.log(boxify(lyst02)); // OK ["one", ["two", [["three", ["four", null]], null]]]
const lyst03 = listArgs("one", "two", listArgs("three", "four"), "five", "six", listArgs(1,2,3,4));
console.log(lyst03);
console.log(boxify(lyst03)); // OK ["one", ["two", [["three", ["four", null]], ["five", ["six", null]]]]]
const lyst04 = listArgs("one", "two", listArgs("three", "four"), "five", "six", listArgs(1,2,3,4));
console.log(lyst04);
console.log(boxify(lyst04)); // ["one", ["two", [["three", ["four", null]], ["five", ["six", [[1, [2, [3, [4, null]]]], null]]]]]]
// validated and pretty printed:
/*
[
"one",
[
"two",
[
[
"three",
[
"four",
null
]
],
[
"five",
[
"six",
[
[
1,
[
2,
[
3,
[
4,
null
]
]
]
],
null
]
]
]
]
]
]
*/
const lyst05 =
listArgs(
"ExtraCellularSpace",
listArgs(
"ExtraCellularSolution",
listArgs(
"Glucose"
)
),
listArgs(
"EukaryoticCell",
listArgs(
"CellMembrane",
listArgs(
"CellBilayer"
)
),
listArgs(
"Cytoplasm",
listArgs(
"Cytosol",
listArgs(
"Glucose",
"Glucose_6_Phosphate",
"Fructose_6_Phosphate",
"Fructose_1x6_Biphosphate",
"DihydroxyacetonePhosphate",
"Glyceraldehyde_3_Phosphate",
"X1x3_BisphosphoGlycerate",
"X3_PhosphoGlycerate",
"X2_PhosphoGlycerate",
"PhosphoEnolPyruvate",
"Pyruvate",
),
"Hexokinase",
"PhosphoGlucoIsomerase",
"PhosphoFructokinase",
"Aldolase",
"TriosePhosphateIsomerase",
"Glyceraldehyde_3_phosphateDehydrogenase",
"PhosphoGlycerokinase",
"PhosphoGlyceromutase",
"Enolase",
"PyruvateKinase"
)
)
)
);
console.log(lyst05);
console.log(boxify(lyst05)); // OK
/*
["ExtraCellularSpace", [["ExtraCellularSolution", [["Glucose", null], null]], [["EukaryoticCell", [["CellMembrane", [["CellBilayer", null], null]], [["Cytoplasm", [["Cytosol", [["Glucose", ["Glucose_6_Phosphate", ["Fructose_6_Phosphate", ["Fructose_1x6_Biphosphate", ["DihydroxyacetonePhosphate", ["Glyceraldehyde_3_Phosphate", ["X1x3_BisphosphoGlycerate", ["X3_PhosphoGlycerate", ["X2_PhosphoGlycerate", ["PhosphoEnolPyruvate", ["Pyruvate", null]]]]]]]]]]], ["Hexokinase", ["PhosphoGlucoIsomerase", ["PhosphoFructokinase", ["Aldolase", ["TriosePhosphateIsomerase", ["Glyceraldehyde_3_phosphateDehydrogenase", ["PhosphoGlycerokinase", ["PhosphoGlyceromutase", ["Enolase", ["PyruvateKinase", null]]]]]]]]]]]], null]], null]]], null]]]
*/
// validated and pretty printed
/*
[
"ExtraCellularSpace",
[
[
"ExtraCellularSolution",
[
[
"Glucose",
null
],
null
]
],
[
[
"EukaryoticCell",
[
[
"CellMembrane",
[
[
"CellBilayer",
null
],
null
]
],
[
[
"Cytoplasm",
[
[
"Cytosol",
[
[
"Glucose",
[
"Glucose_6_Phosphate",
[
"Fructose_6_Phosphate",
[
"Fructose_1x6_Biphosphate",
[
"DihydroxyacetonePhosphate",
[
"Glyceraldehyde_3_Phosphate",
[
"X1x3_BisphosphoGlycerate",
[
"X3_PhosphoGlycerate",
[
"X2_PhosphoGlycerate",
[
"PhosphoEnolPyruvate",
[
"Pyruvate",
null
]
]
]
]
]
]
]
]
]
]
],
[
"Hexokinase",
[
"PhosphoGlucoIsomerase",
[
"PhosphoFructokinase",
[
"Aldolase",
[
"TriosePhosphateIsomerase",
[
"Glyceraldehyde_3_phosphateDehydrogenase",
[
"PhosphoGlycerokinase",
[
"PhosphoGlyceromutase",
[
"Enolase",
[
"PyruvateKinase",
null
]
]
]
]
]
]
]
]
]
]
]
],
null
]
],
null
]
]
],
null
]
]
]
*/
// -------------------------------------------------
console.log("Jan 20 arr11");
// Jan 20 generated by code I developed in Dev Tools
const arr11 = [
"ExtraCellularSpace",
[
[
"ExtraCellularSolution",
[
"Glucose"
]
],
[
"EukaryoticCell",
[
[
"CellMembrane",
[
"CellBilayer"
]
],
[
"Cytoplasm",
[
[
"Cytosol",
[
"Glucose",
"Glucose_6_Phosphate",
"Fructose_6_Phosphate",
"Fructose_1x6_Biphosphate",
"DihydroxyacetonePhosphate",
"Glyceraldehyde_3_Phosphate",
"X1x3_BisphosphoGlycerate",
"X3_PhosphoGlycerate",
"X2_PhosphoGlycerate",
"PhosphoEnolPyruvate",
"Pyruvate"
]
],
"Hexokinase",
"PhosphoGlucoIsomerase",
"PhosphoFructokinase",
"Aldolase",
"TriosePhosphateIsomerase",
"Glyceraldehyde_3_phosphateDehydrogenase",
"PhosphoGlycerokinase",
"PhosphoGlyceromutase",
"Enolase",
"PyruvateKinase"
]
]
]
],
"Avatar"
]
]
const list11 = list(arr11.reverse());
console.log(list11); // a pair function ???
console.log(boxify(list11)); //
})("CellModel3_Jan19")
//# sourceURL=CellModel3_Jan19.js
]]></Lambda>
<Lambda roleName="Jan26_01"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
console.log("Jan26_01");
var {pair, pairGM, head, tail, display, boxify, list, listArgs, append, is_null, length, reverse, last, butlast, emptyq, ycomb, testLambd} = $wnd.xh.lambd();
console.log(head(pair(201, 202))); // 201
testLambd();
console.log(boxify(listArgs(1,22,333,4444,55555,666666,7777777,"eight",{nine: 9})));
const lyst05 =
listArgs(
"ExtraCellularSpace",
listArgs(
"ExtraCellularSolution",
listArgs(
"Glucose"
)
),
listArgs(
"EukaryoticCell",
listArgs(
"CellMembrane",
listArgs(
"CellBilayer"
)
),
listArgs(
"Cytoplasm",
listArgs(
"Cytosol",
listArgs(
"Glucose",
"Glucose_6_Phosphate",
"Fructose_6_Phosphate",
"Fructose_1x6_Biphosphate",
"DihydroxyacetonePhosphate",
"Glyceraldehyde_3_Phosphate",
"X1x3_BisphosphoGlycerate",
"X3_PhosphoGlycerate",
"X2_PhosphoGlycerate",
"PhosphoEnolPyruvate",
"Pyruvate",
),
"Hexokinase",
"PhosphoGlucoIsomerase",
"PhosphoFructokinase",
"Aldolase",
"TriosePhosphateIsomerase",
"Glyceraldehyde_3_phosphateDehydrogenase",
"PhosphoGlycerokinase",
"PhosphoGlyceromutase",
"Enolase",
"PyruvateKinase"
)
)
)
);
console.log(lyst05);
console.log(boxify(lyst05)); // OK
var fac = ycomb(function(f) {
return function (n) {
return n > 1 ? n * f(n - 1) : 1;
};
});
var fib = ycomb(function(f) {
return function(n) {
return n > 1 ? f(n - 1) + f(n - 2) : n;
};
});
console.log(fac(4));
console.log(fib(4));
var fac2 = ycomb(f => n => n > 1
? n * f(n - 1)
: 1
)
console.log(fac2(5)); // OK 120
})("Jan26_01")
//# sourceURL=Jan26_01.js
]]></Lambda>
<!-- Jan26_01 result of console.log(boxify(lyst05))
["ExtraCellularSpace", [["ExtraCellularSolution", [["Glucose", null], null]], [["EukaryoticCell", [["CellMembrane", [["CellBilayer", null], null]], [["Cytoplasm", [["Cytosol", [["Glucose", ["Glucose_6_Phosphate", ["Fructose_6_Phosphate", ["Fructose_1x6_Biphosphate", ["DihydroxyacetonePhosphate", ["Glyceraldehyde_3_Phosphate", ["X1x3_BisphosphoGlycerate", ["X3_PhosphoGlycerate", ["X2_PhosphoGlycerate", ["PhosphoEnolPyruvate", ["Pyruvate", null]]]]]]]]]]], ["Hexokinase", ["PhosphoGlucoIsomerase", ["PhosphoFructokinase", ["Aldolase", ["TriosePhosphateIsomerase", ["Glyceraldehyde_3_phosphateDehydrogenase", ["PhosphoGlycerokinase", ["PhosphoGlyceromutase", ["Enolase", ["PyruvateKinase", null]]]]]]]]]]]], null]], null]]], null]]]
-->
<!-- Jan26_01 result of console.log(boxify(lyst05)) after manually adding spacing
validated and pretty-printed at jsonlint.com
[
"ExtraCellularSpace",
[
[
"ExtraCellularSolution",
[
[
"Glucose",
null
],
null
]
],
[
[
"EukaryoticCell",
[
[
"CellMembrane",
[
[
"CellBilayer",
null
],
null
]
],
[
[
"Cytoplasm",
[
[
"Cytosol",
[
[
"Glucose",
[
"Glucose_6_Phosphate",
[
"Fructose_6_Phosphate",
[
"Fructose_1x6_Biphosphate",
[
"DihydroxyacetonePhosphate",
[
"Glyceraldehyde_3_Phosphate",
[
"X1x3_BisphosphoGlycerate",
[
"X3_PhosphoGlycerate",
[
"X2_PhosphoGlycerate",
[
"PhosphoEnolPyruvate",
[
"Pyruvate",
null
]
]
]
]
]
]
]
]
]
]
],
[
"Hexokinase",
[
"PhosphoGlucoIsomerase",
[
"PhosphoFructokinase",
[
"Aldolase",
[
"TriosePhosphateIsomerase",
[
"Glyceraldehyde_3_phosphateDehydrogenase",
[
"PhosphoGlycerokinase",
[
"PhosphoGlyceromutase",
[
"Enolase",
[
"PyruvateKinase",
null
]
]
]
]
]
]
]
]
]
]
]
],
null
]
],
null
]
]
],
null
]
]
]
-->
<Lambda roleName="xhlambda"><![CDATA[
var beh = {};
((title) => {
console.log(title);
this.println(title);
let xhlambda = null;
if ($wnd.xh && !$wnd.xh.xhlambda) {
$wnd.xh.xhlambda = {};
xhlambda = $wnd.xh.xhlambda;
}
xhlambda.pair = (x, y) => m => m(x, y)
xhlambda.pairGM = x => y => m => m(x, y)
xhlambda.head = z => z((p, q) => p)
xhlambda.tail = z => z((p, q) => q)
xhlambda.display = x => console.log(x)
xhlambda.boxify = pr => typeof pr === "function" ? "[" + xhlambda.boxify(xhlambda.head(pr)) + ", " + xhlambda.boxify(xhlambda.tail(pr)) + "]" : JSON.stringify(pr)
xhlambda.list = arr => arr.length > 0 ? xhlambda.pair(arr.pop(), xhlambda.list(arr)) : null
xhlambda.listArgs = (...args) => xhlambda.list(args.reverse())
xhlambda.append = (list1, list2) => xhlambda.is_null(list1) ? list2 : xhlambda.pair(head(list1), xhlambda.append(tail(list1), list2))
xhlambda.is_null = thing => thing === null
xhlambda.length = (items, count = 0) => xhlambda.is_null(items) ? count : xhlambda.length(xhlambda.tail(items), count + 1)
xhlambda.reverse = (lst, acc = null) => xhlambda.is_null(lst) ? acc : xhlambda.reverse(xhlambda.tail(lst), xhlambda.pair(xhlambda.head(lst), acc))
// 3 new LOGO functions
xhlambda.last = lst => xhlambda.head(xhlambda.reverse(lst))
xhlambda.butlast = lst => xhlambda.reverse(xhlambda.tail(xhlambda.reverse(lst)))
xhlambda.emptyq = lst => lst === null ? true : false
})("xhlambda")
//# sourceURL=xhlambda.js
]]></Lambda>
<Lambda>console.log("LAST END");</Lambda>
</PhysicalSystem>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Lambda</title>
<rect id="PhysicalSystem/Lambda" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Lambda</title>
<rect id="PhysicalSystem/Lambda[2]" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment