From: Per Bothner <per@bothner.com>
To: Duncan Mak <duncanmak@gmail.com>,
kawa mailing list <kawa@sourceware.org>
Subject: Re: Syntax for calling super implementation when overriding a method
Date: Tue, 02 Apr 2019 13:47:00 -0000 [thread overview]
Message-ID: <bb944c85-2204-f92c-760b-ad45a3612186@bothner.com> (raw)
In-Reply-To: <CABgWrqrvvtAgECXfCn7KeXtJ5x11j4fkWpz1trcmLuzFqvVyRQ@mail.gmail.com>
On 4/1/19 11:58 AM, Duncan Mak wrote:
> Hello Per,
>
> I see that there's syntax (this) for referring to the current instance.
>
> When I'm defining a class hierarchy, and I'd like to override a method in a
> subclass, is there a similar syntax, i.e. (super)?
>
> For now, I'm doing this (superclass:method instance ...), but it'd be nice
> not having to explicitly name the superclass.
The Kawa manual suggests using invoke-special, and has a few examples:
(invoke-special supersuper (this) 'methodname arg ...)
where 'methodname is '*init* in the case of a constructor.
However (as you and the manual also notes), this is annoyingly verbose.
One approach is as you suggest:
((super):methodname arg ...)
This would start by having (super) expand to a distinct variant of ThisExpr,
but changing the code-generation to call invokespecial.
An alternative (possibly easier to implement) might be
(invoke-super 'methodname arg ...)
Either of these would be a good project in terms of learning more about how Kawa works.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
prev parent reply other threads:[~2019-04-02 13:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-01 18:59 Duncan Mak
2019-04-02 13:47 ` Per Bothner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bb944c85-2204-f92c-760b-ad45a3612186@bothner.com \
--to=per@bothner.com \
--cc=duncanmak@gmail.com \
--cc=kawa@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).