3 ms·
In TXR Lisp, I provide a "referencing dot" syntax (http://www.nongnu.org/txr/txr-manpage.html#N-013775DB http://www.nongnu.org/txr/txr-manpage.html#N-013775DB).
by kazinator 11y ago
In TXR Lisp, I provide a "referencing dot" syntax (http://www.nongnu.org/txr/txr-manpage.html#N-013775DB http://www.nongnu.org/txr/txr-manpage.html#N-013775DB).
A dot between symbols or compound expressions, with no whitespace, translates to a qref form:
a.b.c.d -> (qref a b c d)
The qref macro (http://www.nongnu.org/txr/txr-manpage.html#N-03A212AB http://www.nongnu.org/txr/txr-manpage.html#N-03A212AB) in turn does useful things like:
obj.child-obj.slot ;; slot access
obj.(fun arg1 arg2) ;; (call obj.fun obj arg1 arg2), obj evaluated once
I didn't go for the equivalence of (f x y) and x.(f y) because it's not a CLOS-like object system. It's single dispatch, and a method is actually a slot. Thus x.(f y) semantically corresponds to (call x.f y), and I don't see any value in making (f x y) a synonym for that, only harm.
It would complicate how function calls work. If global function f exists, x.(f y) still calls the one in x, unambiguously. for (f x y) to do that, the function lookup for f would first have to check that x is a struct object, and whether it has a slot called f, and then use it. Then otherwise fall back on behaving like a normal function call. That's just too much semantic cruft jammed into function calls.
The x.(f y) (f x y) equivalence only makes sense if you have a CLOS-like object system with generic functions that are separate from classes, so that f is a generic function named in the ordinary function namespace, which, when called, dispatches methods. Or a completely static language in which it is worked out at compile time whether f is an ordinary function or the member.