soegaard2
2021-8-5 19:14:46

In Sketching I attempted to make dot notation work for objects.

The notation (obj.f arg ...) will where obj evaluates to an object, will invoke the method f with arguments arg ....

An reference to obj.f will get the field of the object and (:= obj.f v) will assign the value v to the filed f of obj.

Now, obj is restricted to be an identifer, but I still find the notation useful — and I like not having to use the explicit send.

Now, I decided to add “fake” fields and methods to vectors, in order for vector.length etc. to work. It sort of makes vectors look like objects.

Is this a reasonable compromise, between ease of use v.length instead of (vector-length v) versus being slightly slower?

This shows how methods and fields are added:

https://github.com/soegaard/sketching/blob/main/sketching-lib/sketching/dot-method.rkt#L620

The documentation of assignment and friends are here: https://soegaard.github.io/sketching/Reference.html#%28def._%28%28lib._sketching%2Fexports-no-gui..rkt%29._~3a~3d%29%29


laurent.orseau
2021-8-5 19:24:50

Looks like a syntax bee entry to me ;) @spdegabrielle


notjack
2021-8-5 20:45:26

I like it


notjack
2021-8-5 20:46:45

and I think “property” is the usual OOP name for that “codes like a method, looks like a field” concept


notjack
2021-8-5 20:46:59

and I think they’re generally a good idea


spdegabrielle
2021-8-5 20:57:50

We do need more entries so it would be appreciated!


rokitna
2021-8-5 21:54:41

(codes.like a-method) (flies.like a-banana)


samth
2021-8-6 01:11:20

This is very relevant to the discussion of . notation in @mflatt’s recent Rhombus proposal