Created
December 12, 2023 12:05
-
-
Save joakim/68f33a75657719ad90be70c46545ca4b to your computer and use it in GitHub Desktop.
Evil Spreadsheet
This file contains hidden or 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 this Python code: https://ralsina.me/weblog/posts/BB585.html | |
// Really really limited, but it works. "Look ma, no DAG!" | |
function evil(formula, sheet) { | |
with (sheet.functions) { | |
with (sheet.cells) { | |
return eval(formula); | |
} | |
} | |
} | |
class EvilSpreadsheet { | |
cells; | |
functions; | |
constructor(functions = {}, cells = {}) { | |
this.cells = cells; | |
this.functions = functions; | |
return new Proxy(this, { | |
get(sheet, cell) { | |
return evil(sheet.cells[String(cell).toUpperCase()], sheet); | |
}, | |
set(sheet, cell, formula) { | |
sheet.cells[String(cell).toUpperCase()] = formula; | |
return true; | |
} | |
}); | |
} | |
} | |
const sheet = new EvilSpreadsheet(Math); | |
sheet['a1'] = 6; | |
sheet['a2'] = 7; | |
sheet['a3'] = 'log(A1 * A2)'; | |
sheet['a3']; // 3.7376696182833684 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment