Re: Another dotty idea
At 08:38 -0400 8/4/06, John Siracusa wrote: On 4/8/06 6:29 AM, Damian Conway wrote: I'm not enamoured of the .# I must confess. Nor of the #. either. Thank goodness...I was beginning to think it was only me! For the record, I agree with both of you, and that your proposed alternatives are improvements. -- Darren Duncan
Re: Another dotty idea
On 4/8/06 6:29 AM, Damian Conway wrote: > I'm not enamoured of the .# I must confess. Nor of the #. either. Thank goodness...I was beginning to think it was only me! > Though, frankly, every one of the alternatives proposed so far is so ugly that > I seriously doubt that anyone will actually want to use them Agreed, especially... > ...when there are cleaner alternatives for aligning postfixes already > standard in the language: [...] > > foo$obj: $arg = $get_foo( $arg ); > barb $obj: $arg = $get_barb($arg ); > bazaar $obj: $arg = $get_bizarre( $arg ); > > Maybe we're trying too hard to let people have their postfix dotted space > (and eat it too). I could almost swallow #[ ... ] as a multi-line comment...almost. The others with the dot just rub me the wrong way. -John
How do you use a built-in class as a base class?
Folks, With Perl6, we have singleton methods as $me.meta.add_method(me => sub{ ... }); But is there a way to, say, add methods within lexical scope? Take URI on Perl 5. URI behaves both as an object my $uri = URI->new("http://dev.perl.org/perl6/";); print $uri->path; # "/perl6/" But it also behaves as an ordinary string. print $uri; # "http://dev.perl.org/perl6/"; In Perl5, this is done by overloading q(""). If you want anything like this, you needed overloading. But in Perl6, I assume you'd go like class URI is Str { method path(){ # } } So you don't have to resort to overloading. Now the questions are: 1. How are you going to initialize? my URI $uri .= .new("http://dev.perl.org/perl6/";); or my $uri = URI.new("http://dev.perl.org/perl6/";); or my URI $uri = "http://dev.perl.org/perl6/";; ? 2. How do the method access its internal string. Via $?SELF ? Or should I use roles instead of classes in this kind of case? What I want is make something like a "smart builtin classes" within Perl 6 semantics. You don't want to go like $uri.meta.add_method('path' => ...), right? I know how to do that in Perl 5 (possible but difficult). I know how to do that in Javascript (eazy but Str.prototype.yourmeth = function() {...} makes ALL STRINGS smart). What's the recommended way in Perl 6? Dan the Object Disoriented
Re: slurp, quine and context sensitivity
Dan Kogai wrote: ~slurp $file; Very clever. But still not good enough when it comes to autoboxing. { ~slurp }($*PROGRAM_NAME).print and even (~slurp $*PROGRAM_NAME).print works as expected but since "~slurp $file" is really ~(slurp $file), $*PROGRAM_NAME.~slurp.print does not. You want: (~$*PROGRAM_NAME.slurp).print; Or: $*PROGRAM_NAME.slurp(sep=>undef).print; The problem of ~stringify, ?boolify, and +numify is that they are infix operators so it goes the opposite direction. Oh, while I was testing all these on pugs, I came across this. ## say $*PROGRAM_NAME.slurp.elems; ## That call to .slurp is in scalar context, since the result is immediately used as an object. This says 1 but ## my @lines = $*PROGRAM_NAME.slurp; say @lines.elems; ## says 3. That .slurp is in list context. Damian
Re: slurp, quine and context sensitivity
On Apr 08, 2006, at 19:34 , Dan Kogai wrote: does not. The problem of ~stringify, ?boolify, and +numify is that they are infix operators so it goes the opposite direction. s/infix/prefix/ Sorry. Dan the Perl6 Golfer on the Bunker
Re: slurp, quine and context sensitivity
On Apr 08, 2006, at 18:45 , Damian Conway wrote: Dan Kogai wrote: With that understood, I would welcome if we have a version of slurp () which unconditionally returns a scalar. That'd be: ~slurp $file; :-) Very clever. But still not good enough when it comes to autoboxing. { ~slurp }($*PROGRAM_NAME).print and even (~slurp $*PROGRAM_NAME).print works as expected but since "~slurp $file" is really ~(slurp $file), $*PROGRAM_NAME.~slurp.print does not. The problem of ~stringify, ?boolify, and +numify is that they are infix operators so it goes the opposite direction. Oh, while I was testing all these on pugs, I came across this. ## say $*PROGRAM_NAME.slurp.elems; ## This says 1 but ## my @lines = $*PROGRAM_NAME.slurp; say @lines.elems; ## says 3. This I am confused. Dan the Perl6 Golfer on the Bunker
Re: Another dotty idea
Larry wrote: I really prefer the form where .#() looks like a no-op method call, and can provide the visual dot for a postfix extender. It also is somewhat less likely to happen by accident the #., I think. And I think the front-end shape of .# is more recognizable as different from #, while #. requires a small amount of visual lookahead, and is the same "square" shape on the front, and could easily be confused with a normal line-ending comment. I'm not enamoured of the .# I must confess. Nor of the #. either. I wonder whether we need the dot at all. Or, indeed, the full power of arbitrary delimiters after the octothorpe. What if we restricted the delimiters to the five types of balanced brackets? And then simply said that, when any comment specifier (i.e. any octothorpe) is followed immediately by an opening bracket, the comment extends to the corresponding closing bracket? Then you could have: #[ This is a comment ] #( This is a comment ) #{ This is a comment } #< This is a comment > #« This is a comment » That would also mean that # is *always* the comment introducer (and the *only* comment introducer). As for gappy dotting, that would become: $x#[ ].foo() or: $x.#< >foo() as the coder prefers. Though, frankly, every one of the alternatives proposed so far is so ugly that I seriously doubt that anyone will actually want to use them (or maybe that's the point! ;-) Especially when there are cleaner alternatives for aligning postfixes already standard in the language: @another_array[ $idx ] = $hash.{ $key }; @other_array[ $idx ] = $other_hash.{ $key }; @array[ $idx ] = $another_hash.{ $key }; foo$obj: $arg = $get_foo( $arg ); barb $obj: $arg = $get_barb($arg ); bazaar $obj: $arg = $get_bizarre( $arg ); Maybe we're trying too hard to let people have their postfix dotted space (and eat it too). Damian
Re: [svn:perl6-synopsis] r8609 - doc/trunk/design/syn
Larry Wall schreef: > before anyone else points it out to me > I think the long-dot > rule is built into the parser rather than falling out of the > longest-token rule. I think so too, but why then cling to the dot? s:p5/[\][#][^\]*[#][\]// (does not match \#\ ) The backslash is not (or not always) the proper character for this. s:p5/([.^\])[#].*?[#]\1/$1/ thing.# #.xFF(1,2,3) thing.\# #\xFF (0 .. ^# #^42) It's a prophet. :) -- Groet, Ruud
Re: slurp, quine and context sensitivity
Dan Kogai wrote: With that understood, I would welcome if we have a version of slurp() which unconditionally returns a scalar. That'd be: ~slurp $file; :-) Damian
slurp, quine and context sensitivity
Folks, This is a poetic quine (or quine-maker) in perl5. open myself, $0 and print ; The same thing in perl6 would be: my $self = open $*PROGRAM_NAME; for =$self { say } or my $self = open $*PROGRAM_NAME; say for =$self; or my $self = slurp $*PROGRAM_NAME; print $self; or even $*PROGRAM_NAME.slurp.map:{ print }; The last example must not be $*PROGRAM_NAME.slurp.print; You can check it out by running the code below; ## $*PROGRAM_NAME.slurp.print ## Will print: ##$*PROGRAM_NAME.slurp.print## This is because print() (and say()) expects list context and slurp() passes an array of chomped strings. When it comes to autoboxing, the context-sensitivity of builtins may bite you like this. With that understood, I would welcome if we have a version of slurp() which unconditionally returns a scalar. Say swallow()? Of course it is as easy to implement as the following; sub swallow($file){ my $content = slurp $file; return $content }; But like say(), I would love to have something like that as a builtin. Or am I getting too much ruby recently? Dan the Perl6 Addict