Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

subtype declarations

5 views
Skip to first unread message

Luke Palmer

unread,
May 2, 2005, 5:04:57 AM5/2/05
to Language List
S12 says:

subtype Str_not2b of Str where /^[isnt|arent|amnot|aint]$/;

My brain parses this as:

subtype Str_not2b[Str where /.../];

Or:

subtype Str_not2b[Str] where /.../;

Neither of which really reflect how it is really parsed. It looks like
`subtype` has a special syntax. I find this to be free of special
syntax and clearer to boot:

type Str_not2b ::= Str where /^[isnt|arent|amnot|aint]$/;

Why don't we just ditch the `subtype` keyword?

Luke

Thomas Sandlaß

unread,
May 2, 2005, 9:35:29 AM5/2/05
to Language List
Luke Palmer wrote:
> S12 says:
>
> subtype Str_not2b of Str where /^[isnt|arent|amnot|aint]$/;
>
> My brain parses this as:
>
> subtype Str_not2b[Str where /.../];
>
> Or:
>
> subtype Str_not2b[Str] where /.../;

I guess my mental parsing problems stem from the fact
that it was you who told me about the equivalence of
the brackets and 'of'.


> Neither of which really reflect how it is really parsed. It looks like
> `subtype` has a special syntax.

Could you enlighten me how it is actually parsed?
I guess from the corresponding form

subtype Str Str_not2b where /^[isnt|arent|amnot|aint]$/;

that subtype is modeled after sub declarations

subtype Str_not2b returns Str where /^[isnt|arent|amnot|aint]$/;

The thing stored under Str_not2b in the lexical namespace
is actually a closure

sub Str_not2b (Str $unconstrained) returns bit {...}

which is then referenced by variables, signatures etc.


> I find this to be free of special
> syntax and clearer to boot:
>
> type Str_not2b ::= Str where /^[isnt|arent|amnot|aint]$/;
>
> Why don't we just ditch the `subtype` keyword?

Wouldn't the above work as

::Str_not2b ::= Str where /^[isnt|arent|amnot|aint]$/;

so that type is just a short-cut?
--
TSa (Thomas Sandlaß)


Steven Philip Schubiger

unread,
May 2, 2005, 9:09:20 AM5/2/05
to perl6-l...@perl.org
On 2 May, Luke Palmer wrote:

: S12 says:
:
: subtype Str_not2b of Str where /^[isnt|arent|amnot|aint]$/;
:
: My brain parses this as:
:
: subtype Str_not2b[Str where /.../];
:
: Or:
:
: subtype Str_not2b[Str] where /.../;
:
: Neither of which really reflect how it is really parsed. It looks like
: `subtype` has a special syntax. I find this to be free of special
: syntax and clearer to boot:
:
: type Str_not2b ::= Str where /^[isnt|arent|amnot|aint]$/;

Although, I'm aware, that introducing an idiom in favor of some,
occasionally perceived, ancient C programming techniques, will do my
reputation some harm among certain native programmer circles, I dare to
continue stating the inobvious.

If I compare last, given example against the previous ones, it is much
more apparent, in my opinion, that we're in the process of becoming
acquainted with the declaration of a subtype, regardless of the fact
that we set ourselves back to "common" compile-time binding syntax;
typedef is known amongst C knowledgables as a declaration of a synonym
for a type and did inevitably trigger this recognition. But, I'd rather
be cautious, to differentiate between what we had (C) and what we're
striving for (Perl).


: Why don't we just ditch the `subtype` keyword?

I've the same feeling.


: Luke

Steven

Larry Wall

unread,
May 3, 2005, 3:16:35 AM5/3/05
to Language List
On Mon, May 02, 2005 at 03:04:57AM -0600, Luke Palmer wrote:
: S12 says:
:
: subtype Str_not2b of Str where /^[isnt|arent|amnot|aint]$/;
:
: My brain parses this as:
:
: subtype Str_not2b[Str where /.../];
:
: Or:
:
: subtype Str_not2b[Str] where /.../;
:
: Neither of which really reflect how it is really parsed.

It's closer to the former, but perhaps more like

subtype Str_not2b[returns => :(Str where /.../)];

: It looks like


: `subtype` has a special syntax. I find this to be free of special
: syntax and clearer to boot:
:
: type Str_not2b ::= Str where /^[isnt|arent|amnot|aint]$/;

I don't. That "type" keyword is just a strange way to write the
"::" sigil.

: Why don't we just ditch the `subtype` keyword?

Because by similar arguments we should also disallow

sub foo ($x, $y, $z) {...}
class Dog is Mammal {...}

in favor of

&foo ::= sub ($x, $y, $z) {...}
::Dog ::= class is Mammal {...}

I'd rather have most declarative keywords out front, and reserve ::=
for bindings that require unusual calculations on the RHS. Though as
Thomas pointed out, you can still write

::Str_not2b ::= Str where /^[isnt|arent|amnot|aint]$/;

if you really want to.

Larry

0 new messages