trait and properties thru getter/setters

11 views
Skip to first unread message

Stéphane Payrard

unread,
May 13, 2005, 1:58:13 PM5/13/05
to perl6-l...@perl.org
There is syntax to define trait and properties
but is there an API?

my $b = eval '$a but true'; # setting a true property
# API to do it without an eval?

A trait setter probably does not make sense but for the
implementer because it should not be set at run time.

Incidentally, in a interactive environment it would be cool
to access the documentation of variables and functions using
properties. Say "doc" and "udoc" respectively for the full and
one line version.


--
cognominal stef

Stéphane Payrard

unread,
May 13, 2005, 3:20:16 PM5/13/05
to perl6-l...@perl.org
On Fri, May 13, 2005 at 06:37:50PM +0000, mark.a...@comcast.net wrote:
>
>
> > There is syntax to define trait and properties
> > but is there an API?
> >
> > my $b = eval '$a but true'; # setting a true property
> > # API to do it without an eval?
> I don't understand why you think you need the eval here?

My question is more generic than my example.
I may not know at compile time what is the value/trait name and its
value.

> >
> > A trait setter probably does not make sense but for the
> > implementer because it should not be set at run time.
> >
> > Incidentally, in a interactive environment it would be cool
> > to access the documentation of variables and functions using
> > properties. Say "doc" and "udoc" respectively for the full and
> > one line version.
> >
>
> --

> Mark Biggar
--
cognominal stef

Brent 'Dax' Royal-Gordon

unread,
May 13, 2005, 3:26:22 PM5/13/05
to st...@payrard.net, perl6-l...@perl.org
On 5/13/05, Stéphane Payrard <st...@payrard.net> wrote:
> > > There is syntax to define trait and properties
> > > but is there an API?
> > >
> > > my $b = eval '$a but true'; # setting a true property
> > > # API to do it without an eval?
>
> My question is more generic than my example.
> I may not know at compile time what is the value/trait name and its
> value.

Well, the value's pretty easy--just pass in a variable:

my $b = $a is foo($bar);

As for the name, I'd be surprised if the standard symbolic-ref syntax
didn't work:

my $b = $a is ::($foo)($bar);

--
Brent 'Dax' Royal-Gordon <br...@brentdax.com>
Perl and Parrot hacker

Larry Wall

unread,
May 13, 2005, 3:31:09 PM5/13/05
to perl6-l...@perl.org
On Fri, May 13, 2005 at 12:26:22PM -0700, Brent 'Dax' Royal-Gordon wrote:
: Well, the value's pretty easy--just pass in a variable:

:
: my $b = $a is foo($bar);

As we currently have it, that is not legal syntax. "is" may only
be applied to declarations. You must use "does" or "but" to mixin
things at run-time (where this includes the compiler's run-time bits).

Larry

Stéphane Payrard

unread,
May 13, 2005, 3:40:51 PM5/13/05
to perl6-l...@perl.org

And what about the getter part of my question? :)

>
> Larry
>

--
cognominal stef

Brent 'Dax' Royal-Gordon

unread,
May 13, 2005, 3:56:19 PM5/13/05
to perl6-l...@perl.org
On 5/13/05, Larry Wall <la...@wall.org> wrote:
> On Fri, May 13, 2005 at 12:26:22PM -0700, Brent 'Dax' Royal-Gordon wrote:
> : my $b = $a is foo($bar);
>
> As we currently have it, that is not legal syntax. "is" may only
> be applied to declarations.

Sorry, think-o. I meant 'but' in my examples (and Stéphane used 'but' in his).

Should I construe the fact that you didn't comment on the ::() to mean
that the symref syntax works here?

Larry Wall

unread,
May 13, 2005, 4:10:09 PM5/13/05
to perl6-l...@perl.org
On Fri, May 13, 2005 at 12:56:19PM -0700, Brent 'Dax' Royal-Gordon wrote:
: Should I construe the fact that you didn't comment on the ::() to mean

: that the symref syntax works here?

Offhand I don't see any reason for it not to.

Larry

Larry Wall

unread,
May 13, 2005, 4:13:43 PM5/13/05
to perl6-l...@perl.org, st...@payrard.net
On Fri, May 13, 2005 at 09:40:51PM +0200, Stéphane Payrard wrote:
: And what about the getter part of my question? :)

A12 discusses the relationship of traits and properties in great
detail. Any trait's metadata can be stored as properties at compile
time, and such metadata can be retrieved as properties at any time.
But traits are allowed to do other things than just store metadata.

Larry

Mark A Biggar

unread,
May 13, 2005, 2:37:50 PM5/13/05
to st...@payrard.net, perl6-l...@perl.org
I don't understand why you think you need the eval here?

--
Mark Biggar
ma...@biggar.org
mark.a...@comcast.net
mbi...@paypal.com


> There is syntax to define trait and properties
> but is there an API?
>
> my $b = eval '$a but true'; # setting a true property
> # API to do it without an eval?
>

> A trait setter probably does not make sense but for the
> implementer because it should not be set at run time.
>
> Incidentally, in a interactive environment it would be cool
> to access the documentation of variables and functions using
> properties. Say "doc" and "udoc" respectively for the full and
> one line version.
>
>
> --

> cognominal stef

Reply all
Reply to author
Forward
0 new messages