4 ms·
"JavaScript can be the native format of your data" I don't think developers appreciate how amazing this feature is in a language. Code should be a data-struct
by ericHosick 12y ago
"JavaScript can be the native format of your data"
I don't think developers appreciate how amazing this feature is in a language.
Code should be a data-structure giving you all the benefits of data-structures including persistence.
- calebm 12y agoCloser to homoiconicity, but not quite there.
- ericHosick 12y agoYa. Exactly. I like that term.
- rubiquity 12y agoNot exactly at all. Homoiconicity is when your program can be represented as a data structure. Like, literally a data structure. JavaScript doesn't even come close to that.
- deleted 12y ago[deleted]
- ericHosick 12y agoYa. I mean exactly as in the term Homoiconicity. Not Javascript itself. However.. You can use an approach to programming in JavaScript that allows java-script to be Homoiconicit. It is also possible to do the same thing in C#. Here is an example: // This code is a data structure // that can be traversed, persisted, // etc. // Write to the console ( 3 + -1 ) + -1 Con({ text: Add({ left: Add({ left: Num(3), right: Num(-1) }), right: Num(-1) }), }).go; // Add defined var AddF = function() {}; AddF.prototype = { get go() { return this.asNum; }, get asNum() { return this.d.left.asNum + this.d.right.asNum; }, get asStr() { return "(" + this.d.left.asStr + " + " + this.d.right.asStr + ")"; } }; function Add(d) { var f = new AddF(); f.d = d; return f; }; // Num Defined var NumF = function() {}; NumF.prototype = { get val() { return this.d; }, get go() { return this.d; }, get asNum() { return this.d; }, get asArr() { return [this.d]; }, get asStr() { return this.d.toString(); } }; function Num(d) { var f = new NumF(); f.d = d; return f; }; var ConF = function() {}; ConF.prototype = { get go() { console.log(this.d.text.go); return unknown; } } function Con(d) { var f = new ConF(); f.d = d; return f; };
- deleted 12y ago[deleted]
- rubiquity 12y agoAssuming you are talking about JSON, that isn't even close to homoiconicity. Even if it were, any JSON you send/receive over the wire still has to be encoded/decoded into JSON, taking you right back to square one just like with any other language consuming JSON.