- Summary
- Example programs
- Updated (?) edit.k
- ~2014 older version that has more info
- The project has been running since at least 2012
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ "Apter trees" http://archive.vector.org.uk/art10500340 | |
/ https://github.com/stevanapter/hypertree#concepts | |
/ http://nsl.com/k/treetable/treetable_k3.html | |
/ http://www.nsl.com/k/trees.k | |
/ John Earnest notes https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Trees.md | |
/ Aaron Hsu talk on high-performance tree wrangling https://www.youtube.com/watch?v=hzPd3umu78g | |
/ https://www.dyalog.com/uploads/conference/dyalog18/presentations/U19_Tree_Wrangling_the_APL_Way.pdf | |
/ Translation into k by JE: https://github.com/JohnEarnest/ok/blob/gh-pages/examples/key.k | |
/ Conquering recursion: http://archive.vector.org.uk/art10501740 | |
/ https://news.ycombinator.com/item?id=21680133 - comments from geocar and John Earnest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://twitter.com/ua6oxa/status/1170457046153650176 | |
"use strict"; | |
function evalInContext(env, code) { | |
const | |
s = JSON.stringify, | |
locals = Object.keys(env), | |
keys = locals.map(function(k){return s(k)}), | |
values = locals.map(function(k){return env[k]}), | |
body = s("return eval(" + code + ")") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspired by http://kparc.com/b/c.h | |
// See also https://chat.stackexchange.com/transcript/message/51402407#51402407 | |
const x="x",y="y" | |
// Function makers | |
function fn() {return new Function(...arguments)} | |
function f0(b) {return fn(b)} | |
function f1(b) {return fn(x,b)} | |
function f2(b) {return fn(x,y,b)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OPTION A: Nest value and coords within same obj | |
_CELLS = { | |
a: { | |
v: 123, | |
l: "B2" | |
}, | |
b: { | |
get v() {return a * 2}, | |
l: "B3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Caveats: | |
- The below code assumes we have access to the consumed sheet's _CELLS object. Unclear how that would be established (c+p?). | |
- Will somehow need to deal with accessing cells in topological order. We record this when a sheet is run - maybe we can use that? | |
- Unclear whether/how we will import sheet boilerplate fns (maybe a good idea to move it to a dedicated _BOILERPLATE object...) | |
*/ | |
var _CELLS = { | |
a: 123, | |
get b() {return a * 2} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Balancing speed and concision, with a preference for speed. Can we do better? | |
// No ES6! Mesh is ES5-compatible. | |
// Added to global namespace by calling the following: | |
// g._defFunctions = function() {for (let k in _FUNCTIONS) g[k] = _FUNCTIONS[k]} | |
// Vanilla | |
const _FUNCTIONS = { | |
SUM: function() { | |
const l=arguments.length,f=function(x,y){return x+y}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const _CELLS = { | |
B2: ({ | |
l: [1,1], | |
n: false, | |
get v() { | |
return `{"some": "simple value", "another": "simple_value", "nested": [1, 2, 3], "obj": {"hello": "world!", "it's": "me"}}`; | |
} | |
}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Array literals don't have a way to set getters, which are essential for self-references | |
// They *do* work if you manage them directly, but this produces source code that's difficult to manage. | |
const arr = [1]; | |
Object.defineProperty(arr, '1', {get: function() {return this[0] + 1}}) | |
console.log(arr[1]) // prints 2 | |
arr[0] = 1234; | |
console.log(arr[1]) // prints 1235 | |
// 2. Objects literals don't have a key order, which is essential for self-refences to preceding values. | |
// (You could *potentially* mimic this by making an object literal with keys that are numbers that has __proto__ = Array.prototype, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text | |
const FS = String.fromCharCode(28); // File separator; end of file. Or between a concatenation of what might otherwise be separate files. | |
const GS = String.fromCharCode(29); // Group separator; between sections of data. Not needed in simple data files. | |
const RS = String.fromCharCode(30); // Record separator; end of a record or row. | |
const US = String.fromCharCode(31); // Unit separator; between fields of a record, or members of a row. | |
function print_to_string_table(str) { | |
let o = ""; | |
for (var i = 0; i < str.length; i++) { | |
const char = str[i]; |