Re: Why do users need FileHandles?

2004-07-24 Thread Jonadab the Unsightly One
JOSEPH RYAN [EMAIL PROTECTED] writes:

 Well, that's what all of the ruckus is about.  There is a strong
 leaning towards including *no* builtin modules with the core.  

Surely, at bare minimum, there must be something included in core to
allow things that are not in core to be easily installed, the
equivalent of what CPAN.pm is for Perl5 (hopefully even better, and
hopefully without dependencies on external non-Perl things like gcc).

I could live with very little else in core, but the means to install
whatever is not in core is essential; that's the thing that allows
everything else to be made optional -- because it can be installed
easily enough.

Oh, and here's me resisting the urge to suggest that use ought to
automatically install from the CPAN anything that isn't present, as a
core behavior right out of the box.

-- 
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b-()}}
split//,[EMAIL PROTECTED]/ --;$\=$ ;- ();print$/



Re: String interpolation

2004-07-24 Thread Jonadab the Unsightly One
Michele Dondi [EMAIL PROTECTED] writes:

 Well, it seems that there's still a big confusion/indecision about
 the default behaviour. But then an interesting point, and one that
 has already been raised, is that it should be somehow possible to
 customize string interpolation bu means of e.g. adverbs (fortunately
 we don't have true literal strings but rather quote-like
 operators), attributes and god know what else!

I rather like the notion of putting the adverb on the q operator and
its kin (qq, qx, ...)

print q :literal The value of $foo is  . $foo . \n;

:literal might be poorly huffman coded, and q (as opposed to qq or
whatever) might already default to not interpolating scalars, but the
above demonstrates the syntax.  One nice thing about this is it still
allows for arbitrary characters to be used to delimit the quote:

print qq :scalarcontext (There are @foo elements in [EMAIL PROTECTED]);

Again, :scalarcontext isn't the point, just an illustration of the syntax.

This syntax also would give us symetry with the match operators...

$foo =  qr :baz  !blah$!;
$bar =~ m  :quux $foo;  # I forget:  is =~ still spelled as in Perl5?

Here also, with qr you could use whatever adverbs you use with any of
its brethren quoting operators, to interpolate or not interpolate
various stuff, and then you could still use whatever pattern-match
adverbs you like with the match operator.

 Now it should be stressed that the problem is twofold here: one
 aspect is chosing the best default for some hopefully reasonable
 meaning of best

Sure, but allowing the default to be overridden with adverbs doesn't
hinder the ability to choose a nice default.

 and the other one is providing a slim syntax for the alternate
 behaviour(s); i.e. IMHO it would be unreasonable to require the
 users to type something like

   :with_method_interpolation

One would hope an adverb that useful would be shorter, sure.  Maybe
something along these lines, if we can conscion it...

$foo = qq :i($) Woo $hoo;
$bar = qq :i@ . ($boo.hoo @wibble);

Here i stands for interplate, $ for scalars, @ for arrays, . for
methods.  If this is deemed too cryptic, perhaps something in between
this and the excessive verbosity of :with_method_interplation is in
order.

It's slightly bothersome that :i would mean interplate for quoting
but case-insensitive for matching, but since case-insensitivity
doesn't seem sensible for quoting that might not matter.  I thought
about :int for interpolation, but too many people would think integer,
probably, and :itpl is just too C-like in its unpronounceability and
complete lack of obvious meaning.  (What's an i-tuple?)  :terp or
:iterp would make people think interpreter rather than
interpolate, I fear, and when we move up to :terpolate we're getting
long.  The only synonym I can think of for interpolate is evaluate,
and I'm not certain :eval would mean the right thing to everyone.

 each time they want it. But maybe certain delimiters for qq may
 already provide that... (or would that be a bad idea?)

I don't think which _delimiters_ you choose should have any impact on
how the interpolation is done (except as regards the delimiters
themselves; if you choose $ as your delimiter, you're going to have a
hard time interplating scalars, obviously).

IMO, the difference between q and qq should have to do with which
adverbs are turned on by default.

 As a related side note, is it possible to use multi-char delimiters in 
 Perl6? I mean, a la:

   qq...;

I would worry that you'd be getting  and  at the beginning and
end of your string.  IMO, there are enough characters in ASCII that
for any short quotation you ought to be able to find one character you
can use as a quote delimiter.  For longer quotations, we have
heredocs.

Speaking of which, that raises another question:  can we apply adverbs
to heredocs?

if (somecondition()) {
  $foo =  :indent(5) FOO;
 blah, blah
 blah, blah
 blah, blah
 FOO
}

Parsing concerns might constrain that to this:

if (somecondition()) {
  $foo =  :indent(5) FOO;
 blah, blah
 blah, blah
 blah, blah
FOO
}

Which is still better than the bletcherous Perl5 way:
 
if (somecondition()) {
  $foo = FOO;
blah, blah
blah, blah
blah, blah
FOO
}

I've found myself wrapping long quotations in their own subroutines
(that just contain a heredoc and return a string) at the bottom of the
file in Perl5 just to keep my indentation sane.  There ought to be
some way around this problem for POD, too.  Perhaps POD could have its
own quote operator...

sub foo {
 qp :indent(5) FOOPOD;
 Put some POD here.
 FOOPOD
  ... 
}
 
-- 
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b-()}}
split//,[EMAIL PROTECTED]/ --;$\=$ ;- ();print$/



Re: String interpolation

2004-07-24 Thread Jonadab the Unsightly One

Correct me if I'm wrong, but, by analogy with $foo.bar(), ...

 No  Yes
 --  ---
 @foo@foo[1]
 %bar%bar{a} or %bar«a»
 $foo.bar$foo.bar()
 foofoo(1)
  @foo@foo.join( )

Yes?

/me idly wonders whether map and grep and sort could be made into
methods on the array class and chained together and interplated as
such...

print @foo.map({[$_,wibble($_)]}).sort([EMAIL PROTECTED] cmp @$b[1]}).map([EMAIL 
PROTECTED]);

Ugh, that looks horrible.  Of course, one could probably define a
.schwartz() method on the array class and do the above thusly...

print @foo.schwartz({wibble($_)},{$a cmp $b});

That doesn't buy you the flexibility to throw in extra steps (like a
grep in the middle), but it sure is easier to read.  

Of course one could argue that sensible people would assign the
processed list to an array variable first and then interplate that...

-- 
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b-()}}
split//,[EMAIL PROTECTED]/ --;$\=$ ;- ();print$/



Re: String interpolation

2004-07-24 Thread Jonadab the Unsightly One
Johan Vromans [EMAIL PROTECTED] writes:

 Larry Wall [EMAIL PROTECTED] writes:

 :  my $d=a;
 :  print --$d--{my $d = b }--$d--\n;

 Yes, that is correct.

 I'm afraid things like this will keep many popular editors and IDEs
 from implementing perl6 support...

Then maybe people will switch to more capable editors.

-- 
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b-()}}
split//,[EMAIL PROTECTED]/ --;$\=$ ;- ();print$/



Re: String interpolation

2004-07-24 Thread Larry Wall
On Sat, Jul 24, 2004 at 12:08:24PM -0400, Jonadab the Unsightly One wrote:
: Johan Vromans [EMAIL PROTECTED] writes:
: 
:  Larry Wall [EMAIL PROTECTED] writes:
: 
:  :  my $d=a;
:  :  print --$d--{my $d = b }--$d--\n;
: 
:  Yes, that is correct.
: 
:  I'm afraid things like this will keep many popular editors and IDEs
:  from implementing perl6 support...
: 
: Then maybe people will switch to more capable editors.

This particular modeful behavior is easily handled by most current
editors.  You have to be able to treat the insides of strings different
from the outsides.  That being said, there are plenty of other things
in Perl 6 already that will drive editors nuts.  This just isn't one
of them.

As for IDEs, any decent IDE is going to have hooks directly into the
language's parser.

Larry


Re: Why do users need FileHandles?

2004-07-24 Thread Brent 'Dax' Royal-Gordon
Jonadab the Unsightly One wrote:
Surely, at bare minimum, there must be something included in core to
allow things that are not in core to be easily installed, the
equivalent of what CPAN.pm is for Perl5 (hopefully even better, and
I believe that's the current plan--the core will include CPAN, LWP, and 
not much else.

hopefully without dependencies on external non-Perl things like gcc).
Don't think it'll be possible for modules that have C components, 
although Parrot's Native Call Interface ought to make a lot of XS uses 
obsolete.  (With NCI, Parrot provides opcodes to load a shared library, 
then retrieve functions from it and treat them like normal Parrot 
subs--all without writing any C.  That includes converting arguments and 
return values from Parrot types to C types.)

Oh, and here's me resisting the urge to suggest that use ought to
automatically install from the CPAN anything that isn't present, as a
core behavior right out of the box.
Security nightmare.
--
Brent Dax Royal-Gordon [EMAIL PROTECTED]
Perl and Parrot hacker
Oceania has always been at war with Eastasia.


Re: Why do users need FileHandles?

2004-07-24 Thread David Storrs
On Sat, Jul 24, 2004 at 02:23:10PM -0700, Brent 'Dax' Royal-Gordon wrote:
 Jonadab the Unsightly One wrote:
 
 Oh, and here's me resisting the urge to suggest that use ought to
 automatically install from the CPAN anything that isn't present, as a
 core behavior right out of the box.
 
 Security nightmare.

Definitely.  On the other hand...I find myself wondering if we could
offer a pragma so that people can have the option if they want it.
For example:


#!/usr/bin/perl6

#use warnings;  # Note that I am NOT explicitly using these
#use strict;

{   no 'warnings'; no 'strict';   # These must be explicitly turned off...
no installation_security; # or this would throw warning  error

use SomeModule; #
use OtherModule;# 
use Foo;# If these are not installed,
use Bar;# they will be auto-installed.
use Baz;#
use Jaz;#
}

use FrobNitz;   # If this is not installed, the script fails.

script goes here

__END__


Voila, this is now a completely portable-with-zero-effort(*) script.
Anywhere that I install it, it will ensure that all of its prereqs are
available before starting...and, if they aren't, it will install them
instead of failing.  That's pretty darn cool.

And I had to make a concerted effort to enable this behavior.  Really,
if the user wants to shoot himself in the foot, who are we to
interfere?

Note that there are still plenty of issues remaining--how to handle
varying module versions springs to mind--but those are implementation
details. 


--Dks

(*) Note that here, zero-effort means assuming you have a net
connection, plus all necessary installation tools, plus the rights to
install, plus your system is configured correctly to use the
installation diretory (if not in the standard paths), etc.


Re: String interpolation

2004-07-24 Thread Larry Wall
On Sat, Jul 24, 2004 at 11:59:30AM -0400, Jonadab the Unsightly One wrote:
: 
: Correct me if I'm wrong, but, by analogy with $foo.bar(), ...
: 
:  No  Yes
:  --  ---
:  @foo@foo[1]
:  %bar%bar{a} or %bar«a»
:  $foo.bar$foo.bar()
:  foofoo(1)
:   @foo@foo.join( )
: 
: Yes?

Yes, that would presumably work.

: /me idly wonders whether map and grep and sort could be made into
: methods on the array class and chained together and interplated as
: such...
: 
: print @foo.map({[$_,wibble($_)]}).sort([EMAIL PROTECTED] cmp @$b[1]}).map([EMAIL 
PROTECTED]);
: 
: Ugh, that looks horrible.  Of course, one could probably define a
: .schwartz() method on the array class and do the above thusly...
: 
: print @foo.schwartz({wibble($_)},{$a cmp $b});
: 
: That doesn't buy you the flexibility to throw in extra steps (like a
: grep in the middle), but it sure is easier to read.  

Well, on that specific topic I'd suggest going back and looking at
the sort syntax thread we had several months ago.  What we ended up with
has ST built in, among other things.

: Of course one could argue that sensible people would assign the
: processed list to an array variable first and then interplate that...

There are any number of syntactic constructs that people can abuse.
It's actually pretty rare that I get a bee in my bonnet about one of
them and place arbitrary limits.   I do that with statement modifiers
and with required braces on blocks.

Larry


Re: String interpolation

2004-07-24 Thread Larry Wall
On Thu, Jul 22, 2004 at 11:16:09AM -0500, Dan Hursh wrote:
: Larry Wall wrote:
: No  Yes
: --  ---
: @foo@foo[1]
: %bar%bar{a} or %bar«a»
: $foo.bar$foo.bar()
: foo foo(1)
: 
: I may have missed it, but what are the contexts in these cases?  I'm 
: thinking the first two are easily scalar.  Are the second list just as 
: if they were inside curly braces, or are the scalar to match the others 
: (or just to be flexibly different)?

I tend to like the flexibly different approach.  On the other hand,
that doesn't say what to do if such a method or sub actually returns a
list in scalar context, and whether that's the same thing that would
happen inside curlies.  We could distinguish those, rather like Perl
5 distinguishes these:

print @foo,\n;
print @foo,\n;

People certainly learned to deal with that little non-orthogonality.
On the other hand, it might be viewed as gratuitously fiddly to make

print @x.sort()\n;
print [EMAIL PROTECTED];

interpolate differently.  I don't profess to have an opinion on it yet.

: In this worldview, $foo is an exception only because it doesn't naturally
: have a form that ends with some kind of bracket.
: 
: Will $x[$y] interpolate?

Certainly.  Likewise $x{$y}.  (Presuming we keep the end bracket rule.)

: Oh and if $x is a reference to an array, is 
: $x a stringified reference or dereferenced (and in which context)?

In any string context, the default will be to dereference references
to a real value.  That includes list contexts embedded within a string
context, as bare {} would supply.  The main question is when to get
fiddly about supplying spaces between the values.

: I got it in my head that since things in curlies would be in list context 
: that the others must be scalar/string context.

They're all ultimately in string context, but curlies would do it
via list context.  It would make no difference for functions that
always return scalars in list context, and little to no difference for
functions that always return lists regardless of context (depending
on how we fiddle it).

: I haven't been able to 
: find a reason for justifing that leap, but I kind of like it.  Well for 
: the moment.

Yeah, me too...this week...

Larry


Re: Why do users need FileHandles?

2004-07-24 Thread Brent 'Dax' Royal-Gordon
David Storrs wrote:
#!/usr/bin/perl6
#use warnings;  # Note that I am NOT explicitly using these
#use strict;
{   no 'warnings'; no 'strict';   # These must be explicitly turned off...
no installation_security; # or this would throw warning  error
use SomeModule; #
use OtherModule;# 
use Foo;# If these are not installed,
use Bar;# they will be auto-installed.
use Baz;#
use Jaz;#
}

use FrobNitz;   # If this is not installed, the script fails.
script goes here
__END__
This is really something you want to enable or disable per-run, IMHO (so 
e.g. the first time you run the script, you run it with perl -Minstall 
or something).  Or you could just make it part of the 'cpan' program:

brent:~$ wget www.somesite.com/somescript.cgi.gz
brent:~$ gunzip somescript.cgi.gz
brent:~$ cpan --prereqs=somescript.cgi
brent:~$ cp somescript.cgi /www/cgi-bin
brent:~$ chmod 755 /www/cgi-bin/somescript.cgi
# somescript.cgi is now ready for use
This would require 'cpan' to parse the script with a modified grammar 
that noted all the 'use's (and 'require's, I guess), then install each 
module.  Or something like that.

Hmm...maybe this could be done for Perl 5...
--
Brent Dax Royal-Gordon [EMAIL PROTECTED]
Perl and Parrot hacker
Oceania has always been at war with Eastasia.


Re: String interpolation

2004-07-24 Thread Larry Wall
On Thu, Jul 22, 2004 at 11:12:16PM +0100, Dave Mitchell wrote:
: On Wed, Jul 21, 2004 at 04:37:29PM -0700, Larry Wall wrote:
:  We allowed/required @foo to interpolate in Perl 5, and it catches a
:  certain number of people off guard regularly, including yours truly.
:  So I can argue [EMAIL PROTECTED] both ways.
: 
: Currently @foo[] is a syntax error. maybe @foo[] in Perl6 could be
: what @foo is in Perl5? And I mean a literal '[]', not
: @foo[expression-that-returns-an-empty-list]

Well, I can argue that one both ways too.  It's certainly recognizable
as some kind of undifferentiated subscript, but it has two distinct
interpretations, unfortunately.  The null list inside could either
be considered to be a zero-dimensional subscript, or a one-dimensional
subscript that happens to be a null slice.

If you take the former interpretation, it makes sense that @foo[]
means the whole array as the limiting case:

@foo[3;2;1], @foo[3;2], @foo[3], @foo[]

If you take the latter, it makes sense that @foo[] means none of
the array:

@foo[1,2,3], @foo[1,2], @foo[1], @foo[]

A code generator could come up with either of those as a limiting case
and reasonably expect either everything or nothing.  What the user
expects will probably depend also on the declared dimensionality of
the object.  (Similar considerations apply to %foo{}.)  So we have to
penalize one syntax or the other.  Either we force the user to say
something like

@foo[*]

to indicate that the first subscript is to be considered a Zen
slice (make me one with everything) or we force them to say

@foo[()]

to indicate that the first subscript is to be considered an empty
slice.  You just can't have it both ways.  Certainly there seems
to be a lot more utility in arrays with everything in them rather
than nothing, so I'm inclined to bias it in favor of @foo[] returning
the entire array, especially if we go with the end bracket rule.

Larry


Re: Why do users need FileHandles?

2004-07-24 Thread Larry Wall
On Sat, Jul 24, 2004 at 04:51:52PM -0700, Brent 'Dax' Royal-Gordon wrote:
: This would require 'cpan' to parse the script with a modified grammar 
: that noted all the 'use's (and 'require's, I guess), then install each 
: module.  Or something like that.
: 
: Hmm...maybe this could be done for Perl 5...

If the main impediment is security, you have to know what the
checksums of the modules you're looking for are, and that means you
have to know exactly what version you're looking for (or have info
on all versions).  Which implies that you might need something like
Perl 6's ability to (attempt to) use two different versions of the
same module simultaneously.

But don't let me discourage you from playing with it in Perl 5...  :-)

Larry


Re: String interpolation

2004-07-24 Thread Larry Wall
On Thu, Jul 22, 2004 at 03:33:01PM +0200, Michele Dondi wrote:
: But then an interesting point, and one that has already
: been raised, is that it should be somehow possible to customize string
: interpolation bu means of e.g. adverbs (fortunately we don't have true  
: literal strings but rather quote-like operators), attributes and god know 
: what else!

It has always been my intent to extend the rx:foo// model to qq:foo//
and the like.

Larry


Re: xx and re-running

2004-07-24 Thread Larry Wall
On Thu, Jul 22, 2004 at 02:48:59PM -0600, Luke Palmer wrote:
: JOSEPH RYAN writes:
:  When I think about your description of xxx, I 
:  summarized it in my head as Call a coderef a certain
:  number of times, and then collect the results.  
:  That's pretty much what map is, except that xxx is 
:  infix and map is prefix.
:  
:  
:  @results = { ... } xxx 100;
:  @results = map { ... } 1.. 100;
:  
:  Doesn't seem that special to me.
: 
: And adding to that the definition of a unary hyper operator:
: 
: [EMAIL PROTECTED] == map { §$_ } @list
: 
: It seems that the rand problem could be solved this way:
: 
: my @nums = rand« (100 xx 100);

The rand function may be a bad example, since it's by nature a
generator, and you should maybe have to work harder to get a single
value out of it.  We haven't really said what $fh xx 100 should do,
for instance.  I guess the real question is whether xx supplies a
list context to its left argument (and whether rand pays attention
to list context).  These might produce very different results:

@foo = (rand);
@bar = (+rand);

On the other hand, history has rand producing a scalar, so arguably we
should stick with that.

Larry