This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Alternate syntax for field access/method calls
- From: Per Bothner <per at bothner dot com>
- To: dominique dot boucher at nuecho dot com
- Cc: kawa at sources dot redhat dot com
- Date: Sat, 22 Jan 2005 15:45:01 -0800
- Subject: Re: Alternate syntax for field access/method calls
- References: <200501210256.j0L2uB0X013660@bergman.nuecho.ad>
Dominique Boucher wrote:
Also, it was not a request for changing or adding anything to Kawa. It was
only
a small experiment with readtables. I know a few (proprietary) Lisp systems
that
use the same [ ] notation. I simply wanted to know how easy it would be in
Kawa to
emulate that. And I wanted to share this experience with other
users/developers.
Yes, that's cool. But it is still worthwhile thinking about
whether Kawa needs a more compact standard syntax.
And I do have another solution: a simple 'with' macro that implements the
same
expansion:
(with object (method1) (method2 a b))
=>
(invoke (invoke object 'method1) 'method2 a b)
Yes. That's similar to my solution (2), but using a regular
macro name 'with' instead of '.'. That makes it cleaner and
simplier to implement, but it doesn't save any typing in the
single-call case compared to invoke. It only wins in the
cascading-invocation case.
I think the *:method syntax may be worth considering. It's
compact. It's simple. And it's a natural extension of
the exiting class-name:method syntax - Kawa already has too
many ways to write method invocation, so we should avoid
something too new.
Note that:
(*:method x a b)
is more compact than:
(with x (method a b))
and is the same length (and uses fewer token) as:
[x (method a b)]
In the cascading case:
(*:m2 (*:m1 x a) b)
is shorter than:
(with x (m1 a) (m2 b))
and and a few character longer than:
[x (m1 a) (m2 b)]
With 3 calls:
(*:m3 (*:m2 (*:m1 x a) b) c)
(with x (m1 a) (m2 b) (m3 c))
[x (m1 a) (m2 b) (m3 c)]
However, the *:m syntax does have the possible disadvantage
that the method names are "inside out", which is non-ideal
if the calls are basically sequential.
But in that case, instead of defining:
(with object (method1) (method2 a b))
as:
(invoke (invoke object 'method1) 'method2 a b)
it might be more useful to define it as:
(let ((x object)) (invoke x 'method1) (invoke x 'method2 a b)))
--
--Per Bothner
per@bothner.com http://per.bothner.com/