Yeti newcomer and a question

28 views
Skip to first unread message

Tommy McGuire

unread,
Jul 5, 2011, 1:28:23 PM7/5/11
to yeti-lang
I spent the weekend playing with Yeti, and I'm very impressed. It is a
*nice* language.

To have something to work on, I cloned the snake game from Learning
Clojure, which went almost perfectly. I do have one question, though.
I probably missed it in the documentation, but how do you access a
method of a class' superclass?

Specifically, I created a subclass of JPanel whose implementation of
paintComponent needs to call the superclass' paintComponent. If you
want to check out my code, it's at http://www.crsr.net/files/snake.yeti.
I also wrote some comments about it at http://maniagnosis.crsr.net/2011/07/snakes-on-yeti.html.
I would welcome any suggestions or corrections.

Madis

unread,
Jul 6, 2011, 6:30:38 AM7/6/11
to yeti-lang

It wasn't implemented, but I implemented it now. ;)

Just use super#fobar(...) in some method.

https://github.com/mth/yeti/commit/0a7b745cf9da839fcac0c03b9065518263549e18

The http://linux.ee/~mzz/yeti/yeti.jar has been updated, too.

Madis

unread,
Jul 6, 2011, 9:31:28 AM7/6/11
to yeti-lang
On Tue, 5 Jul 2011, Tommy McGuire wrote:

> If you want to check out my code, it's at http://www.crsr.net/files/snake.yeti.
> I also wrote some comments about it at http://maniagnosis.crsr.net/2011/07/snakes-on-yeti.html.
> I would welcome any suggestions or corrections.

Looked at the comments now, member? is contains in the library (and yes,
it would've been better named contains?).

The list destructuring pattern matching is there, but you must use case of to do it.

butLast lst =
case lst of
[_]: [];
h :: t: h :: butLast t;
_: [];
esac;

There is a short-hand for creating new structures from existing ones:

turn snake newdir =
{ dir = newdir,
body = snake.body,
color = snake.color };

Could be written as:

turn snake dir =
snake with {dir};

The {dir} there is equivalent to {dir = dir}, and this can be used
everywhere, so:

{ x = x, y = y, w = w, h = h } = pointToScreenRec pt;

can be written as

{ x, y, w, h } = pointToScreenRec pt;

Hoping this helps ;)

Tommy McGuire

unread,
Jul 6, 2011, 5:00:47 PM7/6/11
to yeti-lang
On Jul 6, 8:31 am, Madis <ma...@cyber.ee> wrote:
> On Tue, 5 Jul 2011, Tommy McGuire wrote:
> > If you want to check out my code, it's athttp://www.crsr.net/files/snake.yeti.
> > I also wrote some comments about it athttp://maniagnosis.crsr.net/2011/07/snakes-on-yeti.html.
> > I would welcome any suggestions or corrections.
>
> Looked at the comments now, member? is contains in the library (and yes,
> it would've been better named contains?).
> ...

Thanks for your comments! I was updating my code and had a little
problem with the super#paintComponent(g) call and the new yeti.jar.

snake.yeti:142:14: Non-public method
javax.swing.JComponent#paintComponent cannot be accessed from
different package ()

It looks like the paintComponent method in javax.swing.JComponent (the
superclass of JPanel) is protected. It should be accessible from my
subclass of JPanel, right?

Also, I am wondering about the definition of butLast:

butLast lst =
case lst of
[_]: [];
h :: t: h :: butLast t;
_: [];
esac;

If I change it to be:

butLast lst =
case lst of
[] : [];
[_] : [];
h :: t : h :: butLast t;
esac;

I get an error: "1:10: Partial match: []".

I can see where your version is guaranteed to match, because the last
case is a default. However, I think mine is exhaustive. What is wrong
with it?

Madis

unread,
Jul 6, 2011, 6:54:33 PM7/6/11
to yeti-lang

On Wed, 6 Jul 2011, Tommy McGuire wrote:

> On Jul 6, 8:31�am, Madis <ma...@cyber.ee> wrote:
>> On Tue, 5 Jul 2011, Tommy McGuire wrote:
>>> If you want to check out my code, it's athttp://www.crsr.net/files/snake.yeti.
>>> I also wrote some comments about it athttp://maniagnosis.crsr.net/2011/07/snakes-on-yeti.html.
>>> I would welcome any suggestions or corrections.
>>
>> Looked at the comments now, member? is contains in the library (and yes,
>> it would've been better named contains?).
>> ...
>
> Thanks for your comments! I was updating my code and had a little
> problem with the super#paintComponent(g) call and the new yeti.jar.
>
> snake.yeti:142:14: Non-public method
> javax.swing.JComponent#paintComponent cannot be accessed from
> different package ()
>
> It looks like the paintComponent method in javax.swing.JComponent (the
> superclass of JPanel) is protected. It should be accessible from my
> subclass of JPanel, right?

I'll look into it.

> Also, I am wondering about the definition of butLast:
>
> butLast lst =
> case lst of
> [_]: [];
> h :: t: h :: butLast t;
> _: [];
> esac;
>
> If I change it to be:
>
> butLast lst =
> case lst of
> [] : [];
> [_] : [];
> h :: t : h :: butLast t;
> esac;
>
> I get an error: "1:10: Partial match: []".
>
> I can see where your version is guaranteed to match, because the last
> case is a default. However, I think mine is exhaustive. What is wrong
> with it?

Yes, your match is exhaustive, but the pattern analyzer isn't currently
smart enough and errs on the safe side (requiring a match-all pattern on
list matches). In practice it's usually possible to organize the pattern
that way.

Madis

unread,
Jul 6, 2011, 7:04:52 PM7/6/11
to yeti-lang

On Thu, 7 Jul 2011, Madis wrote:

> On Wed, 6 Jul 2011, Tommy McGuire wrote:
>
>> Thanks for your comments! I was updating my code and had a little
>> problem with the super#paintComponent(g) call and the new yeti.jar.
>>
>> snake.yeti:142:14: Non-public method
>> javax.swing.JComponent#paintComponent cannot be accessed from
>> different package ()
>>
>> It looks like the paintComponent method in javax.swing.JComponent (the
>> superclass of JPanel) is protected. It should be accessible from my
>> subclass of JPanel, right?
>
> I'll look into it.

Should be fixed now.

Tommy McGuire

unread,
Jul 7, 2011, 5:52:20 PM7/7/11
to yeti-lang
On Jul 6, 6:04 pm, Madis <ma...@cyber.ee> wrote:
> >> It looks like the paintComponent method in javax.swing.JComponent (the
> >> superclass of JPanel) is protected. It should be accessible from my
> >> subclass of JPanel, right?
>
> > I'll look into it.
>
> Should be fixed now.

Yep, works perfectly. Thanks!

Tommy McGuire

unread,
Jul 6, 2011, 2:55:12 PM7/6/11
to yeti-lang
On Jul 6, 5:30 am, Madis <ma...@cyber.ee> wrote:
> On Tue, 5 Jul 2011, Tommy McGuire wrote:
> > Specifically, I created a subclass of JPanel whose implementation of
> > paintComponent needs to call the superclass' paintComponent.
>
> It wasn't implemented, but I implemented it now. ;)
>
> Just use super#fobar(...) in some method.
>
> https://github.com/mth/yeti/commit/0a7b745cf9da839fcac0c03b9065518263...
>
> Thehttp://linux.ee/~mzz/yeti/yeti.jarhas been updated, too.

That was fast! Thanks!
Reply all
Reply to author
Forward
0 new messages