[RFC] object attribute access

29 views
Skip to first unread message

Mariano Guerra

unread,
Jul 25, 2012, 7:38:48 AM7/25/12
to kl...@googlegroups.com
hi,

in squim I need to interoperate with javascript and javascript
objects, that's why I provide a way to wrap JS objects and be able to
use them in squim.

to access attributes of an object in squim I implement the apply
method on the Object type, when called it will get the first parameter
and if it's a symbol it will resolve that symbol and call the result
with the remaining unevaluated parameters, something like:

(person location address)

will do ((person location) address)

this also allows calling methods in an object

(browser open "http://google.com")

it will even allow calling operatives since the remaining args aren't evaluated.

what do you think?

I thought about an alternative of having a type and some accessor
functions but it's not that OO and since I'm dealing with objects it
makes sense to be OO :)

what I like of this solution is that it looks like message passing and
would allow to define a method in term of more than one symbol doing
some kind of pattern matching or currying

PS: this is another reason of why I need code metadata, if I read
"(person location address)" back, I can't be sure it's an object
access or a function call and I would like to provide the user with a
way to enter in the ui "person.location.address" and translate it to
the squim way below.

Andres Navarro

unread,
Jul 25, 2012, 11:29:03 AM7/25/12
to kl...@googlegroups.com
On Wed, Jul 25, 2012 at 8:38 AM, Mariano Guerra
<luismari...@gmail.com> wrote:
> hi,
>
> in squim I need to interoperate with javascript and javascript
> objects, that's why I provide a way to wrap JS objects and be able to
> use them in squim.
>
> to access attributes of an object in squim I implement the apply
> method on the Object type, when called it will get the first parameter
> and if it's a symbol it will resolve that symbol and call the result
> with the remaining unevaluated parameters, something like:
>
> (person location address)
>
> will do ((person location) address)
>
> this also allows calling methods in an object
>
> (browser open "http://google.com")
>
> it will even allow calling operatives since the remaining args aren't evaluated.
>
> what do you think?
>

This can be implemented for Kernel using something similar to the
approach I mentioned for write. You would just need a way to
change/add behaviour to eval, the same way you need to change
behaviour to write to allow new external representations. In the
report there is a mention of this, regarding the ability of user code
to mimic primitive features, especially read, write, eval, eq?, etc,
but the matter is left open. In your case, you need to change the
behaviour of eval on pairs so that instead of checking the car for
just operative and applicative, it also checks for objects, and acts
accordingly.

Regards,
Andres Navarro

Manuel Simoni

unread,
Sep 10, 2012, 9:40:42 AM9/10/12
to kl...@googlegroups.com, luismari...@gmail.com
On Wednesday, July 25, 2012 1:38:48 PM UTC+2, Mariano Guerra wrote:
hi,

 in squim I need to interoperate with javascript and javascript
objects, that's why I provide a way to wrap JS objects and be able to
use them in squim.

to access attributes of an object in squim I implement the apply
method on the Object type, when called it will get the first parameter
and if it's a symbol it will resolve that symbol and call the result
with the remaining unevaluated parameters, something like:

(person location address)

will do ((person location) address)

IMHO, this is a bad idea, and if at all, should be done at a higher level.

I would provide functions like (js-get-prop <obj> <prop-name>), (js-set-prop! <obj> <prop-name> <prop-value>) etc.

JS is so ugly, that you really want to keep it out of your language semantics.

Manuel
Reply all
Reply to author
Forward
0 new messages