Precedence of "where" ("of", "is", "will")?

Nobody on #perl6 today could answer this one.  Is:
    Str | Int where { $_ }
the same as:
    (Str | Int) where { $_ }
or:
    Str | (Int where { $_ })
?

Followup questions, Mr. President:

What kind of operators are "where", "of", "is", and "will"?
Is there a reason that S03 doesn't list them?
What are their precedence(s)?

-- 
Chip Salzenberg            - a.k.a. -            <chip@pobox.com>
         Open Source is not an excuse to write fun code
            then leave the actual work to others.
0
chip
3/19/2005 2:36:49 AM
perl.perl6.language 6835 articles. 0 followers. Follow

4 Replies
2334 Views

Similar Articles

[PageSpeed] 43

Chip Salzenberg writes:
> Nobody on #perl6 today could answer this one.  Is:
>     Str | Int where { $_ }
> the same as:
>     (Str | Int) where { $_ }

I think it's this one.  The junctive operators naturally feel pretty
tight precedence, and named operators feel loose. 

> or:
>     Str | (Int where { $_ })
> ?
> 
> Followup questions, Mr. President:
> 
> What kind of operators are "where", "of", "is", and "will"?
> Is there a reason that S03 doesn't list them?
> What are their precedence(s)?

`will` and `is` are trait auxiliaries (see A12).  I don't know the names
of the other ones.  Maybe they're type modifiers.  Maybe they're also
trait auxiliaries.

Luke
0
luke
3/19/2005 10:24:45 AM
On Fri, Mar 18, 2005 at 09:36:49PM -0500, Chip Salzenberg wrote:
: Nobody on #perl6 today could answer this one.  Is:
:     Str | Int where { $_ }
: the same as:
:     (Str | Int) where { $_ }
: or:
:     Str | (Int where { $_ })
: ?

"where" binds looser than |, but it's a member of a select group of
operators that are considered declarational.  You couldn't replace |
with + there, for instance.

: Followup questions, Mr. President:
: 
: What kind of operators are "where", "of", "is", and "will"?

They're basically keywords that are for use only in type declarations
(where complex type names inside run-time expressions can be considered
a form of anonymous type declaration, with some proviso that anonymous
types declared similarly are considered structurally equivalent,
for some definition of "similarly").

: Is there a reason that S03 doesn't list them?

They aren't really operators in any general sense.

: What are their precedence(s)?

They might not actually have an official precedence if they're typically
parsed top-down.  We can say how they behave relative to the other
declarational keywords, but they're sort of in a different world than
the ordinary operators.  Your Str | Int above could be considered
a thunk that is forced to be evaluated at compile time.

Anyway, "is" is what we call a "trait_auxiliary" because it introduces
another identifier plus its associated argument, while "of" is what
we call a "trait_verb" because it just takes an ordinary argument.
The "is" is left associative in the sense that it always applies to
the main thing being declared to its left, so a sequence of is clauses
all refer to the same object.  On the other hand, "of" is right associative
and modifies the rightmost thing to its left.

"will" is just a variant of "is" that parses its two arguments with
the assumption that a closure is expected for the second one, but is
otherwise identical in precedence and associativity.

"returns" is an exact synonym for "of".  Both of them parameterize the
type to their left, though that type may be implicit in the cases where
the variable doesn't have an explicit "is" type.  That is,

    my @array of Int;

is really short for

    my @array is Array of Int

which is really something like

    my @array is Array[:returns(Int)]

and because of right associativity,

    my @array is Array of Array of Int

means something like:

    my @array is Array[:returns(Array[:returns(Int)])]

As for "where", it probably associates like "of" and other trait verbs,
though it means something different, associating a Selector with the
leftward type rather than a return type.

Larry
0
larry
3/19/2005 7:39:36 PM
Larry Wall wrote:
>     my @array of Int;
>=20
> is really short for
>=20
>     my @array is Array of Int;

How does 'is' relate to 'does'?  I mean is the above @array
ready for operation? Whilst

my @array does Array of Int;

still needs a compatible object to be put into @array?
Like so:

class Blubber does Array of Int {...}

@array =3D Blubber.new; # or with :=3D ?


BTW, does

my Int $value;

expand to

my $value is Ref of Int;

or the often mentioned

my $value is Scalar of Int;

and what is the difference between the two, if any?


What exactly does the 'is shape' syntax expand to?
I guess it is some parser gymnastics that somehow
puts more aguments into the Array class closure.
Which brings me to the question: how does this parameter
list look like?.

class Array[ ::ContentType, List of List $shape ] {...}


And yet another one: when is the resulting expansion of
such a class template or whatever it is performed? Or does
the implementor of the class have to revert to blessing in
the constructor?  Wouldn't this prevent static type checking
unless the compiler would call the constructor in some
hypotheticality mode to produce type information.


Regards,
--=20
TSa (Thomas Sandla=DF)

0
Thomas
3/23/2005 5:58:51 PM
On Wed, Mar 23, 2005 at 06:58:51PM +0100, Thomas Sandla´┐Ż wrote:
: Larry Wall wrote:
: >    my @array of Int;
: >
: >is really short for
: >
: >    my @array is Array of Int;
: 
: How does 'is' relate to 'does'?  I mean is the above @array
: ready for operation?

Yes, I think "is" typically implies construction of the variable's
main object.  Note that this is the trait "is" rather than the ISA
"is".  (The way it currently stands, ISA "is" is just the usual side
effect of applying a trait to a class.)

: Whilst
: 
: my @array does Array of Int;
: 
: still needs a compatible object to be put into @array?

I would think that'd be short for

    my @array is Array does Array of Int;

which is kind of redundant, so no, I don't think it stubs out @array.

: Like so:
: 
: class Blubber does Array of Int {...}
: 
: @array = Blubber.new; # or with := ?

If there were a syntax for stubbing @array, it'd have to use := I think
to initialize.

: BTW, does
: 
: my Int $value;
: 
: expand to
: 
: my $value is Ref of Int;
: 
: or the often mentioned
: 
: my $value is Scalar of Int;
: 
: and what is the difference between the two, if any?

The latter, I expect.  The former kind of implies to me that you
could only assign a reference to it, not a normal integer value.
Though there's certainly some overlap there, and they effectively
come out to the same thing in most cases, so it's possible they
might be forced to mean the same thing.  On the other hand, maybe

    my @value is Ref of Array of Int;

is the syntax you're looking for to stub out an array type without
allocating an array.

: What exactly does the 'is shape' syntax expand to?
: I guess it is some parser gymnastics that somehow
: puts more aguments into the Array class closure.

Traits are just names for code that is run at compile time to tweak
whatever they are applied to.  A trait can do anything it pleases
with the object you apply it to.  In the case of "shape" it might
even swap in a different set of methods entirely.  (Change vtable
in Parrot terms.)

: Which brings me to the question: how does this parameter
: list look like?.
: 
: class Array[ ::ContentType, List of List $shape ] {...}

I would not assume it has to come in as a parameter to the type name.
The type correspondences of arrays will have to be negotiated by the
types involved somehow, and that may or may not be done by comparing
the "long names" of types that include the parameters.  (If we don't
do it that way, then there has to be some other interface for it,
of course.)  I'd like to leave a little wiggle room for structural
correspondence of types, not just named correspondence.  This being
Perl, we need to provide a little room to dwim in, even if the user
doesn't take us up on it.

If this sounds inadequately handwavy, please allow me to wave my
hands some more till it's adequately handwavy.  :-)

: And yet another one: when is the resulting expansion of
: such a class template or whatever it is performed?

At compile time, by the trait(s) in question, and perhaps by an implicit
instantiate call of some sort after the last explicit trait is parsed.

: Or does the implementor of the class have to revert to blessing in
: the constructor?

Somebody's gotta construct the variable at some point, whether it's
with .bless or some other mechanism.

: Wouldn't this prevent static type checking
: unless the compiler would call the constructor in some
: hypotheticality mode to produce type information.

There very little that is "static" about compiling Perl, except insofar
as things like traits are guaranteed to run code at compile time.
So there's no need to run things hypothetically.  You run it really,
and then look to see if you're happy with what you ended up with.
I suspect "static" type checking in this Brave New World is less
about evaluating passive data structures for consistency and more
about asking various objects if they're happy with each other so far.

We just have to define the right interfaces for asking the right
questions at the right time.  Piece of cake.  I'll let you work on
that part.  :-)

Larry
0
larry
3/25/2005 1:49:23 AM
Reply:

Similar Artilces:

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

"Me" is better than "You"
Yes I know, strings are frozen. But let me talk about it, I really can't get through the idea of a PC talkin to me. I consider my PC as an extension of myself, not a dumb companion who addresses Me as You. Yes there are times when I get angry with Him while I work and get wrong calculations etc.., but it really is my fault, Me using wrong istructions and eventually wanting to find someone else to blame, but it's Me. And yes, I consider Thunderbird my mail program, reading my mail on my PC as Me. So I personally like to have Me in the header bar as a compact address ...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

"-" not "_"
I wrote a SQL statement in the data tab. I wrote a bunch of alaises as example ' word-type ' but when I hit the layout tab it converts the "-" to "_". So now my field name is ' word_type '. Is there any way to prevent this? CardGunner Don' use a hypen ( - ).  It isn't a valid character for column names.   See http://searchsqlserver.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid87_gci1188931,00.html   Here's an excerpt about column names: Letters as defined in the Unicode Standard 2.0 Decimal numbers from either B...

Replacing "\\" with "\"
Hi all I'm getting this value from a CheckBoxList control - a location of file, i have to remove "\\" and replace it with "\" and pass it to Query, how to do it, i tried with Replace, but coud'nt suceed. "\\\\Blaze10xp\\BLZ_SFS_07\\Sample Excel Files\\Excel Files\\report2.xls" thank's in advance - Prakash.C you tried Replace like this? string newstring = oldstring.Replace(@"\\",@"\");Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!My blog: Scenes From A Developer Memory yes i tr...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

double quote
hello there...  i tried everything of think but not working the way i wanted to be... not sure what i'm missing...i'm generating a <span> in code behind and then using in javascript.... here is what i'm doing code behind: int i=0string _keywordID = "keyword";string _name = row["visit_info_nm"].ToString().Trim(); String _getElementByID = String.Format("<span id='{0}' OnClick = \"document.getElementById('{1}').value='{2}';\">{3}</span><br>", i, _keywordID, _name, _name); here is what it generate : <span id='1' OnClick = \"document.getElementById('keyword')...

"To" and "From" missing
When I print emails, the words "To" and "From" are blank, even though the "To" name and "From name (addresser, addressee) do show up. This is not a problem for other users on my system. Suggestions In mailbox right click, view. On the message window, right click and choose print options. Make sure print header is checked. -- Barry Merchant NSC Volunteer SysOp *** no email unless requested please!! *** > In mailbox right click, view. On the message window, right click and > choose print options. Make sure prin...

replace the "." with a ","
Oi.... I need to build a small programm in ASP.NET and chose to use C# for it.Now i got everything working but there's one little problem.the first textbox is a double. I need to make it so that when someone enters a "." then it gets replaced by a ","any ideas?Ghan  string blah = "4.2.2.2";blah = blah.Replace(".", ",");Ryan Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

Regular Expression to remove "/", "\", "<", ">" and "="
Can anyone please show me the regular expression to reject a string ("<blue", "right>" etc.) which has the following expression in it: "/", "\", "<", ">" and "="  hi, It may Help u.. it is in Class file u may use this expressin in validation controls also. Regex objReg = new Regex(@"^[^,.?/\~|`;:'<>]*$", RegexOptions.Singleline); Regex objReg = new Regex(@"^[^,][^.][^?][^/][^\][^~|][^`][^;][^:][^'][[^<][^>]$", RegexOptions.IgnoreCase);Thanks &...

"JROC" / "JROK" / "JROCK" / "JROQ"
I just started a new contract and the tech lead told me that he wanted me to become familiar with something called "JROC" (among some other tools). I've been searching the web and I haven't found any dev tool called "JROC." Based on the name of the tool, it sounds like it encapsulates some javascript functionality. I have tried searching for different spellings - "JROK" / "JROCK" / "JROQ" but I haven't found any matches. Have you ever heard of a dev tool by this name?...

"SSL" "Mail" and "Code"
Does anybody know of any discussions taking place within Mozilla regarding these 3 bits in the certificate manager? Perhaps I've missed something in the discussions here. In any case, I think a new mechanism for indicating trust w/in the Mozilla apps are needed. Take for example the "StartCom Certification Authority" root. The Certificate Manager (I'm using Firefox on Windows) says it can identify web sites, email users, and code yet the cert itself says it can only be used for signing other certs (essentially, that is). At a minimum this is confusing but I have...

pulling out "a","an", "the" from beginning of strings
I need to pull out articles "a", "an", and "the" from the beginning of title strings so that they sort properly in MySQL. What is the best way to accomplish that if I have a single $scalar with the whole title in it? Thanks, Tim -- Tim McGeary tim.mcgeary@lehigh.edu --=-weUphL4mkB1WR5g+DMDc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, 2004-08-24 at 15:04, Tim McGeary wrote: > I need to pull out articles "a", "an", and "the" from the beginning of=20 >...

Web resources about - Precedence of "where" ("of", "is", "will")? - perl.perl6.language

Resources last updated: 12/15/2015 8:06:27 PM