Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
enhanced open-funktion
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 28 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Unknown Sender  
View profile  
 More options Jul 13 2004, 5:06 am
Newsgroups: perl.perl6.language
From: bo...@nntp.perl.org (Unknown Sender)
Date: Tue, 13 July 2004 02:06:38 -0700
Local: Tues, Jul 13 2004 5:06 am
Subject: enhanced open-funktion

   Hello,

 I have a wish for Perl 6. I would like if the open-funktion
 opens only a file if it doesn't exist.
 Of course, I can first test if the file exist.

  if (-e $filename)
  { print "file already exists!"; }
  else
  { open (FH, ">$filename") }

 My suggestion is to have a character for the open-mode-character that
 indicate that the file should not already exist.

 For example:

  open (FH, "?>$filename") || die "can't open $filename: $!";  

   Gerd


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Jul 13 2004, 9:24 am
Newsgroups: perl.perl6.language
From: l...@luqui.org (Luke Palmer)
Date: Tue, 13 Jul 2004 07:24:55 -0600
Local: Tues, Jul 13 2004 9:24 am
Subject: Re: enhanced open-funktion

perl6-language-return-17800-fibonaci=babylonia.flatirons....@perl.org writes:
>    Hello,

>  I have a wish for Perl 6. I would like if the open-funktion
>  opens only a file if it doesn't exist.
>  Of course, I can first test if the file exist.

>   if (-e $filename)
>   { print "file already exists!"; }
>   else
>   { open (FH, ">$filename") }

>  My suggestion is to have a character for the open-mode-character that
>  indicate that the file should not already exist.

Like O_EXCL, yeah, that'd be nice.

But in Perl 6, you don't have to specify things like that through the
mode string: you can specify them through named parameters:

    my $fh = open ">$filename" :excl;

Luke


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Dondi  
View profile  
 More options Jul 13 2004, 9:41 am
Newsgroups: perl.perl6.language
From: bla...@pcteor1.mi.infn.it (Michele Dondi)
Date: Tue, 13 Jul 2004 15:41:54 +0200 (CEST)
Local: Tues, Jul 13 2004 9:41 am
Subject: Re: enhanced open-funktion
On Tue, 13 Jul 2004 perl6-language-return-17800-blazar=pcteor1.mi.infn...@perl.org wrote:

>  I have a wish for Perl 6. I would like if the open-funktion
>  opens only a file if it doesn't exist.
>  Of course, I can first test if the file exist.

I rather have a much "bigger" wish for an open-like operator that to be
fair I would like to see *also* in Perl5: nothing that one can do in well
more than one way in any case (also including creating a module that will
do exactly what I write below...), but that indeed would come handy
occasionally.

I'm thinking of an operator that returns a "magical" FH working like the
ARGV one (with authomatic error handling etc. - obviously under Perl6
the beahviour could be tunable by means of modifiers, etc.), e.g.

  openmany my $fh, [list];
  while (<$fh>) {
    # ...
  }

Michele
--

+++ wrote:
> Idiot.

top-poster
- Robin Chapman in sci.math,
  "Re: This Week's Finds in Mathematical Physics (Week 204)"

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Dondi  
View profile  
 More options Jul 13 2004, 9:49 am
Newsgroups: perl.perl6.language
From: bla...@pcteor1.mi.infn.it (Michele Dondi)
Date: Tue, 13 Jul 2004 15:49:44 +0200 (CEST)
Local: Tues, Jul 13 2004 9:49 am
Subject: Re: enhanced open-funktion

On Tue, 13 Jul 2004, Michele Dondi wrote:
> I rather have a much "bigger" wish for an open-like operator that to be

                                                      ^^^^^^^^

Of course that should be "function".

> I'm thinking of an operator that returns a "magical" FH working like the

                                   ^^^^^^^
[snip]

>   openmany my $fh, [list];

And it should assign to an undefined scalar variable, rather than
returning the filehandle, for consistency with open().

Sorry,
Michele
--
comunque non ha le alette rosse.....e' metallo metallizzato colore
metallo....
- "Franz" su it.hobby.modellismo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Scott Duff  
View profile  
 More options Jul 13 2004, 10:03 am
Newsgroups: perl.perl6.language
From: d...@pobox.com (Jonathan Scott Duff)
Date: Tue, 13 Jul 2004 09:03:36 -0500
Local: Tues, Jul 13 2004 10:03 am
Subject: Re: enhanced open-funktion

From your description, it sounds like this is what you want:

{
   local @ARGV = qw(foo bar baz and some other files);
   while (<>) {
      # ...   ARGV and friends are at your disposal
   }

}

I suppose the perl6 equivalent would be:

{
   temp $*ARGS = <<foo bar baz and some other files>>;
   while (<$ARGS>) {
      # ...
   }

}

Not much different is it?

-Scott
--
Jonathan Scott Duff
d...@pobox.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Dondi  
View profile  
 More options Jul 13 2004, 11:01 am
Newsgroups: perl.perl6.language
From: bla...@pcteor1.mi.infn.it (Michele Dondi)
Date: Tue, 13 Jul 2004 17:01:15 +0200 (CEST)
Local: Tues, Jul 13 2004 11:01 am
Subject: Re: enhanced open-funktion

On Tue, 13 Jul 2004, Jonathan Scott Duff wrote:
> > I rather have a much "bigger" wish for an open-like operator that to be
> > fair I would like to see *also* in Perl5: nothing that one can do in well
> > more than one way in any case (also including creating a module that will

    ^^^^^^^^^^^^^^^^^
    ^^^^^^^^^^^^^^^^^

> > do exactly what I write below...), but that indeed would come handy
> > occasionally.

    ^^^^^^^^^^^^
    ^^^^^^^^^^^^

> From your description, it sounds like this is what you want:

> {
>    local @ARGV = qw(foo bar baz and some other files);
>    while (<>) {
>       # ...   ARGV and friends are at your disposal
>    }
> }

Yes, in fact this is One Way To Do It(TM), and one that indeed I have
used, when I felt I needed it.

However, there are *admittedly* rare cases in which it plainly won't do:

  while (<$fh>) { # $fh just as magic as ARGV
     my $l=<>;
     # ...
  }

And once one has such a function, then the default *ARGV beahviour may be
based upon it. Also, as I already said, in Perl6 users could be allowed
further degrees of customizability.

Michele
--

>> try sleeping on it, that usually works.
> I think you're right. Usually it works every time. ;-)

I don't know about that.
I tried sleeping on a big big problem and we're now divorsed.
- "Tralfaz" on sci.math, "Re: About a big big problem" (edited)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Jul 13 2004, 12:23 pm
Newsgroups: perl.perl6.language
From: l...@luqui.org (Luke Palmer)
Date: Tue, 13 Jul 2004 10:23:45 -0600
Local: Tues, Jul 13 2004 12:23 pm
Subject: Re: enhanced open-funktion

Michele Dondi writes:
> On Tue, 13 Jul 2004, Michele Dondi wrote:

> > I rather have a much "bigger" wish for an open-like operator that to be
>                                                       ^^^^^^^^

> Of course that should be "function".

> > I'm thinking of an operator that returns a "magical" FH working like the
>                                    ^^^^^^^
> [snip]
> >   openmany my $fh, [list];

> And it should assign to an undefined scalar variable, rather than
> returning the filehandle, for consistency with open().

How very convenient, because in Perl 6, open *does* return the file
handle.  Valid Perl 6 code ahead:

    my $fh = open 'foo.bar';
    for <$fh> {              # note, not while
        # do stuff
    }

Luke


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Wall  
View profile  
 More options Jul 13 2004, 1:19 pm
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Tue, 13 Jul 2004 10:19:16 -0700
Local: Tues, Jul 13 2004 1:19 pm
Subject: Re: enhanced open-funktion
On Tue, Jul 13, 2004 at 07:24:55AM -0600, Luke Palmer wrote:

: But in Perl 6, you don't have to specify things like that through the
: mode string: you can specify them through named parameters:
:
:     my $fh = open ">$filename" :excl;

While that probably works, I think better style would be to use a comma:

    my $fh = open ">$filename", :excl;

That explicitly passes :excl to open as a term in a list rather
than relying on the magical properties of :foo to find the preceding
operator adverbially when used where an operator is expected.  We may
have to tighten up the definition of operator :foo a bit, since it's
not always going to be clear which preceding operator is intended.
Even quotes are operators if you squint. Arguably, someone could look at

    my $fh = open ">$filename" :excl;

and legitimately wonder which predicate the :excl attaches to:

    my $fh = open (circumfix:""('>$filename', :excl));     # apply to quote
    my $fh = open(">$filename", :excl);                    # apply to open
    infix:=(my $fh, open(">$filename"), :excl);            # apply to assignment

I see several directions we could go to clarify this, and I don't
entirely like any of them.  One could look at the set of available
signatures (at either compile time or run time) and see who wants
that particular adverb.  But the early binding solutions tend to
bind too soon, and the late binding solutions tend to bind too late.
(The latter is much closer to how humans treat adverbs, though,
since humans are essentially MD creatures with an overlay of various
pre-compiled heuristics.)

Operator adverbs are, in essence, postfix operators with weird
precedence.  We're going to have to be very explicit about what we
mean by "weird" here.  Unfortunately, this morning I don't feel
very explicit.

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Austin Hastings  
View profile  
 More options Jul 13 2004, 1:41 pm
Newsgroups: perl.perl6.language
From: austin_hasti...@yahoo.com (Austin Hastings)
Date: Tue, 13 Jul 2004 10:41:32 -0700 (PDT)
Local: Tues, Jul 13 2004 1:41 pm
Subject: Re: enhanced open-funktion
--- Larry Wall <la...@wall.org> wrote:

> While that probably works, I think better style would be to use a
> comma:

>     my $fh = open ">$filename", :excl;

> That explicitly passes :excl to open as a term in a list rather
> than relying on the magical properties of :foo to find the preceding
> operator adverbially when used where an operator is expected.  

Hmm. If I must use the comma, I think I'd prefer a constant in this
scenario:

  my $fh = open ">$filename", open::exclusive;

Is it reasonable to use package:: as a prefix to a block to change the
default namespace:

  { package open; exclusive + rw; }

becomes

  open::{exclusive + rw}

which then lets me say:

  my $fh = open ">$filename", open::{exclusive + rw};

=Austin

=Austin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Wall  
View profile  
 More options Jul 13 2004, 2:36 pm
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Tue, 13 Jul 2004 11:36:56 -0700
Local: Tues, Jul 13 2004 2:36 pm
Subject: Re: enhanced open-funktion
On Tue, Jul 13, 2004 at 10:41:32AM -0700, Austin Hastings wrote:

: --- Larry Wall <la...@wall.org> wrote:
: > While that probably works, I think better style would be to use a
: > comma:
: >
: >     my $fh = open ">$filename", :excl;
: >
: > That explicitly passes :excl to open as a term in a list rather
: > than relying on the magical properties of :foo to find the preceding
: > operator adverbially when used where an operator is expected.  
:
: Hmm. If I must use the comma, I think I'd prefer a constant in this
: scenario:
:
:   my $fh = open ">$filename", open::exclusive;

The problem with constants is that they're constant.  Sometimes you
don't want them to be:

    my $fh = open ">$filename", :encoding($myencoding);

: Is it reasonable to use package:: as a prefix to a block to change the
: default namespace:
:
:   { package open; exclusive + rw; }
:
: becomes
:
:   open::{exclusive + rw}

Except that syntax already means something else (lookup of a symbol
in the "open::" stash).

: which then lets me say:
:
:   my $fh = open ">$filename", open::{exclusive + rw};

If you want to call a function that will artificially multiplex several
arguments into a single argument, go ahead and call a function.
Functions are allowed to be package qualified, and they're allowed
to transmogrify random strings into package identifiers in whatever
package they like.  I don't think parameter names themselves need
to be package qualified though.  And I do think that something like
:excl is a boolean argument, not an object.  Explicitly making it
into an object (even so simple an object as a bit) seems to me like
a misfeature borrowed from C.

I can see how you're trying to use the identifier system to force
compile time checking of symbol names here, but that approach is going
to be of limited use in a language with MD.  Most parameter names will
end up being checked at runtime, and will end up throwing an exception
if no function with an appropriate signature can be found.  As I say,
you can always force checking with a function or macro of your own choosing:

    my $fh = open ">", $filename, *open::mode(:exclusive :rw);

But I think most people will prefer just to say

    my $fh = open ">", $filename, :exclusive :rw;

and take their lumps at run time.

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juerd  
View profile  
 More options Jul 13 2004, 3:25 pm
Newsgroups: perl.perl6.language
From: ju...@convolution.nl (Juerd)
Date: Tue, 13 Jul 2004 21:25:52 +0200
Local: Tues, Jul 13 2004 3:25 pm
Subject: Re: enhanced open-funktion
Luke Palmer skribis 2004-07-13  7:24 (-0600):

> But in Perl 6, you don't have to specify things like that through the
> mode string: you can specify them through named parameters:
>     my $fh = open ">$filename" :excl;

I was hoping we could finally get rid of mode characters, and especially
combined mode and filename in one argument.

Ever since I read about the new :pairs, I thought that would imply :rw
instead of >.

Juerd


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Wall  
View profile  
 More options Jul 13 2004, 5:04 pm
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Tue, 13 Jul 2004 14:04:28 -0700
Local: Tues, Jul 13 2004 5:04 pm
Subject: Re: enhanced open-funktion
On Tue, Jul 13, 2004 at 09:25:52PM +0200, Juerd wrote:

: Luke Palmer skribis 2004-07-13  7:24 (-0600):
: > But in Perl 6, you don't have to specify things like that through the
: > mode string: you can specify them through named parameters:
: >     my $fh = open ">$filename" :excl;
:
: I was hoping we could finally get rid of mode characters, and especially
: combined mode and filename in one argument.

The combined form is definitely problematic in various ways, and we haven't
really redesigned open yet, since we haven't got to A29 yet.  :-)

We could mandate the two argument form.  Or we could decide that "open"
is one of those overly general concepts, and separate things by name:

     my $fh = open $filename :excl;
     my $fh = append $filename :excl;
     my $fh = creat $filename :excl;

...er, I mean,

     my $fh = create $filename :excl;

Of course, append and create might just be shorthand for a normal open
with a :create or :append arguments, I suppose.  Similar considerations
apply for piped commands, though what the appropriate words might be,
I don't know offhand.

Another interesting question is how well those things read in code like this:

    @lines = <open $infile>;
    print (append $outfile): @lines;

Or equivalently:

    <open $infile> ==>
    print (append $outfile):

But that might be a little too concise for good error messages.  And they
might lead people to write things like

    while <open $file> {...}

which wouldn't necessarily work.  At first blush, I'd expect that
to reopen $file every time through the loop, which is probably not
what the user expects.  Possibly <...> in scalar context is smart
enough to cache its iterator, but then you start getting into the
"return false once" syndrome that confuses people.  The inside of
<...> isn't really a closure.  So maybe <...> is smart about closures:

    while <{open $file}> {...}

and only calls its closure after its previous iterator is exhausted.
On the other hand, iterators tend to *look* like closures anyway,
so may that'll be hard to distinguish in the absence of a declared
return type.

But I digress...

: Ever since I read about the new :pairs, I thought that would imply :rw
: instead of >.

But :rw is more or less orthogonal to < and > in UnixThink.  The fact
that you want to both read and write a file says nothing about whether
you initially want to use, clobber, or append to an existing file.

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juerd  
View profile  
 More options Jul 13 2004, 5:43 pm
Newsgroups: perl.perl6.language
From: ju...@convolution.nl (Juerd)
Date: Tue, 13 Jul 2004 23:43:32 +0200
Local: Tues, Jul 13 2004 5:43 pm
Subject: Re: enhanced open-funktion
Larry Wall skribis 2004-07-13 14:04 (-0700):

> The combined form is definitely problematic in various ways, and we haven't
> really redesigned open yet, since we haven't got to A29 yet.  :-)

Well, open being much like IO::All::io would really make me happy.

That is:

    my $fh = open 'foo.txt';
    $fh.print 'hello!';

Should be possible, as well as:

    my $fh = open 'foo.txt';
    print $fh.readline;

Modifiers could be used to force something into a separate mode. rw and
ro are used elsewhere in Perl 6 already, but obviously r without w would
also be handy.

    my $fh = open 'foo.txt', :ro;
    $fh.print 'hello!';  # Not possible

Of course, those who want the mode first can use

    my $fh = open :ro, 'foo.txt';

Which isn't too different from

    open my $fh, '<', 'foo.txt';

Or perhaps, for open an exception should be made, and r should be used
instead of ro.

>      my $fh = open $filename :excl;
>      my $fh = append $filename :excl;
>      my $fh = creat $filename :excl;
> ...er, I mean,
>      my $fh = create $filename :excl;

That I would very much dislike. Let's not introduce keywords when the
same thing can be done by modifiers, unless something is used EXTREMELY
often (my mind has now accepted "say", but only because print "...\n" is
extremely common).

> Of course, append and create might just be shorthand for a normal open
> with a :create or :append arguments, I suppose.

I hope those keywords can be introduced with a pragma. "use
shorthands;". That pragma then does need a single letter command line
switch, because it would be very useful for one-liners.

>     @lines = <open $infile>;
>     print (append $outfile): @lines;
> Or equivalently:
>     <open $infile> ==>
>     print (append $outfile):

I'd prefer

    (open $outfile :append).print slurp $infile;

Or, for the shorthand junkies :)

    (append $outfile).print slurp $infile;

> But that might be a little too concise for good error messages.

Assuming $infile ne $outfile and that the default error message (which
perhaps is only there if enabled with a Fatal.pm-like pragma) includes
the filename (it should, imo), two things being on one line shouldn't be
a problem.

> And they might lead people to write things like
>     while <open $file> {...}

I've never seen

    while (IO::File->new($file)->readline) { ... }

either.

Of course, while-open is a good candidate for a warning.

I don't think this "problem" needs a solution. I hope or-cache will
still be an often used idiom in Perl 6:

    while <my $fh //= open $file> { ... }

Although I'm not sure what exactly "my" would mean here.

> But :rw is more or less orthogonal to < and > in UnixThink.

There's one thing feel I must say about < and >: They're not different
enough, visually. This works well on the command line and for
delimiters, but

    open '<', $foo;
    open '>', $foo;

is much harder to read than

    open 'r', $foo;
    open 'w', $foo;

For the same reason, I prefer unified diff format to the </> format that
my copy uses by default.

> The fact that you want to both read and write a file says nothing
> about whether you initially want to use, clobber, or append to an
> existing file.

It's okay to have defaults, I think.

    r       use
    w       clobber
    a       append
    rw      use

This can without too much trouble be solved with :append and :clobber.

Juerd


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Williams  
View profile  
 More options Jul 13 2004, 5:44 pm
Newsgroups: perl.perl6.language
From: willi...@tni.com (John Williams)
Date: Tue, 13 Jul 2004 15:44:11 -0600 (MDT)
Local: Tues, Jul 13 2004 5:44 pm
Subject: Re: enhanced open-funktion

My understanding is that the :adverb is at the end because it is passed as
a named argument, which must be after the positional arguments.  And that
is certainly unambiguous with the comma.

However we have a precedent in m:i// where the :adverb comes directly
after the operator.  It's probably special because it "is parsed" that
way, but it's so common that I feel I can use it as a precedent anyway.

So if :adverbs are having such a weird time finding their verbs, wouldn't
it be easier to allow them to be placed directly after the verb all the
time?  Then the magic is merely moving it into the named args section
instead of wondering which operator's named args section it belongs to.

Then

  my $fh = open ">$filename" :excl;

is unambiguously

  my $fh = open (circumfix:""('>$filename', :excl));

while what was actually wanted is written as either of

  my $fh = open ">$filename", :excl;  # part of the arg list
  my $fh = open :excl ">$filename";   # adverb to open

And besides, I think it reads better when the adverb is next to the verb.

yes, no, maybe?

~ John Williams


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Wall  
View profile  
 More options Jul 14 2004, 2:10 pm
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Wed, 14 Jul 2004 11:10:05 -0700
Local: Wed, Jul 14 2004 2:10 pm
Subject: Re: enhanced open-funktion
On Tue, Jul 13, 2004 at 03:44:11PM -0600, John Williams wrote:

: On Tue, 13 Jul 2004, Larry Wall wrote:
: > On Tue, Jul 13, 2004 at 07:24:55AM -0600, Luke Palmer wrote:
: > : But in Perl 6, you don't have to specify things like that through the
: > : mode string: you can specify them through named parameters:
: > :
: > :     my $fh = open ">$filename" :excl;
: >
: > While that probably works, I think better style would be to use a comma:
: >
: >     my $fh = open ">$filename", :excl;
: >
: > That explicitly passes :excl to open as a term in a list rather
: > than relying on the magical properties of :foo to find the preceding
: > operator adverbially when used where an operator is expected.  We may
: > have to tighten up the definition of operator :foo a bit, since it's
: > not always going to be clear which preceding operator is intended.
: > Even quotes are operators if you squint.
: [snip]
: > I see several directions we could go to clarify this, and I don't
: > entirely like any of them.  [snip]
: >
: > Operator adverbs are, in essence, postfix operators with weird
: > precedence.  We're going to have to be very explicit about what we
: > mean by "weird" here.  Unfortunately, this morning I don't feel
: > very explicit.
:
: My understanding is that the :adverb is at the end because it is passed as
: a named argument, which must be after the positional arguments.  And that
: is certainly unambiguous with the comma.

It's unambiguous becase a term is expected at that point, so :adverb
isn't really an adverb--it's just a pair constructor.

: However we have a precedent in m:i// where the :adverb comes directly
: after the operator.  It's probably special because it "is parsed" that
: way, but it's so common that I feel I can use it as a precedent anyway.
:
: So if :adverbs are having such a weird time finding their verbs, wouldn't
: it be easier to allow them to be placed directly after the verb all the
: time?  Then the magic is merely moving it into the named args section
: instead of wondering which operator's named args section it belongs to.
:
: Then
:
:   my $fh = open ">$filename" :excl;
:
: is unambiguously
:
:   my $fh = open (circumfix:""('>$filename', :excl));
:
: while what was actually wanted is written as either of
:
:   my $fh = open ">$filename", :excl;  # part of the arg list
:   my $fh = open :excl ">$filename";   # adverb to open
:
: And besides, I think it reads better when the adverb is next to the verb.
:
: yes, no, maybe?

Except that you've but :excl where the parse is expecting a term, so it
isn't an adverb.  It's just a pair constructor.  Which means that after
it the parser is expecting an operator, and blows up on the string literal.

The adverb notation as currently defined only works where an operator
is expected.  Which means it can't really be used on unary operators
unless there's some kind of pecking order where we try to apply it to
the unary operator, and if that fails, apply it to the preceding binary
operator.  But that's a headache waiting to happen.  I'm more inclined
to say that the adverb notation only works for binary operators, and
you have to use pair args with unaries.  So you can't write

    $x = rand 20 :bell_curve

because it would try to apply :bell_curve to the assignment, but you
can write

    $x = rand(20, :bell_curve)

I know it seems like the adverb syntax is misplacing the modifier with
respect to the binary operator it's modifying, but I think most of its
uses are actually very short:

    1..100:by(3)

If you really want something fancy, you'd be better off to write it
in functional form with a normal named pair argument:

    infix:..(1, <some_big_hairy_expression>, :by(3))

instead of

    1 .. <some_big_hairy_expression> :by(3)

Alternately, I do see an easy formatting hack:

    1 .. (<some_big_hairy_expression>)
      :by(3)

Just don't anyone suggest that we indicate what's modified
*syntactically* by placing the adverb directly under it...

Hmm.  Maybe with an extra uparrow?

    1 .. (<some_big_hairy_expression>)
      ^:by(3)

Yow.  Two-dimensional programs.  Reminds me of BF...

But we'd have to pay really close attention to how indenting is done.
Maybe we should just pass this suggestion on to Guido...  :-)

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Dondi  
View profile  
 More options Jul 15 2004, 5:42 am
Newsgroups: perl.perl6.language
From: bla...@pcteor1.mi.infn.it (Michele Dondi)
Date: Thu, 15 Jul 2004 11:42:52 +0200 (CEST)
Local: Thurs, Jul 15 2004 5:42 am
Subject: Re: enhanced open-funktion

On Tue, 13 Jul 2004, Juerd wrote:
>     open '<', $foo;
>     open '>', $foo;

> is much harder to read than

>     open 'r', $foo;
>     open 'w', $foo;

Are you sure?!? I would tend to disagree... not that MHO is particularly
important, I guess, but just to stress the fact that it is by large a
subjective matter...

Michele
--
Oh, for God's sake! Earnest misunderstanding I can cope with,
stupidity I can cope with, complete lack of sense of humour I can cope
with, but lying I cannot.
*PLONK*
- Ben Morrow in clpmisc (slightly edited)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg Boug  
View profile  
 More options Jul 15 2004, 6:01 am
Newsgroups: perl.perl6.language
From: gb...@unico.com.au (Greg Boug)
Date: Thu, 15 Jul 2004 20:01:40 +1000
Local: Thurs, Jul 15 2004 6:01 am
Subject: Re: enhanced open-funktion
On Thursday 15 July 2004 19:42, Michele Dondi wrote:

> >     open '<', $foo;
> >     open '>', $foo;

> > is much harder to read than

> >     open 'r', $foo;
> >     open 'w', $foo;
> Are you sure?!? I would tend to disagree... not that MHO is particularly
> important, I guess, but just to stress the fact that it is by large a
> subjective matter...

I have always felt that keeping it the same as shell scripting was a handy
thing, especially when I have been teaching it to others. It also makes
the ol' perl5

        open FH, "|/usr/bin/foo";

make a lot more sense. Using something like

        open "p", "/usr/bin/foo";

just wouldn't have the same ring to it. Aside from which, it gets even worse
when you consider how you would have to change:

        open FH, "/usr/bin/foo|";

Greg
--
Greg Boug (gb...@unico.com.au)
Systems and Network Administrator
UNICO Computer Systems
Melbourne, Australia.
Phone: +61-3-9865-9116


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
H.Merijn Brand  
View profile  
 More options Jul 15 2004, 5:57 am
Newsgroups: perl.perl6.language
From: h.m.br...@hccnet.nl (H.Merijn Brand)
Date: Thu, 15 Jul 2004 11:57:24 +0200
Local: Thurs, Jul 15 2004 5:57 am
Subject: Re: enhanced open-funktion
On Thu 15 Jul 2004 11:42, Michele Dondi <bla...@pcteor1.mi.infn.it> wrote:

> On Tue, 13 Jul 2004, Juerd wrote:

> >     open '<', $foo;
> >     open '>', $foo;

> > is much harder to read than

> >     open 'r', $foo;
> >     open 'w', $foo;

> Are you sure?!? I would tend to disagree...

So do I. "<", and ">" are imho MUCH clearer than 'r' and 'w' for several
reasons

0. More appealing to the eye
1. They do not ambiguate with files named 'r', or 'w'
2. They don't have to be translated (in german that would be 'l' and 's')
3. They play nice with possible extensions 'open ">:utf8", $file;

> not that MHO is particularly
> important, I guess, but just to stress the fact that it is by large a
> subjective matter...

--
H.Merijn Brand        Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using perl-5.6.1, 5.8.3, & 5.9.x, and 809 on  HP-UX 10.20 & 11.00, 11i,
   AIX 4.3, SuSE 9.0, and Win2k.           http://www.cmve.net/~merijn/
http://archives.develooper.com/daily-bu...@perl.org/   perl...@perl.org
send smoke reports to: smokers-repo...@perl.org, QA: http://qa.perl.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juerd  
View profile  
 More options Jul 15 2004, 6:56 am
Newsgroups: perl.perl6.language
From: ju...@convolution.nl (Juerd)
Date: Thu, 15 Jul 2004 12:56:53 +0200
Local: Thurs, Jul 15 2004 6:56 am
Subject: Re: enhanced open-funktion
H.Merijn Brand skribis 2004-07-15 11:57 (+0200):

> 1. They do not ambiguate with files named 'r', or 'w'

Not a problem, assuming that these are named arguments as in:

    open :r, $file;
    open :w, $file;
    open :rw, $file;
    open :r :w, $file;  # Hmm...

> 2. They don't have to be translated (in german that would be 'l' and 's')

zeg "hallo, wereld";

mijn $dbh = DBI->verbind(...);
mijn $sth = $dbh->bereid_voor($zoekopdracht);
$sth->voer_uit(@waardes);
$sth->bind_kolommen(\my ($foo, $bar));

zolang ($sth->apporteer) {  # :)
    toonf "%10s %d", $foo, $bar;
    volgende als $bar gd 15;

}

No, translations don't work in programming.

> 3. They play nice with possible extensions 'open ">:utf8", $file;

But

    open :w('utf8'), $file;

it would even make using different layers for in and output easy:

    open :r('iso-8859-15') :w('utf8'), $file;

although you shouldn't want that :)

Juerd


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juerd  
View profile  
 More options Jul 15 2004, 7:01 am
Newsgroups: perl.perl6.language
From: ju...@convolution.nl (Juerd)
Date: Thu, 15 Jul 2004 13:01:24 +0200
Local: Thurs, Jul 15 2004 7:01 am
Subject: Re: enhanced open-funktion
Greg Boug skribis 2004-07-15 20:01 (+1000):

>    open FH, "|/usr/bin/foo";

I'd love to be rid of -| and |-. I always have to RTFM to know which
one is which.

    open :r :p, '/usr/bin/foo';  # Or :read :pipe
    open :rp, '/usr/bin/foo';    # IIRC, rules also let you combine
                                 # single-letter modifiers

>    open FH, "/usr/bin/foo|";

    open :w :p, ...;

And open2 is :r :w :p or :rwp or :read :write :pipe.

Or something like that.

Juerd


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Smylers  
View profile  
 More options Jul 15 2004, 2:28 pm
Newsgroups: perl.perl6.language
From: Smyl...@stripey.com (Smylers)
Date: Thu, 15 Jul 2004 18:28:08 GMT
Local: Thurs, Jul 15 2004 2:28 pm
Subject: Re: enhanced open-funktion

Greg Boug writes:
> I have always felt that keeping ['>' and '<'] the same as shell
> scripting was a handy thing, ...

Using C<:w> and C<:r> would at least match what C<:w> and C<:r> do in
'Vi' ...

Smylers


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Austin Hastings  
View profile  
 More options Jul 15 2004, 2:51 pm
Newsgroups: perl.perl6.language
From: austin_hasti...@yahoo.com (Austin Hastings)
Date: Thu, 15 Jul 2004 11:51:24 -0700 (PDT)
Local: Thurs, Jul 15 2004 2:51 pm
Subject: Re: enhanced open-funktion

--- Smylers <Smyl...@stripey.com> wrote:
> Using C<:w> and C<:r> would at least match what C<:w> and C<:r> do in
> 'Vi' ...

That seems intuitive:

  my $fh = open 'foo.txt', :w;
  $fh.say "Hello, world!";

  $fh = open 'foo.txt', :e;    # Ha, ha, just kidding!

  $fh.say <<<-EOF
    If wifey shuns
      Your fond embrace
    Don't kill the mailman:
      Feel your face!
    Burma Shave
  EOF

  $fh.close :q!;    # Tricked again.
  $fh = open :n;    # Opens next file from argv?

=Austin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brent 'Dax' Royal-Gordon  
View profile  
 More options Jul 15 2004, 4:04 pm
Newsgroups: perl.perl6.language
From: br...@brentdax.com (Brent 'Dax' Royal-Gordon)
Date: Thu, 15 Jul 2004 13:04:33 -0700
Local: Thurs, Jul 15 2004 4:04 pm
Subject: Re: enhanced open-funktion

Greg Boug wrote:
> I have always felt that keeping it the same as shell scripting was a handy
> thing, especially when I have been teaching it to others. It also makes
> the ol' perl5

>    open FH, "|/usr/bin/foo";

> make a lot more sense. Using something like

>    open "p", "/usr/bin/foo";

> just wouldn't have the same ring to it. Aside from which, it gets even worse
> when you consider how you would have to change:

>    open FH, "/usr/bin/foo|";

My personal preference is for:

     $in=open :r "|/usr/bin/foo";
     $out=open :w "|/usr/bin/foo";
     $both=open :rw "|/usr/bin/foo";

The pipe would be legal on either side of the string.  This would still
allow the often-useful "type a pipe command at a prompt for a file",
while matching the trait-based syntax suggested elsewhere.

--
Brent "Dax" Royal-Gordon <br...@brentdax.com>
Perl and Parrot hacker

Oceania has always been at war with Eastasia.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juerd  
View profile  
 More options Jul 15 2004, 4:35 pm
Newsgroups: perl.perl6.language
From: ju...@convolution.nl (Juerd)
Date: Thu, 15 Jul 2004 22:35:32 +0200
Local: Thurs, Jul 15 2004 4:35 pm
Subject: Re: enhanced open-funktion
Brent 'Dax' Royal-Gordon skribis 2004-07-15 13:04 (-0700):

>     $in=open :r "|/usr/bin/foo";
>     $out=open :w "|/usr/bin/foo";
>     $both=open :rw "|/usr/bin/foo";

No, thank you. Please let us not repeat the mistake of putting mode and filename/path in one argument.

juerd@ouranos:~/tmp/example$ ls -R *
|:
usr

|/usr:
bin

|/usr/bin:
foo

Juerd


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Smylers  
View profile  
 More options Jul 15 2004, 4:52 pm
Newsgroups: perl.perl6.language
From: Smyl...@stripey.com (Smylers)
Date: Thu, 15 Jul 2004 20:52:27 GMT
Local: Thurs, Jul 15 2004 4:52 pm
Subject: Re: enhanced open-funktion

Brent 'Dax' Royal-Gordon writes:
> My personal preference is for:

>      $in=open :r "|/usr/bin/foo";

> The pipe would be legal on either side of the string.  This would
> still allow the often-useful "type a pipe command at a prompt for a
> file",

And it still allows for all those security holes in websites where
inexperienced programmers are just expecting a filename but write code
that's capable of executing commands.  Such behaviour is non-obvious to
somebody who hasn't been specifically warned about the danger, and the
potential for abuse is high.

Please let's not repeat this ...

Smylers


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 28   Newer >
« Back to Discussions « Newer topic     Older topic »