use only The::Finest = 1.23;

2003-02-19 Thread Brian Ingerson
I've just released a module called 'only.pm' that allows people to
install multiple versions of various modules. It also lets them 'use'
specific versions.

It was suggested to me that this might contribute insight towards module
versioning in Perl6. Have fun.

Here is the doc:

  NAME
  only - Load specific module versions; Install many
  
  SYNOPSIS
  # Install version 0.30 of MyModule
  cd MyModule-0.30
  perl Makefile.PL
  make test
  perl -Monly=install# substitute for 'make install' 
  
  # Only use MyModule version 0.30
  use only MyModule = '0.30';
  
  # Only use MyModule if version is between 0.30 and 0.50
  # but not 0.36; or if version is = to 0.55.
  use only MyModule = '0.30-0.50 !0.36 0.55-', qw(:all);
  
  # Don't export anything!
  use only MyModule = '0.30', [];
  
  # Version dependent arguments
  use only MyModule =
  [ '0.20-0.27', qw(f1 f2 f3 f4) ],
  [ '0.30-', qw(:all) ];
  
  USAGE
  # Note: angle brackets mean optional.
  
  # To load a specific module
  use only MODULE = 'CONDITION SPEC' , ARGUMENTS;
  
  # For multiple argument sets
  use only MODULE = 
  ['CONDITION SPEC 1' , ARGUMENTS1],
  ['CONDITION SPEC 2' , ARGUMENTS2],
  ...
  ;
  
  # To install an alternate version of a module
  perl -Monly=install - VERSION# instead of 'make install'
  
  DESCRIPTION
  The only.pm facility allows you to load a MODULE only if it satisfies
  a given CONDITION. Normally that condition is a version. If you just
  specify a single version, 'only' will only load the module matching that
  version. If you specify multiple versions, the module can be any of
  those versions. See below for all the different conditions you can use
  with only.
  
  only.pm will also allow you to load a particular version of a module,
  when many versions of the same module are installed. See below for
  instructions on how to easily install many different versions of the
  same module.
  
  CONDITION SPECS
  A condition specification is a single string containing a list of zero
  or more conditions. The list of conditions is separated by spaces. Each
  condition can take one of the following forms:
  
  * plain version
  This is the most basic form. The loaded module must match this
  version string or be loaded from a version directory that uses the
  version string. Mulitiple versions means one or the other.
  
  use only MyModule = '0.11';
  use only MyModule = '0.11 0.15';
  
  * version range
  This is two single versions separated by a dash. The end points are
  inclusive in the range. If either end of the range is ommitted, then
  the range is open ended on that side.
  
  use only MyModule = '0.11-0.12';
  use only MyModule = '0.13-';
  use only MyModule = '-0.10';
  use only MyModule = '-';   # Means any version
  
  Note that a completely open range (any version) is not the same as
  just saying:
  
  use MyModule;
  
  because the only module will search all the various version libs
  before searhing in the regular @INC paths.
  
  Also note that an empty string or no string means the same thing as
  '-'.
  
  # All of these mean use any version
  use only MyModule = '-';
  use only MyModule = '';
  use only 'MyModule';
  
  * complement version or range
  Any version or range beginning with a '!' is considered to mean the
  inverse of that specification. A complement takes precedence over
  all other specifications. If a module version matches a complement,
  that version is immediately rejected without further inspection.
  
  use only MyModule = '!0.31';
  use only MyModule = '0.30-0.40 !0.31-0.33';
  
  The search works by searching the version-lib directories (found in
  only::config) for a module that meets the condition specification. If
  more than one version is found, the highest version is used. If no
  module meets the specification, then a normal @INC style require is
  performed.
  
  If the condition is a subroutine reference, that subroutine will be
  called and passed an only object. If the subroutine returns a false
  value, the program will die. See below for a list of public methods that
  may be used upon the only object.
  
  ARGUMENTS
  All of the arguments following the CONDITION specification, will be
  passed to the module being loaded.
  
  Normally you can pass an empty list to use to turn off Exporting. To
  do this 

Re: Arrays, lists, referencing

2003-02-19 Thread David Storrs
On Wed, Feb 19, 2003 at 09:51:12AM +1100, Deborah Ariel Pickett wrote:

 That said, I don't know of anything that the C comma operator can do
 that you couldn't equivalently do with a Perl5 Cdo statement:
 
   foo() or (do { warn(blah); next; });   # Yes, it's ugly.

Or just a Boolean:

   foo() or (warn(blah)  next; );

--Dks



Re: Arrays, lists, referencing

2003-02-19 Thread Stephen McCamant
 DP == Deborah Ariel Pickett [EMAIL PROTECTED]
   writes:

DP One thing that the C comma operator promises is that its left
DP operand (and all side effects) is completely evaluated before work
DP starts on the right operand.  (This may not be strictly true in
DP the Perl interpretation of the operator; can a Perl5 developer
DP comment?)

It's a matter of some controversy exactly what promises with regards
to order of operation Perl5 provides. Unlike C, there's no separate
standard describing what Perl should do: just an implementation, and
some documentation.

As a matter of implementation, I believe both scalar and list comma
operators have always evaluated their arguments from left to right.
(This also applies to the comma separating sub arguments, if you count
that separately from list comma).

As for documentation, both the POD and the Camel book use language
that strongly suggests left-to-right evaluation for the scalar comma
(it evaluates its left argument, throws that value away, then
evaluates its right argument and returns that value) as well as
referring to it as just like the C comma. By contrast, they don't
say anything directly about the evaluation order of the list comma.

On the other hand, there is the following example from perldata (I
can't find it in the Camel, but I can't grep the Camel):

# A reverse comma operator.
return (pop(@foo),pop(@foo))[0];

which only makes sense if list comma is guaranteed to evaluate left to
right.

DP I'm pretty sure that for a Perl list, the order of evaluation of
DP elements isn't guaranteed, meaning that Cnext may evaluate
DP before Cwarn in the above example if it were treated exactly
DP like a list.  (Again, can someone refute or support this?)

[The example again is 'foo() or (warn(blah), next);']

Note that neither argument to or can be a list, so that comma isn't
a list comma. It's actually in a void context there, so it's a scalar
comma. (The rule void context is a kind of scalar context seems
rather arbitrary in the abstract, and the reasons for it are at least
partially historical, but it does seem to me to give the right answer
here).

 -- Stephen



Re: Arrays, lists, referencing

2003-02-19 Thread Smylers
Dave Mitchell wrote:

 On Tue, Feb 18, 2003 at 10:06:29PM -, Smylers wrote:
 
  More practically, the length of a list is never interesting: a list
  by definition must be hardcoded into the program so its length is
  known at compile time.
 
 Err, no.  Eg in perl 5:
 
 $value = (1,2, @ARGV,3,4)[$i]
 
 That's a list, and its length is not known at compile time.

Ooops, yes.  I was overstating the case that a list's length must be
known at compile time.  But I'd still maintain that the length isn't
interesting.  In your example you are picking out a particular element,
which is reasonable and I've got no objection with that.

What I don't understand is why a list in numeric context should yield
its length, and that still applies to your example.  There's no
advantage in doing:

  $length = 1 + (1, 2, @ARGV, 3, 4);

over the much more straightforward:

  $length = 5 + @ARGV;

Smylers



Re: Arrays, lists, referencing

2003-02-19 Thread Luke Palmer
On Wed, Feb 19, 2003 at 09:51:12AM +1100, Deborah Ariel Pickett wrote:
 That said, I don't know of anything that the C comma operator can do
 that you couldn't equivalently do with a Perl5 Cdo statement:
 
   foo() or (do { warn(blah); next; });   # Yes, it's ugly.

Well, gee, it's not that ugly:

  foo or do { warn blah; next };

Stripping off all unneeded parentheses.  Cdo is a little redundant:

  foo or { warn blah; next }();

And what if, something like m//, closures based whether they evaluate
on context.  i.e. they Iwould evaluate in void context.  Then we
have completely redundantized the C comma:

  foo or { warn blah; next };
  loop ({ $i=0; $j=20 }; $i = 10  $j; { $i++; $j-- }) {...}

When it wouldn't evaluate because of context, there's still Cdo and
() to do the trick.

Assuming you can do control flow from within a closure.  Hmm... that
makes me cringe a bit.  Oh, look, you can do it in Perl 5, though.

But I think all of us already agreed that the C comma is not
needed.  
 
Luke