I've been mulling around this crazy idea for a little while, and thought I would share it. If you haven't been following my earlier post[1] (I don't blame you, it's long and jumps all over the place), then my basic idea is that all complex data types would be represented as tables, so `(table)` would create something like this: (obj set (fn (k v) ...)
call (fn (k d) ...)
keys (fn () ...))
But... what should functions be represented as? They could of course be represented as a table that only has a `call` attribute: (obj call ...)
But we can go further. What if functions had an `arguments` attribute, that contained the argument list...? So this... (fn (a b c) ...)
...would create this: (obj call ...
arguments '(a b c))
And then, what if the body of the function was stored in the `body` attribute? So this... (fn (a b c)
(+ a b)
(+ b c))
...would create this: (obj call ...
arguments '(a b c)
body '((+ a b) (+ b c)))
And then, what if the function's environment was also stored in the `environment` attribute...? (obj call ...
arguments '(a b c)
body '((+ a b) (+ b c))
environment ...)
This would not only allow you to inspect the argument list, body, and environment of every function[2], but also allow you to change them! And since every environment would have an `outer` attribute that points to the outer scope, this would allow you to inspect/change the function's closure as well.Everything would be completely open. There would be no information hiding[3]. You could change how many arguments a function expects, you could change the function's body itself, you could change the function's environment, or change the outer environment... So. This is kinda scary. Because there's no information hiding, how would you implement security? Would security even be possible in such a language? But... Arc's goal is not security or safety, it's conciseness and malleability, and this idea would definitely increase malleability. In case information hiding is needed... we could provide a different mechanism for that. So rather than functions being opaque blobs by default, they would be open and free, with information hiding being used only when needed. What do you guys think? --- * [1]: http://arclanguage.org/item?id=14219 * [2]: This won't work on built-ins, because those are implemented in Python. But it would work on every user-created function. I may eventually get it to work on built-ins too, but that's more of a long-term goal. * [3]: I find it amusing that one reason I dislike Python is because it makes modules and classes so open and makes information hiding sorta difficult, yet here I am, seriously considering making py-arc even more open than Python. |