If JavaScript scopes and objects are so alike, then why do we need both concepts at the same time?
The Scopes programming language takes the saying "Objects are a poor man's closures" (and its reverse, "Closures are a poor man's objects") seriously. The saying is especially truthful in the case of JavaScript due to the way that its prototypal inheritance chain works identical to lexical variable lookup. Scopes removes the conceptual distinction between the two. Here's what that looks like:
let adjective = "awesome"; let concepts = [ { let name = "objects"; let adjective = "boring" } { let name = "scopes" } ] let describe = concept => `${concept.name} are ${concept.adjective}` console.log( concepts.map(describe) ) // ["objects are boring", "scopes are awesome"]
It's pretty much JavaScript already, right? A super straightforward transpilation step gives us:
let _S1 = Object.create(null); _S1.adjective = "awesome"; let _S2 = _Array_create(_S1); let _S3 = Object.create(_S2); _S3.name = "objects"; _S3.adjective = "boring"; _S2.push(_S3); let _S4 = Object.create(_S2); _S4.name = "scopes"; _S2.push(_S4); _S1.people = _S2; _S1.describe = concept => `${concept.name} are ${concept.adjective}` console.log( _S1.people.map(_S1.describe) ); // ["objects are boring", "scopes are awesome"]
And about that _Array_create
function in the transpilation
output, it's a simple helper that "glues" together the prototype chain
in the way we want it: (1) the outer scope — (2) the array methods
(Array prototype) — (3) the array itself:
let _ArrayMethods = (() => { let { map, filter, reduce, push /* etc */ } = []; return { map, filter, reduce, push /* etc */ }; })(); let _Array_create = S => { let A = Object.create(S); Object.assign(A, _ArrayMethods); return Object.create(A); }
Is this even a good idea?
I don't know! But eliminating concepts seems like generally a good idea,
so I'm giving it a try.
This is hardly a description of a language, where's the rest?
Coming very soon. There'll be a language description, a transpiler, more
interesting examples, etc. For now, this is just a quick intro page so
that I can register the wonderful domain name
https://scopes.js.org/
:D
I'm not so sure about the logo... is this the final design?
Nope. I want to do something playful with the JS-square trend, but I'm
not very graphically oriented, haha! Designs and ideas are welcome :)
Who is this coming from? Can I get in contact?
For sure! It's me, Kelley van Evert, hit
me up!