Created
February 8, 2013 05:32
-
-
Save Beyamor/4736860 to your computer and use it in GitHub Desktop.
A thought experiment involving an associative array-oriented language.
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
// Lisp, for reference | |
(if something? | |
(if something-else? | |
"double true" | |
"true and false") | |
"just false") | |
// Let's try something javascript-y | |
{tag: if, | |
what: something, | |
true: {tag: if, | |
what: something-else, | |
true: "double true", | |
false: "true and false"}, | |
false: "just false} | |
// Okay. Clearly commas should be optional. | |
{tag: if | |
what: something | |
true: {tag: if | |
what: something-else | |
true: "double true" | |
false: "true and false"} | |
false: "just false} | |
// "tag" is too verbose. Maybe just assume the first token is the tag? | |
{if | |
what: something | |
true: {if | |
what: something-else | |
true: "double true" | |
false: "true and false"} | |
false: "just false} | |
// We're getting somewhere, but the special casing is too much syntax | |
// Maybe something shorter. | |
{. if | |
what: something | |
true: {. if | |
what: something-else | |
true: "double true" | |
false: "true and false"} | |
false: "just false"} | |
// Ehh. Not great. Not bad, but not great. | |
// Actually, the colons are redunant if every form must be a map. | |
{tag if | |
what something | |
true {tag if | |
what something-else | |
true "double true" | |
false "true and false"} | |
false "just false} | |
// "tag" still sticks out like a sore thumb. | |
// The thing is, it needs to be painfully succinct *and* easy to type | |
// However, it should, ideally, still fit in the everything-is-a-map syntax | |
{- if | |
what something | |
true {- if | |
what something-else | |
true "double true" | |
false "true and false"} | |
false "just false"} | |
// Having the tag as a key is reading too badly. | |
// Maybe we can go back to the special syntax. | |
{:if | |
what something | |
true {:if | |
what something-else | |
true "double true" | |
false "true and false"} | |
false "just false"} | |
// Naw dude. I think it's gotta be key and value all the way down. | |
// Let's keep it briefer than "tag" though. | |
{. if | |
what something | |
true {. if | |
what something-else | |
true "double true" | |
false "true and false"} | |
false "just false"} | |
// Now we're getting somewhere. But let's keep it succinct. | |
{. if | |
? something | |
t {. if | |
? something-else | |
t "double true" | |
f "true and false"} | |
f "just false} | |
// Too succinct? It's too brief to be readable and *still* a lot of typing | |
// Whatever. As a proof of mental concept, we can muck about with the order | |
{false "just false" | |
true {true "double true" | |
false "true and false" | |
. if} | |
. if} | |
// Ha. That's terrible. | |
// Speaking of which, how does math look? | |
{. + | |
x 1 | |
y 2} | |
// Jeez. That's gunna be awful for lots of math. | |
// Okay. Let's try function definition real quick. | |
{. defn | |
name fizzbuzz | |
args {max 100} | |
{. for | |
bind {i {. range from 1 to max}} | |
body {. println | |
what {. cond | |
{. and | |
x {. zero? x {. mod x i y 3}} | |
y {. zero? x {. mod x i y 5}}} "FizzBuzz" | |
{. zero? x {. mod x i y 3}} "Fizz" | |
{. zero? x {. mod x i y 5}} "Buzz | |
else i}}}} | |
// Okay. Some good stuff, some bad stuff, some interesting stuff. | |
// The big one is the args list. Notice how it's just {max 100}? | |
// So, an argument named "upto" defaulting to 100. | |
// Well, I kind of intended that to be a plain old data instead of a function. | |
// So, leaving out the "." key might be a good indicator for things which shouldn't be called. | |
// The alternative is something like lisp's (list ...) - {. map ...} | |
// Anyway, sometimes the arg keylist works great - {. range from 1 to max} | |
// Other times, it's a struggle to name the argument - {. zero? x {. mod x i y 3}} | |
// I see a lot of xs and ys as throwaway variable names. That's a bummer. | |
// It's really awkard how "bind" is unordered. That sucks, man. | |
// Like, what do you do with {y x x {. range from 1 to 100}}? | |
// I dunno. Some of this is interesting, but I don't see a way out of position-oriented code right now. | |
// Still, gunna keep thinking about this. Maybe implement it some time. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment