RE: Perl6 Operator List, Take 2
On Sun, 27 Oct 2002 [EMAIL PROTECTED] wrote: : Damian Conway wrote: : :or : : : :given ( /home/temp/, $f ) : : - ( str $x , int $n ) { : : $x ~ [one, two, ... , hundreed][$n] : : }; : : : :it seems that the last does not work because given take only one argument. : : : : That's right. But this does: : : : : for /home/temp/, $f : : - str $x , int $n { : : $x ~ [one, two, ... , hundreed][$n] : : } : : : : Damian : : except that it will not tolerate list in block signature : : for /home/temp/, @f : - str $x , int @y { :... :} : : am I right ? for is special in that it provides a list context to its, er, list, while looking for scalars in the signature to map it against. So the problem with that example is not the signature, which nicely specifies a scalar reference to an array, but that the list context would naturally flatten @f. You'd have to pass it as \@f, unless you actually mean @f to contain a list mapping to: (Array of int, (str, Array of int) is repeated). : Now it will be : : given [/home/temp/, @f] : - [ str $x , int @y ]{ :... :} : : ? Though that doesn't iterate like for can: for /home/temp/, \@f, /home/notsotemp, \@g, - str $x , int @y { ... } Larry
RE: Perl6 Operator List, Take 2
Damian Conway wrote: :or : :given ( /home/temp/, $f ) : - ( str $x , int $n ) { : $x ~ [one, two, ... , hundreed][$n] : }; : :it seems that the last does not work because given take only one argument. : : That's right. But this does: : : for /home/temp/, $f : - str $x , int $n { : $x ~ [one, two, ... , hundreed][$n] : } : : Damian except that it will not tolerate list in block signature for /home/temp/, f - str $x , int y { ... } am I right ? Now it will be given [/home/temp/, f] - [ str $x , int y ]{ ... } ? arcadi
Re: Perl6 Operator List, Take 2
[EMAIL PROTECTED] (Michael Lazzaro) writes: | ! - superpositional all any one (none?) I don't understand this, on several levels. The lowest level on which I don't understand it is that testing whether an array is full of threes: @array 3 makes sense, but how do you test if all of its elements are more than six? @array { $^a 6 } # ? If you can't do the latter with the same operator as the former, why have the operator at all? Suddenly, @array.all?({ |$a| $a 6 }) seems a lot more appealing. :) -- 10. The Earth quakes and the heavens rattle; the beasts of nature flock together and the nations of men flock apart; volcanoes usher up heat while elsewhere water becomes ice and melts; and then on other days it just rains. - Prin. Dis.
Re: Perl6 Operator List, Take 2
On Fri, Oct 25, 2002 at 04:10:31PM -0700, Michael Lazzaro wrote: Here's try #2. Things that are not true operators or have other caveats are marked, where known. LMKA. methods and listops, uncategorized: my our map grep sqrtlogsin cos tan lc lcfirstuc ucfirst int ordoct hex (bin?) Why do sqrtlogsin cos tan int ordoct hex (bin?) count as methods, when perl5 has them as numeric functions? And based on perlfunc.pod, I think the uniops abs, log and exp are missing, and the listop atan2. (And is perl6 going to have other more unusual transcendental maths functions such as acos, asin, cosh, sinh, cosec, erf as builtin keywords?) Nicholas Clark -- INTERCAL better than perl? http://www.perl.org/advocacy/spoofathon/
Re: Perl6 Operator List, Take 2
Simon Cozens wrote: I don't understand this, on several levels. The lowest level on which I don't understand it is that testing whether an array is full of threes: array 3 Err...that's not what that does. What you wrote creates a scalar value that superimposes the scalar values C \array and C 3 . To test if an array is full of 3's you'd write: all(array) == 3 makes sense, but how do you test if all of its elements are more than six? array { $^a 6 } # ? No. What you wrote is the superposition of C \array and (effectively) C sub($a){$a6} . To test if an array is full of greater-than-6's you'd write: all(array) 6 If you can't do the latter with the same operator as the former, why have the operator at all? The operator is for composing superpositions from separate elements. Such as: $x $y $z == 3 # all three variables equal 3 $x $y $z 6 # all three variables greater than 6 $x $y | $z 6 # either $x and $y greater than 6, or $z greater than 6 Suddenly, array.all?({ |$a| $a 6 }) seems a lot more appealing. :) More appealing than: all(array) 6 ??? No wonder you put a smiley there. ;-) Damian
Re: Perl6 Operator List, Take 2
Damian Conway wrote: ~~ !~ - smartmatch and/or perl5 '=~' (?) like unlike- (tentative names) Do we *really* need the alphabetic synonyms here? Me no like! I agree with Damian. Clike wouldn't've been a bad name for the Perl 5 C=~ operator; it's at least similar to SQL's CLIKE. However the smart matching is going to do many things in Perl 6, representing tests such as 'is contained in' or 'contains'. I don't think that there's an English word which is flexible enough to represent all the kinds of matching this will do. As such I think it's less confusing to have a special symbol that we all remember as doing 'magic matching' than it would be to have an English word which sometimes has its ordinary English meaning and sometimes has the meaning of a different English word or phrase. Smylers
RE: Perl6 Operator List, Take 2
References: [EMAIL PROTECTED] Questions : * are stream separators ; | in the for loop - operators in the usual sence ( like , ) or they are pure grammar ? * is prototype of the subrotine more regexp then expression ? to what extent it is a regexp ? where it is stored , can we inspect it or even change . * do we have have an axcess to the signature of the subroutine if we have been passed only its reference . that is , for exemple , can process( @x , step ) guess how many arguments step expects ? * how one can write function analogous to for loop that will be able to handle multiple streams ? * how one can call subroutine in place sub (str $x , int $n ) { $x ~ [one, two, ... , hundreed][$n] } . (/home/temp/, $f ) ; or given ( /home/temp/, $f ) - ( str $x , int $n ) { $x ~ [one, two, ... , hundreed][$n] }; it seems that the last does not work because given take only one argument. thanks , arcadi
RE: Perl6 Operator List, Take 2
On Sat, 26 Oct 2002, fearcadi wrote: : * are stream separators ; | in the for loop - operators : in the usual sence ( like , ) or they are pure grammar ? If ;, probably operator, though behaving a bit differently on the left of - than on the right, since the right is essentially a signature. Ordinarily a ; in a signature would be taken to mean optional arguments, but for would hide that meaning. If we used and | they'd have to be pure grammar, since they're not really doing superpositions. : * is prototype of the subrotine more regexp then expression ? : to what extent it is a regexp ? where it is stored , can we inspect it : or even change . I have been resisting the notion that the signature can be generalized into a regex. I'd rather have it separate, so that parsing is a separate concern from the list of input arguments. In my tome last night I was actually putting regex-ese into the name rather than the signature, like this: sub term:qaquotestr (str $quotestr) { ... } which would presumably define a qa// term. But maybe that's putting too much load onto the term: notation. Maybe it should be sub term:qa (str $quotestr) is parsed /qaquotestr/ { ... } Or maybe it should be something else entirely. In any event, all the information should be stored somewhere where it can be inspected, almost certainly in ordinary properties. In fact, my int sub foo (int $x) { ... } is really syntactic sugar for something like: my foo is retsig (int) is sig (int $x) is body { ... } which may in turn be syntactic sugar for: my foo ::= new Code(retsig = (int), sig = (int $x), body = { ... }); : * do we have have an axcess to the signature of the : subroutine if we have been passed only its reference . : that is , for exemple , can : : process( x , step ) : : guess how many arguments step expects ? I don't see why not, if a sub ref is pointing at its descriptor as it does in Perl 5. : * how one can write function analogous to for loop that will be able to : handle multiple streams ? That depends on whether ; is an operator or pure grammar. :-) In either case, the body of the function is going to get in the separate streams as an array of lists. The signature will also have to come in as a sequence-separated list, so that the routine can match up the streams. I expect that for might have an immediate component (read macro) that analyzes the number of streams at compile time so as to call an efficient looping algorithm for the common cases. : * how one can call subroutine in place : sub (str $x , int $n ) { : : $x ~ [one, two, ... , hundreed][$n] : : } . (/home/temp/, $f ) ; : : or : : given ( /home/temp/, $f ) : - ( str $x , int $n ) { : $x ~ [one, two, ... , hundreed][$n] : }; : : : it seems that the last does not work because given take only one argument. But that argument can certainly be a list, and it seems like it would not be too terribly difficult to make it do the signature binding just the same as if they were function arguments. In fact, I'm thinking about a Haskellish way to take any argument that's a list reference and map it against a sub-signature. Something like: sub foo ([$head, *tail], *other) { ... } foo( [1,2,3], 4,5,6 ); with the result that the parameters are bound like this: $head := 1 tail := 2,3 other := 4,5,6 Or maybe the declaration of a sub-signature just uses parens like the outer ones: sub foo (($head, *tail), *otherargs) { ... } That's less distinctive but more consistent. On the other hand, there are perhaps reasons to distinguish a sub-signature that parses multiple args from a sub-signature that parses a single list arg. In that frame of mind, your latter case might just work right out of the box. The given supplies a scalar context to its left argument, so the (/home/tmp/, $f) is taken to mean [/home/tmp/,$f]. And that is a valid list to feed to the sub-signature on the right. At worst, you might have to use [] on the right instead of (). If so, it'd probably be better to use it on both sides: given [ /home/temp/, $f ] - [ str $x , int $n ] { ... } Note that the topic in the given is an array ref in this case, not the the first element of the list. Larry
Re: Perl6 Operator List, Take 2
[EMAIL PROTECTED] (Damian Conway) writes: Err...that's not what that does. What you wrote creates a scalar value that superimposes the scalar values C \@array and C 3 . To test if an array is full of 3's you'd write: all(@array) == 3 Ah, I see. So (x y) is equivalent to all(x,y) ? Suddenly, @array.all?({ |$a| $a 6 }) seems a lot more appealing. :) More appealing than: all(@array) 6 Yes. But then, if I want Ruby, I know perfectly well where to find it. -- The Blit is a nice terminal, but it runs emacs.
Re: Perl6 Operator List, Take 2
fearcadi wrote: * do we have have an axcess to the signature of the subroutine if we have been passed only its reference . that is , for exemple , can process( x , step ) guess how many arguments step expects ? I'd expect that Code objects would have a Csignature or Csig method: subname.sig() $subref.sig() * how one can call subroutine in place sub (str $x , int $n ) { $x ~ [one, two, ... , hundreed][$n] } . (/home/temp/, $f ) ; Yes. Or, if you're not gung-ho on explicit typing: { $^x ~ [one, two, ... , hundreed][$^n] }.(/home/temp/,$f) or given ( /home/temp/, $f ) - ( str $x , int $n ) { $x ~ [one, two, ... , hundreed][$n] }; it seems that the last does not work because given take only one argument. That's right. But this does: for /home/temp/, $f - str $x , int $n { $x ~ [one, two, ... , hundreed][$n] } Damian
Perl6 Operator List, Take 2
Here's try #2. Things that are not true operators or have other caveats are marked, where known. LMKA. unary (prefix) operators: \ - reference to * - list flattening ? - force to bool context ! - force to bool context, negate not - force to bool context, negate + - force to numeric context - - force to numeric context, negate ~ - force to string context . - method call on current topic ++ - preincrement -- - predecrement unary (postfix) operators: ++ - postincrement -- - postdecrement other postfix operators: () - [when operator is expected] [] - array access {} - hash access hyperoperators: ^ - as prefix to any unary/binary operator, vectorizes the operator binary operators: + -*/%** xxx ~ += -= *= /= %= **= x= xx= ~= = = == != = lt gt le ge eq ne cmp ||!!//- boolean operations = ||= !!= //= and orxor err ..|.! - bitwise operations .= .|= .!= = = - (or is that ., ., etc?) | ! - superpositional all any one (none?) ~~ !~ - smartmatch and/or perl5 '=~' (?) like unlike- (tentative names) = - pair creator , - list creator ; - lesser comma, list-of-lists creator : - adverbial . - method call .. - range ... - (maybe range exclusive of endpoint, or maybe ..Inf) = - assignment := - binding ::= - binding, but more so trinary operators: ?? :: parens, misc, and quotelike operators: () [] - [when term is expected] {} - [when term is expected] m// - shorthand for something else s/// - shorthand for something else tr///- shorthand for something else '...' ... `...` /.../ q qq qx qr qw (heredocs) - [exact format unknown] named unary (prefix) operators, terms, and other assorted hangers-on, identified when possible: -X - [op] filetest operators temp- [op] let - [op] ref - [op] defined - [op] undef - [op] undef - [term] exists - [op] delete - [op] ${ }- [deref] dereference scalarref { }- [deref] dereference arrayref %{ }- [deref] dereference hashref { }- [deref] dereference coderef ... - [term] yada**3 Inf - [term] NaN - [term] is - [declar] var properties but - [op?]val properties - - [declar] like 'sub' hash- [declar] force hash context methods and listops, uncategorized: my our map grep sqrtlogsin cos tan lc lcfirstuc ucfirst int ordoct hex (bin?) MikeL
Re: Perl6 Operator List, Take 2
Excellent (and valuble) work Michael. Thank-you. My turn for a few comments: | ! - superpositional all any one (none?) Although there certainly are good uses for a Cnone superpositional: push list, $newval if $newval eq none(list); print In range\n if 1 none(values) 10; they can always be achieved with Call instead: push list, $newval if $newval ne all(list); print In range\n if 1 all(values) 10; Then there's the problem of finding a suitable infix operator. Overall, I think adding a Cnone might be multiplying entities unnecessarily. ~~ !~ - smartmatch and/or perl5 '=~' (?) like unlike- (tentative names) Do we *really* need the alphabetic synonyms here? Me no like! ; - lesser comma, list-of-lists creator Actually, I'd describe this as greater comma. Sure, it has lower precedence, but that means its scope of effect is greater. Maybe we need another name entirely for it. Sequence separator perhaps? ... - (maybe range exclusive of endpoint, or maybe ..Inf) I'd much prefer the latter. But note that that semantics changes it from an binary to a postfix unary operator. trinary operators: Nit pick: s/s// '...' ... `...` /.../ q qq qx qr qw s/qr/rx/ but - [op?]val properties Yes, it's an operator. Damian