what is the behavior of the x operator (string replication) with negative values

2007-05-25 Thread Chas Owens

In my mind

perl -le 'print join "\n", map { "[" . 0 x $_ . "]" } -1 .. 1'

and

pugs -e 'say join "\n", map { "[{ 0 x $_}]" }, -1 .. 1'

should both print
[]
[]
[0]

But the Pugs code throws
pugs: List.genericTake: negative argument

Is this Pugs specific behavior or has the the x operator changed with
respect to negative values?

from perldoc perlop
  If the right operand is zero or negative, it returns an empty
string . . .


x and xx operators fail when given negatives

2007-05-25 Thread Chas Owens

"-" x -1 should evaluate to an empty string and 0 xx -1 should
evaluate to an empty list.  I have hacked pugs/src/Pugs/Prim.hs to
correctly handle negatives, but I don't know Haskell very well and am
not familiar with the layout of Pugs, so I may have written bad code
in a bad place.  I have also added tests to pugs/t/operators/repeat.t
to test for correct handling of negative and zero values.

Hopefully the patch will make it through to the list.
diff -ruN pugs.orig/src/Pugs/Prim.hs pugs/src/Pugs/Prim.hs
--- pugs.orig/src/Pugs/Prim.hs	2007-05-25 16:34:55.0 -0400
+++ pugs/src/Pugs/Prim.hs	2007-05-25 15:59:47.0 -0400
@@ -923,6 +923,11 @@
 | last str == '\n'  = VStr (init str)
 | otherwise = VStr str
 
+perlReplicate :: VInt -> a -> [a]
+perlReplicate i a = if i < 0 
+then genericReplicate 0 a 
+else genericReplicate i a
+
 -- |Implementation of 2-arity primitive operators and functions
 op2 :: String -> Val -> Val -> Eval Val
 op2 "rename" = guardedIO2 rename
@@ -931,8 +936,8 @@
 op2 "*"  = op2Numeric (*)
 op2 "/"  = op2Divide
 op2 "%"  = op2Modulus
-op2 "x"  = op2Cast (\x y -> VStr . concat $ (y :: VInt) `genericReplicate` x)
-op2 "xx" = op2Cast (\x y -> VList . concat $ (y :: VInt) `genericReplicate` x)
+op2 "x"  = op2Cast (\x y -> VStr . concat $ (y :: VInt) `perlReplicate` x)
+op2 "xx" = op2Cast (\x y -> VList . concat $ (y :: VInt) `perlReplicate` x)
 op2 "+&" = op2Int (.&.)
 op2 "+<" = op2Int shiftL
 op2 "+>" = op2Int shiftR
diff -ruN pugs.orig/t/operators/repeat.t pugs/t/operators/repeat.t
--- pugs.orig/t/operators/repeat.t	2007-05-25 16:34:55.0 -0400
+++ pugs/t/operators/repeat.t	2007-05-25 16:13:29.0 -0400
@@ -8,7 +8,7 @@
 
 =cut
 
-plan 19;
+plan 23;
 
 #L
 
@@ -16,6 +16,8 @@
 is('ab' x 4, 'abababab', 'string repeat operator works on multiple character');
 is(1 x 5, '1', 'number repeat operator works on number and creates string');
 is('' x 6, '', 'repeating an empty string creates an empty string');
+is('a' x 0, '', 'repeating zero times produces an empty string');
+is('a' x -1, '', 'repeating negative times produces an empty string');
 
 #L
 my @foo = 'x' xx 10;
@@ -23,12 +25,20 @@
 is(@foo[9], 'x', 'list repeat operator created correct array');
 is([EMAIL PROTECTED], 10, 'list repeat operator created array of the right size');
 
+
 lives_ok { my @foo2 = undef xx 2; }, 'can repeat undefs';
 my @foo3 = (1, 2) xx 2;
 is(@foo3[0], 1, 'can repeat lists');
 is(@foo3[1], 2, 'can repeat lists');
 is(@foo3[2], 1, 'can repeat lists');
 is(@foo3[3], 2, 'can repeat lists');
+
+my @foo4 = 'x' xx 0;
+is([EMAIL PROTECTED], 0, 'repeating zero times produces an empty list');
+
+my @foo5 = 'x' xx -1;
+is([EMAIL PROTECTED], 0, 'repeating negative times produces an empty list');
+
 my @foo_2d = [1, 2] xx 2; # should create 2d
 is(@foo_2d[1], [1, 2], 'can create 2d arrays', :todo); # creates a flat 1d array
 # Wrong/unsure: \(1, 2) does not create a ref to the array/list (1,2), but


Re: x and xx operators fail when given negatives

2007-05-25 Thread Chas Owens

it looks like the patch did not make it to the list, so here it is inline

diff -ruN pugs.orig/src/Pugs/Prim.hs pugs/src/Pugs/Prim.hs
--- pugs.orig/src/Pugs/Prim.hs  2007-05-25 16:34:55.0 -0400
+++ pugs/src/Pugs/Prim.hs   2007-05-25 15:59:47.0 -0400
@@ -923,6 +923,11 @@
| last str == '\n'  = VStr (init str)
| otherwise = VStr str

+perlReplicate :: VInt -> a -> [a]
+perlReplicate i a = if i < 0
+then genericReplicate 0 a
+else genericReplicate i a
+
-- |Implementation of 2-arity primitive operators and functions
op2 :: String -> Val -> Val -> Eval Val
op2 "rename" = guardedIO2 rename
@@ -931,8 +936,8 @@
op2 "*"  = op2Numeric (*)
op2 "/"  = op2Divide
op2 "%"  = op2Modulus
-op2 "x"  = op2Cast (\x y -> VStr . concat $ (y :: VInt) `genericReplicate` x)
-op2 "xx" = op2Cast (\x y -> VList . concat $ (y :: VInt) `genericReplicate` x)
+op2 "x"  = op2Cast (\x y -> VStr . concat $ (y :: VInt) `perlReplicate` x)
+op2 "xx" = op2Cast (\x y -> VList . concat $ (y :: VInt) `perlReplicate` x)
op2 "+&" = op2Int (.&.)
op2 "+<" = op2Int shiftL
op2 "+>" = op2Int shiftR
diff -ruN pugs.orig/t/operators/repeat.t pugs/t/operators/repeat.t
--- pugs.orig/t/operators/repeat.t  2007-05-25 16:34:55.0 -0400
+++ pugs/t/operators/repeat.t   2007-05-25 16:13:29.0 -0400
@@ -8,7 +8,7 @@

=cut

-plan 19;
+plan 23;

#L

@@ -16,6 +16,8 @@
is('ab' x 4, 'abababab', 'string repeat operator works on multiple character');
is(1 x 5, '1', 'number repeat operator works on number and
creates string');
is('' x 6, '', 'repeating an empty string creates an empty string');
+is('a' x 0, '', 'repeating zero times produces an empty string');
+is('a' x -1, '', 'repeating negative times produces an empty string');

#L
my @foo = 'x' xx 10;
@@ -23,12 +25,20 @@
is(@foo[9], 'x', 'list repeat operator created correct array');
is([EMAIL PROTECTED], 10, 'list repeat operator created array of the right 
size');

+
lives_ok { my @foo2 = undef xx 2; }, 'can repeat undefs';
my @foo3 = (1, 2) xx 2;
is(@foo3[0], 1, 'can repeat lists');
is(@foo3[1], 2, 'can repeat lists');
is(@foo3[2], 1, 'can repeat lists');
is(@foo3[3], 2, 'can repeat lists');
+
+my @foo4 = 'x' xx 0;
+is([EMAIL PROTECTED], 0, 'repeating zero times produces an empty list');
+
+my @foo5 = 'x' xx -1;
+is([EMAIL PROTECTED], 0, 'repeating negative times produces an empty list');
+
my @foo_2d = [1, 2] xx 2; # should create 2d
is(@foo_2d[1], [1, 2], 'can create 2d arrays', :todo); # creates
a flat 1d array
# Wrong/unsure: \(1, 2) does not create a ref to the array/list (1,2), but


Re: x and xx operators fail when given negatives

2007-05-26 Thread Chas Owens

On 5/25/07, Moritz Lenz <[EMAIL PROTECTED]> wrote:
snip

It did. For the future I'd suggest that you commit them yourself, that's
far more efficient. Just tell us what nick name you want, and somebody
will invite you. If you want a different email address then the one you
used on this list, please let us know as well ;-)

snip

I tend to use (in order of preference) cowens, chas.owens, or cowensiv.


Re: x, xx, and negative counts

2007-05-29 Thread Chas Owens

On 5/29/07, Mark J. Reed <[EMAIL PROTECTED]> wrote:

 My expectation before reading the delta was that negative counts
would do a reversal:

"123" x -1 = "321"

('a', 'b', 'c') xx -3 = ('c', 'b', 'a', 'c', 'b', 'a', 'c', 'b', 'a');

I don't know why I think that makes sense, but it was honestly my
first thought.  Does it make sense to anyone else?  Is there a
compelling reason I'm missing for having negative values behave as if
they were zero rather than adding some other potentially useful
functionality?

snip

In Perl 5 I commonly say things like

sub zeropad (
   my ($len, $s) = @_;
   my $slen = length $s;
   carp "the string $s is longer than the specified length $len" if
$slen > $len;
   return = 0 x  ($len - length($str)) . $str;
);

Which is roughly equivalent to doing a sprintf with the format "%0${len}d".


Re: [svn:perl6-synopsis] r14405 - doc/trunk/design/syn

2007-05-29 Thread Chas Owens

On 5/29/07, Larry Wall <[EMAIL PROTECTED]> wrote:

On Tue, May 29, 2007 at 04:05:39PM -0400, Chas Owens wrote:
: On 5/29/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
: snip
: >+If the count is less than 1, returns the null string.
: >+The count may not be C<*> because Perl 6 does not support
: >+infinite strings.  (At least, not yet...)
: snip
:
: Does "may not be c<*>" mean that the compiler should throw a fatal
: error if it sees it or that the program will hang because it is the
: programmer's fault (similar to "while 1 {}") .

The compiler is generally allowed to complain about anything it knows
must fail at runtime, and since scalars default to eager, this will
certainly run out of memory at runtime.

Larry



Just an odd corner case, but
   "foo" x -*
should return an empty string and
   "foo" xx -*
should return an empty list, right?


Re: [svn:perl6-synopsis] r14405 - doc/trunk/design/syn

2007-05-29 Thread Chas Owens

On 5/29/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
snip

+If the count is less than 1, returns the null string.
+The count may not be C<*> because Perl 6 does not support
+infinite strings.  (At least, not yet...)

snip

Does "may not be c<*>" mean that the compiler should throw a fatal
error if it sees it or that the program will hang because it is the
programmer's fault (similar to "while 1 {}") .


Re: [svn:perl6-synopsis] r14405 - doc/trunk/design/syn

2007-05-29 Thread Chas Owens

On 5/29/07, Larry Wall <[EMAIL PROTECTED]> wrote:

On Tue, May 29, 2007 at 04:43:20PM -0400, Chas Owens wrote:
: Just an odd corner case, but
:"foo" x -*
: should return an empty string and
:"foo" xx -*
: should return an empty list, right?

I'm doubt &prefix:<->:(Whatever) is defined at all, so that's probably
a run-time failure unless someone defines the appropriate multi.
And if the - fails it never even gets to the x or xx.  The * token
doesn't mean infinity.  It means that the operator you feed it to
has to figure out what it means.  Some operators interpret * to mean
infinity.  But infix:<-> interprets a * on the left to mean the end
of the current subscript range.  And the range operator interprets *
to mean either negative or positive infinity depending on whether
it's on the left or the right.  We don't require (or even allow)
people to say -*..* as it currently stands.

Larry


Okay, obviously I have more synopsis to read, but currently Pugs says:
pugs> my $posinf = *
Inf
pugs> my $neginf = -*
-Inf

which made me think * is Inf in scalar context.  Is this a bug in Pugs then?

Is Inf the canonical way of spelling the literal "infinity"?

I am patching Pugs' x and xx operators to handle infinity now.  The
behavior after the patch is
pugs> "a" x 5
"a"
pugs> "a" x 0
""
pugs> "a" x -5
""
pugs> "a" x Inf
Internal error while running expression:
Infinite replications would exahust memory
pugs> "a" x -Inf
""

Besides fixing the spelling error on exhaust and making it a real die
instead of an internal error (which I have yet to figure out how to
do), does this match up with your expectations for the replication
operators?


How to die

2007-05-29 Thread Chas Owens

I have poked around a bit in the code and can't find a good way to
die.  I am currently using

perlReplicate n a = if n == 1/0
   then error "Infinite replications would exhaust memory"
   else if n < 0
   then genericReplicate 0 a
   else genericReplicate (truncate n) a

But that gives the following message

pugs> "a" x Inf
Internal error while running expression:
Infinite replications would exhaust memory

But this isn't an internal error; it is a user error, so I want a message like

pugs> "a" x Inf
*** Infinite replications would exhaust memory
   at  line 1, column 1-9


Re: propose renaming Hash to Dict

2007-05-31 Thread Chas Owens

On 5/31/07, Darren Duncan <[EMAIL PROTECTED]> wrote:

Barring some better name, I highly recommend/propose renaming Hash to Dict.


And lets rename Perl to Python. This is just change for the sake of change.

snip

The term Dict (as a short form of "dictionary") is well understood by
general people and is the term used for associative arrays in some
other languages, so it is easy to learn, and easy to explain to
people in Learning Perl.

snip

Dict also makes it sound like you are talking about pornography.  Of
course, hash makes it sound like you are talking about getting high.

snip

The term Dict is easier for new people to Perl, either new
programmers or visitors from other languages, to learn than Hash is.
It allows more self-documenting code where one is used.  And writing
Learning Perl should be easier.

snip

Please provide the peer-reviewed study that proves this as it goes
against my experience.

snip

For Perl 5 people, it should be very easy to adapt, or for the most
part they may not notice any difference save for documentation
references.

snip

The Perl 5 people are already annoyed that . is changing to ~, sigils
are becoming invariant, etc.  Why not change the name of one of the
data structures too?  If we give them too many things to complain
about they won't be able to decide where to start!

snip

You also have equal huffmanization since the terms Hash and Dict are
both of the same length, and they are also equally easy to type.

snip

They may be the same number of characters, but I can type hash without
leaving the home row on QWERTY keyboards, I don't know about Dvorak.

snip

And aside from the 4 letter word, all the other details associated
with hashes, eg the % sigil and {} constructor, and parts named
keys,values,pairs,kv et al can/should remain the same as they are.

snip

Right, because dictionaries have keys and values not terms and
definitions.  Of course, it all makes sense now.

snip

In fact, since many users of Perl don't refer to the data type by the
name Hash but rather just by % or {}, the change may not take from
their useability at all or they may not even notice that a change
occurred at all, so easy to adapt.

snip

Except of course those poor schmucks who foolishly wrote code like

if (ref $arg eq 'HASH') { ... }


Re: propose renaming Hash to Dict

2007-06-01 Thread Chas Owens

On 6/1/07, Doug McNutt <[EMAIL PROTECTED]> wrote:

At 09:15 -0700 6/1/07, Larry Wall wrote:
>: To conclude, as hash definitely tastes better than a dictionary, we
>: should stick to that name. ;)
>:
>: At least nobody can say that Perl is bad taste!
>
>Then maybe we should rename Array to Skewer or Kabob or some such...
>
>Hmm, except it's hard to random access the middle...
>
>Maybe AntsOnALog...  (celery, cream cheese/peanut butter, and raisins)

Since Larry started it:

Don't forget that a common form of hash as a food is SPAM in all capitals. 
Perhaps perl6 could get special dispensation from Hormel.

--

--> From the U S of A, the only socialist country that refuses to admit it. <--



That is just not kosher.


Re: 'x' vs. 'xx'

2007-06-02 Thread Chas Owens

On 6/2/07, Jonathan Lang <[EMAIL PROTECTED]> wrote:

Is there any reason why we can't simply define '$a x $n' as being
shorthand for 'cat($a xx $n)'?  In what way does the former differ
from the latter, other than the use of a Whatever in place of $n?

--
Jonathan "Dataweaver" Lang


"$a x $n" is equivalent to "join '', $a xx $n", but that isn't an apt
description of its behavior.  "cat($a xx *)" is an attempt to provide
an infinite string since 'a' x Inf would result in memory overflow
(but the cat trick works since lists are evaluated lazily).


Re: 'x' vs. 'xx'

2007-06-03 Thread Chas Owens

On 6/3/07, Jonathan Lang <[EMAIL PROTECTED]> wrote:

Chas Owens wrote:
> Jonathan Lang wrote:
> > Is there any reason why we can't simply define '$a x $n' as being
> > shorthand for 'cat($a xx $n)'?  In what way does the former differ
> > from the latter, other than the use of a Whatever in place of $n?
>
> "$a x $n" is equivalent to "join '', $a xx $n", but that isn't an apt
> description of its behavior.  "cat($a xx *)" is an attempt to provide
> an infinite string since 'a' x Inf would result in memory overflow
> (but the cat trick works since lists are evaluated lazily).

Then it looks to me like 'cat($a xx $n)' is more flexible than "join
'', $a xx $n", and would work better as the baseline definition for
'$a x $n'.  Is there any reason to prefer a join-based definition to a
cat-based one?  AFAICT, the only thing that 'join' can do that 'cat'
can't is to provide a delimiter when stitching the component strings
together; in the case of 'x', this feature is (rightfully) not being
used.

--
Jonathan "Dataweaver" Lang



Okay, maybe my understanding of the cat function is flawed, but I
thought it walked through each array handed to it in a serial fashion
(as opposed to zip which walks the arrays in a parallel fashion).  If
that is the case then ("a" x 5) ne cat("a" xx 5).  The former produces
a scalar string value of five characters and the other produces a list
of one character scalar string values.  My understanding is that the
cat function and the xx operator are being used in  the documentation
to mimic what an _infinite_ string (not a normal string) would look
like.  Since you cannot have an infinite string with the current
implementation of scalars (memory would give out), a list with lazy
evaluation is used; however, you could not just drop cat("a" xx *)
into a spot where you you were using "a" x 5.


Re: 'x' vs. 'xx'

2007-06-03 Thread Chas Owens

On 6/3/07, Jonathan Lang <[EMAIL PROTECTED]> wrote:

Chas Owens wrote:
> Jonathan Lang wrote:
> > Chas Owens wrote:
> > > Jonathan Lang wrote:
> > > > Is there any reason why we can't simply define '$a x $n' as being
> > > > shorthand for 'cat($a xx $n)'?  In what way does the former differ
> > > > from the latter, other than the use of a Whatever in place of $n?
> > >
> > > "$a x $n" is equivalent to "join '', $a xx $n", but that isn't an apt
> > > description of its behavior.  "cat($a xx *)" is an attempt to provide
> > > an infinite string since 'a' x Inf would result in memory overflow
> > > (but the cat trick works since lists are evaluated lazily).
> >
> > Then it looks to me like 'cat($a xx $n)' is more flexible than "join
> > '', $a xx $n", and would work better as the baseline definition for
> > '$a x $n'.  Is there any reason to prefer a join-based definition to a
> > cat-based one?  AFAICT, the only thing that 'join' can do that 'cat'
> > can't is to provide a delimiter when stitching the component strings
> > together; in the case of 'x', this feature is (rightfully) not being
> > used.
>
> Okay, maybe my understanding of the cat function is flawed, but I
> thought it walked through each array handed to it in a serial fashion
> (as opposed to zip which walks the arrays in a parallel fashion).

Hmm... true enough.  That was an aspect of the 'cat' function that I
hadn't been aware of.  Rather, what came to mind when I saw the 'cat'
function was the following (from S29): "...a C in item context
emulates the C interface lazily."

In short, 'cat("a" x 5)' effectively _is_ a scalar string value of
five characters - in item context.  And because it emulates the string
interface _lazily_, there's no danger from an infinitely long string.

Again, I was not aware that there _was_ a distinct list context result
for 'cat'; and I'm pretty sure that it was referenced as an
alternative to '$a x *' due to its behavior in scalar context, rather
than its behavior in list context.

So the question is this: is there a problem with "'a' x 5" producing
"'a', 'a', 'a', 'a', 'a'" in list context, and 'a' in item
context?  Or should it produce the latter in anything but void
context?

--
Jonathan "Dataweaver" Lang



I am almost certain that the following code is in list context.

pugs> my @a = '-' x 5, 'foo', '-' x 5;
pugs> @a
("-", "foo", "-")
pugs> my @b = cat('-' xx 5), 'foo', cat('-' xx 5)
("-", "-", "-", "-", "-", "foo", "-", "-", "-", "-", "-")

However, it does seem that Pug's version of cat does not handle the
Str emulation, so that may fix it, but I don't see how it could since
(at least in my mind) the code above is in list context.


Re: 'x' vs. 'xx'

2007-06-03 Thread Chas Owens

On 6/3/07, Jonathan Lang <[EMAIL PROTECTED]> wrote:
snip

From what you're saying, I get the impression that you think that "'-'
x 5" ought to produce a single string of five dashes regardless of
whether the context is item or list.  Correct?  (Note: I'm not asking
about what the spec says, since what it says is potentially up for
revision, given sufficient cause; I'm asking about what you think the
spec _should_ say.)  If so, "cat($n xx *)" is not an adequate
replacement for "$n x *", since it produces a list of one-character
strings if used in list context.  OTOH, "~cat($n xx *)" might work.

snip

The current Perl 5 behavior is

[EMAIL PROTECTED]:~$ perl -le 'my @a = ("-" x 5, "foo", "-" x 5); print "@a"'
- foo -
[EMAIL PROTECTED]:~$ perl -le 'my @a = (("-") x 5, "foo", ("-") x 5); print 
"@a"'
- - - - - foo - - - - -

I am against anything other than that for x or xx without a really
compelling reason.

snip


Personally, I would tend to favor the notion that infix: always
produces a single string.  With this in mind, I'm now leaning toward
"~cat($a xx $n)" as the more verbose equivalent of "$a x $n".  You
always produce a single string, and you do so lazily (according to the
way that 'cat' works in item context).

--
Jonathan "Dataweaver" Lang


I assume it is a bug in Pugs implementation of cat, but
pugs> ~cat('a' xx 5)
"a a a a a"

I also am having a hard time figuring out why I would want an infinite
string.  My first thought was something like

my $ten_zeros = substr(cat(0 xx *), 0, 10);

but that is more clearly written as

my $ten_zeros = 0 x 10;


Re: [svn:perl6-synopsis] r14421 - doc/trunk/design/syn

2007-06-14 Thread Chas Owens

On 6/14/07, Damian Conway <[EMAIL PROTECTED]> wrote:
snip

To get the multi-line quote, you'd need:

say :to(END);
=begin POD
blah blah blah
=end POD
END

Damian



Would this work as well?

say :to(END);
\x{3D}begin POD
blah blah blah
\x{3D}end POD
END


Re: [svn:perl6-synopsis] r14421 - doc/trunk/design/syn

2007-06-22 Thread Chas Owens

On 6/22/07, Mark Overmeer <[EMAIL PROTECTED]> wrote:
snip

* Jonathan Lang ([EMAIL PROTECTED]) [070622 10:41]:

snip

> Please forgive my ignorance: what does "AST" stand for?

The Abstract Syntax Tree, the result of the code parser, un-interpreted.

snip

You mean it isn't Andrew S. Tanenbaum?  Well, it would have been a lot
easier to write that parser then.  You wouldn't believe how hard it is
to get a Perl script to output a Dutchman.


Re: Web Module (Was: Perl6 new features)

2007-06-22 Thread Chas Owens

On 6/22/07, chromatic <[EMAIL PROTECTED]> wrote:

On Thursday 21 June 2007 15:23:38 Smylers wrote:

> Has Larry yet decreed whether Web will be bundled with Perl 6?

I also like to proceed from the assumption that the only core modules should
be those required to install other modules.

-- c



Please, god, no.  Or at least make two distributions: Bare Perl 6 and
Perl 6.  Many companies have a "Only Core Perl" policy.  They refuse
to install CPAN modules because "We don't trust them".  Yeah, it is
stupid, but as a contractor I have limited ability to fight their
ignorance.


Re: Web Module (Was: Perl6 new features)

2007-06-22 Thread Chas Owens

On 6/22/07, Daniel Hulme <[EMAIL PROTECTED]> wrote:

On Fri, Jun 22, 2007 at 02:07:35PM -0400, Chas Owens wrote:
> On 6/22/07, chromatic <[EMAIL PROTECTED]> wrote:
> >I also like to proceed from the assumption that the only core modules
> >should be those required to install other modules.

> Please, god, no.  Or at least make two distributions: Bare Perl 6 and
> Perl 6.  Many companies have a "Only Core Perl" policy.  They refuse
> to install CPAN modules because "We don't trust them".  Yeah, it is
> stupid, but as a contractor I have limited ability to fight their
> ignorance.
Sounds like a bare Perl 6 distribution might be just what you need to
get them to weaken their restriction to "only modules with a good
cpanrating" or, best of all, "evaluate each module according to its
merits." Well, actually, I'm not sure that last one would be best, as
getting each module evaluating would almost inevitably entail getting
five or six high-up people together, none of whom have any interest in
you getting your job done, and who probably hate each others' guts, and
getting them to commit to some form of responsibility-generating paper-
trail.

Call me cynical if you like, but I prefer to call it, "experienced."


Most of the time the policy is enacted by lower-case-l lazy sysadmins
who can't be bothered to type

perl -MCPAN -e install Foo::Bar

My normal route around them is to install the module into the home
directory of the user who is going to run the script, but I have had
difficulty with this before when it comes time to move to production:
"Where is the code review for that code?".  My answer of "where is the
code review for that (often open source) database install you just
did?" doesn't tend to hold the weight I wish it did.  For some reason
binary blobs make some types of sysadmins feel all fuzzy and warm
inside.

As to whether a bare bones Perl distribution would help or hinder the
process of getting people to accept modules, well, all I can say is
that it is hard enough to get Perl into some companies.  If I had to
tell them "Oh, and we have to install all of these modules before we
can start coding." their response would likely be "Java already can do
that.  Use it instead.".  Yes, I have been told that before (related
to some XML stuff).


Re: Web Module (Was: Perl6 new features)

2007-06-22 Thread Chas Owens

On 6/22/07, jerry gay <[EMAIL PROTECTED]> wrote:

On 6/22/07, Chas Owens <[EMAIL PROTECTED]> wrote:
> Most of the time the policy is enacted by lower-case-l lazy sysadmins
> who can't be bothered to type
>
> perl -MCPAN -e install Foo::Bar
>
> My normal route around them is to install the module into the home
> directory of the user who is going to run the script, but I have had
> difficulty with this before when it comes time to move to production:
> "Where is the code review for that code?".  My answer of "where is the
> code review for that (often open source) database install you just
> did?" doesn't tend to hold the weight I wish it did.  For some reason
> binary blobs make some types of sysadmins feel all fuzzy and warm
> inside.
>
so use the parrot back end and compile all the modules to bytecode.
oh, and you can merge the foreign module bytecode with the bytecode
for your application, so it's all one big happy binary file.

in fact, parrot will even provide a way to compile bytecode to a
native executable which contains parrot itself. there, now you've got
a proper binary with *zero* external requirements in the production
environment--it doesn't even need to have parrot installed.

at that point, i'd be surprised if the release engineers or sysadmins
even notice.
~jerry



Good point.  I am still to stuck in the Perl 5 mind set.


Re: Web Module (Was: Perl6 new features)

2007-06-22 Thread Chas Owens

On 6/22/07, chromatic <[EMAIL PROTECTED]> wrote:

On Friday 22 June 2007 11:07:35 Chas Owens wrote:

> Please, god, no. Or at least make two distributions: Bare Perl 6 and
> Perl 6. Many companies have a "Only Core Perl" policy. They refuse
> to install CPAN modules because "We don't trust them".

I think of this the same way I think of "Do not drink even if you mix with
beer" labels on bleach bottles.  Stupid people often remove their genes from
the pool.  We should not discourage stupid business practices from doing the
same.

-- c



I still need to earn a paycheck, and I would rather do it with Perl
than with Java.  Fighting my customers stupidity, instead of working
around it, is a good way to stop earning my paycheck. But, as Jerry
pointed out, it will be a lot easier to hide module usage in Perl 6.
Get a code review sign off from people who aren't idiots, compile it
all to bytecode, and hand off the binary file to the schmucks who are
the problem.


Re: Ternary endweight alternative?

2007-06-29 Thread Chas Owens

On 6/29/07, raiph <[EMAIL PROTECTED]> wrote:
snip

Finally, but very importantly imo, what if there are 3 or more
alternatives?

snip

Use a hash or array (depending on the selecting data).

system((zip , )<$?OS>);
system({win32=>'cls', linux=>'clear', other=>'nuke'}<$?OS>);

Of course, this should actually be abstracted more.  What happens if
there is a fourth platform?

my %command = (
   win32 => {
   clear => 'cls',
   ls=> 'dir /b',
   dir   => 'dir',
   },
   linux => {
   clear => 'clear',
   ls=> 'ls',
   dir   => 'ls -l',
   }
);

...

system %command{$?OS};


Re: pugs bugs (or features?)

2007-09-07 Thread Chas Owens
On 9/7/07, Wim Vanderbauwhede <[EMAIL PROTECTED]> wrote:
> The following program works fine in pugs r17041 (which is the rev of
> /usr/bin/pugs on feather):
>
> my $r=\{say $x+1};
> my $x=2;
> $r();
>
> With r17041, this gives 3;
> However, on the latest pugs (r17615 or later), it gives an error:
> ***
> Unexpected "$r"
> expecting "=", "::", context, ":" or "("
> Variable "$x" requires predeclaration or explicit package name
> at pugs_var_bug.p6 line 1, column 4
> It would think that the r17041 result is correct.

You can't use variables before declaring them, think use strict.  Even
if strict weren't in effect this code should not work since the $x in
the closure is not the one created after the closure:

perl -le 'my$r=sub{print $x+1};my $x = 2;$r->()'

That Perl 5 code prints 1 because undef plus one is one.

> ---
> There is also a scoping issue in r17615:
>
> my $v=1;
> if ($v) {
> map ->$v {$v},(2);
> } else {
> $v;
> }
>
> With r17041, this gives 2; With r17615 it gives an error:
> ***
> Unexpected end of input
> expecting "::"
> Variable "$v" requires predeclaration or explicit package name
> at pugs_scoping_bug.p6 line 6, column 15
>
> Now, if I change $v to $x in the pointy sub, it works fine.

This definitely seems like a bug.  It looks like $v is being destroyed
after it is used in the map.  It is my understanding that the $v in
the map should be treated like a temp variable (its old value should
return after the map).


Re: What is the origin of the nickname, "Texas quotes"?

2007-12-07 Thread Chas. Owens
On Dec 7, 2007 5:46 PM, Thom Boyer <[EMAIL PROTECTED]> wrote:
snip
>  But, back to Perl I didn't get an answer to my follow-up question:
>
>  So, it's because <> is so much bigger than «this», "this", or 'this'?
snip

That is my take on it: "Everything is bigger in Texas", even French Quotes.

snip
>  Numbers are like people; torture them enough and they'll tell you anything.
snip

Are you accusing me of territorial-waters-boarding?


Re: What is the origin of the nickname, "Texas quotes"?

2007-12-07 Thread Chas. Owens
On Dec 7, 2007 11:50 AM, Larry Wall <[EMAIL PROTECTED]> wrote:
> On Thu, Dec 06, 2007 at 12:12:36PM -0700, Thom Boyer wrote:
> > Larry Wall wrote:
> >> Good guess, but no.  It comes from the fact that Texas always bragged
> >> about how they were the largest state in the union, and had the biggest
> >> everything, including ten-gallon hats.  That was before we added Alaska.
> >> Now if they pull that stunt we offer to carve Alaska up into 4 states,
> >> in which case Texas would be the 5th largest.
> >>
> >> But Texans still like to think big, and we love 'em all to pieces for it.
> >> Especially Patrick these days... :)
> >>
> >> Larry
> >>
> > So, it's because <> is so much bigger than «this», "this", or 'this'?
> >
> > By the way, as a native Texan, I find offensive your claim that Texas*4 <
> > Alaska. The truth is hurtful enough:
> >Texas*2.1787 = Alaska
> > I had to carry it out to 4 decimal places so I wouldn't have to round the
> > last digit UP.
> >
> > :-)
>
> My claim is just that that's how the standard joke goes.  (I suspect
> the 4x probably arises from casual inspection of a mercator projection,
> where Alaska does look four times bigger.  But then, that's the fault
> of Texas for being closer to the equator. :)
>
> Larry
>

Like a true Texan* (grin), he skewed the numbers to make Texas look
bigger than it is.  It is between 2.4** and 2.5*** when you include
inland bodies of water, and when you include territorial waters it may
well have a 4 to 1 ratio with Texas (since it is effectively a very
large peninsula and Texas has a relatively small coastline).  I have
placed calls to both Alaska's CGIN and NOAA NOS* and they are
trying to find the area of the two states' territorial waters for
me**.  I was not able to find a Texas resource, but so far it
looks like the NOAA NOS and OCS*** are going to be the best bets
anyways.

* I am resident of Virgina, so I have no axe to grind; I am just
looking for a definitive answer.
** random sites on the Internet
*** wikipedia: 663267/261797 = 2.5335
 Census and Geographic Information Network:
http://almis.labor.state.ak.us/?PAGEID=67&SUBID=114
* National Ocean Service: oceanservice.noaa.gov
** Yes, I am anal, insane, and on narcotics (I had my wisdom teeth
extracted this morning)
*** Office of Coast Survey:
http://oceanservice.noaa.gov/programs/cs/welcome.html


Re: Bite-sized Tasks for the Interested (was Re: Standards bearers)

2007-12-13 Thread Chas. Owens
On Dec 13, 2007 6:30 PM, ispyhumanfly <[EMAIL PROTECTED]> wrote:
snip
> This task list is available via an rss feed.  I think this will help
> solve the problem in the way you described.
snip

What is the URL for this feed?


Re: Bite-sized Tasks for the Interested (was Re: Standards bearers)

2007-12-13 Thread Chas. Owens
On Dec 13, 2007 4:37 PM, ispyhumanfly <[EMAIL PROTECTED]> wrote:
> Hello list,
>
> I've created a group on www.hiveminder.org for Perl6 collaborative
> task tracking and management.  I've done some thinking and I've come up
> with a way in which I would like to maintain this group, its organizers
> and its members.
snip

hiveminder.org doesn't seem to exist, do you mean hiveminder.com?


Re: Concerns about "{...code...}"

2007-12-21 Thread Chas. Owens
On Dec 21, 2007 4:51 PM, Dave Whipp <[EMAIL PROTECTED]> wrote:
> Larry Wall wrote:
>
> > As for the Q base form, it's not really there so much for end-use,
>
> For an operator not intended for end use, it has a remarkable low
> Huffman rank...
>

But since it will be combined with adverbs like

my $str = Q :b :s /Hello $name\n/;

it needs to be short.   Q is just one part of a larger expression that
is meant to be taken as a whole.


Re: not wanting something

2009-01-06 Thread Chas. Owens
On Tue, Jan 6, 2009 at 10:12, Patrick R. Michaud  wrote:
snip
> Also, Perl 6 already provides a 'digit' rule by default, although
> it's digits in the Unicode sense as opposed to simply the 0..9
> sequence.
snip

Please tell me that Perl 6 isn't going to make that same error the
Perl 5.8 did.  Or at least tell me that it will provide two classes:
Unicode digit and digit you can do math with.  Unicode digit is nearly
worthless, and people keep confusing it for digit you can do math
with.  Shouldn't the Huffman encoding principle come into play and \d
be reserved for [0-9] and \p{IsDigit} (or the equivalent Perl 6
construct) be used for matching Unicode digits?


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: what should be the default extension?

2008-01-07 Thread Chas. Owens
On Jan 7, 2008 1:34 PM, Richard Hainsworth <[EMAIL PROTECTED]> wrote:
snip
> Definitely a good idea for the implementation / implementors to decide
> how to get a resource magically.
>
> But ...
> I have run into situations where I wanted to have more control over
> where specific resources were located, at least temporarily. And I could
> not find a simple way to do it in perl5.
>
> Or is there some other magic I have not understood (and there is a lot I
> dont understand) that would allow for this as perl6 is already specified?
snip

I think you want the PERL5LIB environmental variable for Perl 5.  I
assume there will be a similar variable for Perl 6.

snip
> True. Yet this implies all Perl programmers write for platform
> independence. My experience has been that when I was using perl under
> windows, I had to use ppm made available by ActiveState. Whereas for
> Linux, I could use CPAN directly. This indicates a conversion procedure
> and rules of best practice for software whose authors want it to be used
> cross-platform.
> 
snip

There is nothing that prevents you from using CPAN with ActivePerl on
Win32 systems.  Both nmake* and the compiler** are available from
Microsoft for free and you only need the compiler for XS based
modules.  The ppm packages are just for your convenience.

* http://support.microsoft.com/default.aspx?scid=kb;en-us;Q132084
** http://www.microsoft.com/express/download/#webInstall


Re: Easy question: what is a "list comprehension" ?

2008-04-05 Thread Chas. Owens
On Sat, Apr 5, 2008 at 3:07 PM, John M. Dlugosz
<[EMAIL PROTECTED]> wrote:
> What is a "list comprehension"?  I've seen that term bantered around here.
snip

It is like a list, for loop, and grep all rolled up into one.  Here is
what it looks like in Python:

S = [2*x for x in xrange(100) if x**2 > 3]


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Nomenclature Question - BEGIN etc.

2008-04-09 Thread Chas. Owens
On Thu, Apr 10, 2008 at 1:31 AM, John M. Dlugosz
<[EMAIL PROTECTED]> wrote:
> Consider the words that may be used to introduce a block for a special
> purpose, like
>
>  BEGIN
>  END
>  INIT
>  CATCH
>  etc.
>
>  What do you call those?  They are not even "special named blocks" because
> that is not the block name (that already means something).
snip

The perldocs call them "Five specially named code blocks", The Camel
names them individually (e.g. BEGIN block).  How about phase blocks?
They control in what phase of compilation/runtime the code runs in.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Nomenclature Question - BEGIN etc.

2008-04-09 Thread Chas. Owens
On Thu, Apr 10, 2008 at 2:16 AM, Mark J. Reed <[EMAIL PROTECTED]> wrote:
> JMD> Consider the words that may be used to introduce a block for a special
>  JMD> purpose, like
>  JMD>
>  JMD>  BEGIN
>  JMD>  END
>  JMD>  INIT
>  JMD>  CATCH
>  JMD>  etc.
>  JMD>
>  JMD>  What do you call those?
>
>  Well, lessee.  The Common Lisp spec calls them "situations" in the
>  definition of (eval-when)...
>
>  JMD> They are not even "special named blocks" because
>  JMD> that is not the block name (that already means something).
>
>  Now you've lost me.  I was pretty sure that was the block name.  AIUI,
>  you can give arbitrary names to any block, and these names function
>  the same way (i.e. can be used in flow control statements), but they
>  also happen to control when the block is actually evaluated.
>
>  CO>  The perldocs call them "Five specially named code blocks", The Camel
>  CO>  names them individually (e.g. BEGIN block).  How about phase blocks?
>  CO>  They control in what phase of compilation/runtime the code runs in.
>
>  I don't know, "phase" sounds too specific to me.  Does the catching of
>  an exception really bring us into a new phase of execution?  What
>  about the LAST time through a loop?  etc.
>
>
>  --
>  Mark J. Reed <[EMAIL PROTECTED]>
>

It looks like they already have a name in S04: Closure traits*.

* http://dev.perl.org/perl6/doc/design/syn/S04.html#Closure_traits

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Nomenclature Question - BEGIN etc.

2008-04-09 Thread Chas. Owens
On Thu, Apr 10, 2008 at 2:29 AM, Mark J. Reed <[EMAIL PROTECTED]> wrote:
> On Thu, Apr 10, 2008 at 2:26 AM, Chas. Owens <[EMAIL PROTECTED]> wrote:
>  >  It looks like they already have a name in S04: Closure traits*.
>  >
>  >  * http://dev.perl.org/perl6/doc/design/syn/S04.html#Closure_traits
>
>  I don't know, it seems like any value might happen to both be a
>  closure and have traits, which aren't necessarily these particular
>  ones...
snip

How about Control Closure then?


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Decrement of Numbers in Strings (Was: [svn:perl6-synopsis] r14460 - doc/trunk/design/syn)

2008-04-23 Thread Chas. Owens
On Thu, Apr 24, 2008 at 1:20 AM, Ph. Marek <[EMAIL PROTECTED]> wrote:
> On Mittwoch, 23. April 2008, Larry Wall wrote:
>  > On Wed, Apr 23, 2008 at 04:03:01PM +0100, Smylers wrote:
>  > : The algorithm for increment and decrement on strings sounds really good,
>  > : however I'm concerned that dealing with all that has made the common
>  > : case of integer decrement a little less intuitive where the integer
>  > : happens to be stored in a string, for example in this case:
>  > :
>  > :perl -wle '$a = 10; $b = shift; $a--; $b--; print "$a $b"' 10
>  > :
>  > : Perl 5 prints "9 9", but Perl 6 will print "9 09".
>  >
>  > On the other hand, "09" has the advantage of still having the numeric
>  > value 9.  But the converse is not true if the user was expecting a
>  > string decrement, since decrementing "10" in Perl 5 to get 9 is also
>  > counterintuitive if you were expecting "09".  So Perl 5 just punts,
>  > which is the third option.  In any case, there's always something
>  > to explain to a beginner.  But I think in Perl 6 we're leaning more
>  > toward preserving information than Perl 5 did.
>  But that doesn't really work for loops.
>
>  Imagine (excuse my perl5)
> $a = "100";
> $a-- for(1 .. 40);
>
>  So ($a eq "060")?
>  Then you'll have the problem that this gets (or might get) interpreted as
>  octal somewhere; if not in perl6 directly (because of different base
>  specifications), you're likely to get problems when passing that to other
>  programs, eg. via system().
snip

If you are certain to want a number then you either need to say

$a = +("100");

or use +($a) when passing it.
-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: negative index in perl6 array

2009-06-19 Thread Chas. Owens
On Sat, Jun 20, 2009 at 00:58, Aruna Goke wrote:
> is negative index not allowed in perl6?
>
> i tried
>
> my @test = (1 .. 20);
> @test[-1].say;
>
> OUTPUT
> Use of uninitialized value
>

You have to say

@test[*-1].say;

now

http://perlcabal.org/syn/S09.html#Negative_and_differential_subscripts

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: negative index in perl6 array

2009-06-20 Thread Chas. Owens
On Sat, Jun 20, 2009 at 02:49, Aruna Goke wrote:
> Chas. Owens wrote:
>>
>> On Sat, Jun 20, 2009 at 00:58, Aruna Goke wrote:
>>>
>>> is negative index not allowed in perl6?
>>>
>>> i tried
>>>
>>> my @test = (1 .. 20);
>>> @test[-1].say;
>>>
>>> OUTPUT
>>> Use of uninitialized value
>>>
>>
>> You have to say
>>
>> @test[*-1].say;
>>
>> now
>>
>> http://perlcabal.org/syn/S09.html#Negative_and_differential_subscripts
>>
> Thanks Chas,
>
> however, i have been trying to run the example of Mixing subscripts under
> S09.
>
> can you give me an example of using the Mixing subscripts?
>
> goksie
>

Hmm, I can't get [user-defined array indexes][1] working, and those
are a prerequisite for mixing subscripts (you can't mix normal and
user-defined indexes if you can't create user-defined indexes).  I
took a quick look at the tests and couldn't even find a test for
user-defined array indexes.

[1] : http://perlcabal.org/syn/S09.html#User-defined_array_indexing

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: A few questions

2009-07-11 Thread Chas. Owens
On Sat, Jul 11, 2009 at 22:02, Minimiscience wrote:
> I tried to find the answers to these in the Synopses, but I couldn't.  Plan
> B is to ask the mailing list.
>
>  - What does the "first" method/subroutine return when no elements of the
> list match?  Does it return the empty list?  Does the return value count as
> undefined/failure?

from http://perlcabal.org/syn/S32/Containers.html
grep takes a list or array of values and returns a lazily evaluated list
comprised of all of the values from the original list for which the $test
smart-matches as true.
...
first works exactly like grep but returns only the first matching value.

Since grep is defined as returning a list of matching elements and first is
defined as being the same as grep, I would say that it returns an empty list
if nothing matches.  The empty list is one of the false values.

>
>  - What type is the $buf argument to the IO::Readable::read method supposed
> to be?  Should it be a Buf, and, if so, does the size of the Buf's elements
> matter?  How would one indicate a desired element size when reading to an
> uninitialized Buf?  A similar question also applies to IO::Writeable::write.
>  (Also, "Writable" is misspelled.)

from http://perlcabal.org/syn/S32/IO.html#IO%3A%3AReadable

It is important to realize that this is "raw" read. You're going to have
plain octets stored in $buf, if this is actually encoded data, you're
going to need to encode it later, or use "getc" or other
IO::Readable::Encoded methods.

Given that it claims that $buf will will contain plain octets, $buf should
be a Buf8.

>
>  - How does one get/set the number/size of elements in a Buf object?

No idea, I am not certain it has been defined yet.

>
>  - Exactly what happens if & when a call to open() fails?  Is an exception
> thrown, and, if so, how does one catch it?

The open function does throw an exception, and you catch it with try:

#!perl6

use v6;

my $fh;
try {
$fh = open "foo.txt";
CATCH {
say "oops, file doesn't exist"
}
};

say "made it";

>
>  - How does one declare multiple variables of the same type with a single
> "my" statement?  Is it "my Int ($x, $y);", "my(Int $x, Int $y);", or
> something else?  Are the parentheses still necessary when declaring more
> than one variable?  What about when initializing more than one variable?

At least currently, only

my Int $x;
my Int $y;

works.

>
>  - Is there some sort of shortcut (e.g., of the form ".‽method") for calling
> a method on an object if the object is defined and returning undef if it is
> not defined?  I was hoping that ".?method" could do this, but it doesn't
> seem to (in Rakudo, at least).

Not a clue.

>
> Thank you in advance,
>        Minimiscience



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: hash slice failed ?

2009-07-18 Thread Chas. Owens
On Fri, Jul 17, 2009 at 18:50, Marc Chantreux wrote:
> hello,
>
> this is a simple code i wrote for test:
>
> -
>
> my %foo = < a 12 b 34 c 45 >;
> my @a = < a >;
> my $c = 'c';
> say %foo.keys.join('/');  # b/c/a
> say @a[0];                # a
> say %foo<< @a[0] $c >>.join('/');
>
> -
>
> on the last line, i expected: '12/45' but had
>
> # stdout: /45
> # stderr: Use of uninitialized value
>
> both rakudo and parrot where just upgraded. Did i make it wrong ?
>
> regards
> marc
>

It looks like array dereferencers don't interpolate currently in
double quotish strings, so you were trying to look up '@a[0]' in the
hash.  This is likely a bug a Rakudo.  I think S02 says that "@a[0]"
should be interpolated and that "@a[]" should be interpolate the way
"@a" does in Perl 5).  You can currently say

say %foo<< {...@a[0]} $c >>.join('/');

or

say %f...@a[0], $c}.join('/')

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Annoying list user -- again

2009-11-22 Thread Chas. Owens
He/she showed up on the Perl Beginners list a while ago as well.  I
created a special bit bucket for him/her in my email client.

On Sun, Nov 22, 2009 at 14:14, Carl Mäsak  wrote:
> I'd like to point out that the address di...@mail.ua is back on this
> list, sending out annoying automated messages about whitelisting to
> anyone who posts to it.
>
> It's up to the list admins, but I for one wouldn't be too disappointed
> if this member was booted from the list. If memory serves me, this is
> the third time this happens for this particular member on p6u.
>
> // Carl
>



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Q: Is there a reason why I can't do this?

2010-12-27 Thread Chas. Owens
On Mon, Dec 27, 2010 at 15:46, Daniel Carrera  wrote:
> Hello,
>
> Looking at the first example in "Using Perl6", I have:
>
> if $r1 > $r2 {
>    %matches{$p1}++;
> } else {
>    %matches{$p2}++;
> }
>
> I was thinking that it should be possible to make this more compact, but the
> two ideas I tried didn't work:
>
> # Idea 1 gives: Unable to parse postcircumfix:sym<{ }>, couldn't find final
> '}'
> %matches{  $r1 > $r2 ? $p1 : $p2 }++;
>
> # Idea 2 gives: Unable to parse blockoid, couldn't find final '}'
> $r1 > $r2 ? { %matches{$p1}++ } : { %matches{$p2}++ };
>
>
> Is there a way to make something along these lines work?
>
> Daniel.
> --
> No trees were destroyed in the generation of this email, but a large number
> of electrons were severely inconvenienced.
>

The [conditional operator][1] is now spelled test ?? true !! false not
test ? true : false.

 [1] : http://perlcabal.org/syn/S03.html#Conditional_operator_precedence

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Q: Is there a reason why I can't do this?

2010-12-27 Thread Chas. Owens
On Mon, Dec 27, 2010 at 15:55, Daniel Carrera  wrote:
> On Mon, Dec 27, 2010 at 9:49 PM, Chas. Owens  wrote:
>>
>> The [conditional operator][1] is now spelled test ?? true !! false not
>> test ? true : false.
>
> Thanks!
> Now the following code works:
> %matches{  $r1 > $r2 ?? $p1 !! $p2 }++;
>
> I'm still having trouble with the other alternative:
> $r1 > $r2 ?? { %matches{$p1}++ } !! { %matches{$p2}++ };
> Now the problem is that %matches is empty. I'm not sure why. Maybe you can't
> have code blocks inside ?? ... !! ...
> Daniel.
> --
> No trees were destroyed in the generation of this email, but a large number
> of electrons were severely inconvenienced.
>

{ } by itself creates a lambda (i.e. an anonymous function), so it may
be that you are returning an anonymous function that never gets
executed.  Try using parentheses instead of braces.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Q: Is there a reason why I can't do this?

2010-12-27 Thread Chas. Owens
On Mon, Dec 27, 2010 at 16:00, Chas. Owens  wrote:
> On Mon, Dec 27, 2010 at 15:55, Daniel Carrera  wrote:
>> On Mon, Dec 27, 2010 at 9:49 PM, Chas. Owens  wrote:
>>>
>>> The [conditional operator][1] is now spelled test ?? true !! false not
>>> test ? true : false.
>>
>> Thanks!
>> Now the following code works:
>> %matches{  $r1 > $r2 ?? $p1 !! $p2 }++;
>>
>> I'm still having trouble with the other alternative:
>> $r1 > $r2 ?? { %matches{$p1}++ } !! { %matches{$p2}++ };
>> Now the problem is that %matches is empty. I'm not sure why. Maybe you can't
>> have code blocks inside ?? ... !! ...
>> Daniel.
>> --
>> No trees were destroyed in the generation of this email, but a large number
>> of electrons were severely inconvenienced.
>>
>
> { } by itself creates a lambda (i.e. an anonymous function), so it may
> be that you are returning an anonymous function that never gets
> executed.  Try using parentheses instead of braces.
>
> --
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the ability to read.
>

Or better yet, don't use anything.  Since ++ has higher precedence
than ??!!, it doesn't need to any parentheses:

$r1 > $r2 ?? %matches{$p1}++ !! %matches{$p2}++ ;

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Q: Is there a reason why I can't do this?

2010-12-27 Thread Chas. Owens
On Mon, Dec 27, 2010 at 18:18, Daniel Carrera  wrote:
> On Mon, Dec 27, 2010 at 10:03 PM, Moritz Lenz wrote:
>
>> or
>>
>> my $closure = $r1 > $r2 ?? { %matches{$p1}++ } !! { %matches{$p2}++ };
>> # invoke it
>> $closure();
>>
>
>
> That's very cool. Perl 6 is a functional language with lambdas and
> everything.
>
> Daniel.
> --
> No trees were destroyed in the generation of this email, but a large number
> of electrons were severely inconvenienced.
>

Perl 5 has lambdas as well:

my $lambda = sub { print "hello $_[0]\n"; };

$lambda->("world");

Perl 6 just has lots of short cuts that make them nicer.  Like the ^ twigil:

my $lambda = { say "hello $^name" };

$lambda("world");



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Q: Is there a reason why I can't do this?

2010-12-27 Thread Chas. Owens
On Mon, Dec 27, 2010 at 18:49, Daniel Carrera  wrote:
snip
> That's cool. Thanks. I notice it works on numbers and string literals:
> "hello".WHAT   # Str()
> 3.WHAT         # Int()
> 3.3.WHAT       # Rat()
> pi.WHAT        # Num()
> (1+3i).WHAT    # Complex()
>
> But it seems to give very inconsistent results when applied to functions:
> print.WHAT  # Bool()
> say.WHAT    # [blank]
> sin.WHAT    # [error]
snip

That is because you are calling the WHAT on the function's return
value, not on the function itself.  For instance,

{ 5 }().WHAT;
{ "foo" }().WHAT;

will retrun Int() and Str() because that is what those lambdas return, but

{ 5 }.WHAT;

returns Block(), because that is what it is.  Similarly,

sub f { 5 }
&f.WHAT;

returns Sub(), and

&say.WHAT

returns Multi() because that is what they are.

snip
>> This might not have helped you had you not realized that {%matches{$p1}++}
>> is a term.  However, if you keep in mind that TTIAR is always a syntax error
>> in Perl6, then if your code is compiling, whatever is between ?? and !! must
>> be a single term.
>>
>> It's really the TTIAR thing that makes reading Perl6 so incredibly
>> predictable, I think.
>
>
> What is TTIAR?
snip

It is an error to have Two Terms In A Row.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Q: Is there a reason why I can't do this?

2010-12-27 Thread Chas. Owens
On Mon, Dec 27, 2010 at 19:41, Daniel Carrera  wrote:
snip
> Hmm... I think this will only make sense to me if I ask you to define what a
> "term" is, but I am sure that this term (pun intended) is difficult to
> define. In particular, if a number like 5 is a term, then I would think that
> the following expression contains four terms:
> 2 > 3 ?? 5 !! 6
> I figure that 2, 3, 5 and 6 are all terms. Or how about:
> print 5 if 4;
> I'd think that if 5 is a term, then so is 4.
snip

All of your examples are in fact terms.  A term is a thing that is
considered one unit.  So, numbers, strings, and variables are all
obviously terms.  A function or method call that includes parentheses
is also a term.  But parentheses can create terms out of expressions,
so, for instance, (5 + 4) is a term (that happens to contain a term,
an operator, and a another term).  In the [order of operations][1] you
will find that terms have the highest precedence, this is why (5+5)*2
is 20, not 15.

snip
> Indeed, it is. Strange. I would have thought that print, with no arguments,
> would give me an error like with "sin". And why does "print" return True?
> What's "True" about it?
snip

It successfully printed nothing.  It would return Failure if it failed to print.

>From [S32][2]:
Stringifies each element, concatenates those strings,
and sends the result to the output. Returns Bool::True
if successful, Failure otherwise.

snip
> Interesting. I imagine that Multi() means that the function has multiple
> definitions. For example, I expect that "sin" has one implementation for
> floats and another for complex numbers.
snip

Yes, Multi() means it is a multimethod.  Multimethods [are routines
that can have multiple variants that share the same name, selected by
arity, types, or some other constraints.][3]

 [1] : http://perlcabal.org/syn/S03.html#Operator_precedence
 [2] : http://perlcabal.org/syn/S32/IO.html#multi_print_(*...@list_-->_Bool)
 [3] : http://perlcabal.org/syn/S06.html#Routine_modifiers

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Q: Is there a reason why I can't do this?

2010-12-28 Thread Chas. Owens
On Tue, Dec 28, 2010 at 05:13, Daniel Carrera  wrote:
> On Tue, Dec 28, 2010 at 5:27 AM, yary  wrote:
>>
>> On Mon, Dec 27, 2010 at 8:50 PM, Daniel Carrera 
>> wrote:
>> >
>> > So TTIR just means that any two terms must be separated by something,
>> > like
>> > an operator (2+5). Which basically is common sense and I'm actually
>> > surprised to hear that in Perl 5 you could have two terms one after the
>> > other with nothing in between.
>>
>> Very common example from Perl 5:
>>  print $filehandle "Here is a line that goes to some file";
>>
>> Note that there is no operator between $filehandle and the string.
>
>
> Thanks. It's funny... I've done that a thousand times and I didn't think of
> it. I just Googled and found the Perl 6 way to print to a file handle:
> $filehandle.print("Hello world\n");
> $filehandle.say("Hello world");
snip

[Indirect object][1] notation is still in Perl 6; it just got an
unambiguous syntax:

print $filehandle: "Hello world";

 [1]: http://perlcabal.org/syn/S12.html#line_274

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Questions for Survey about Perl

2010-12-29 Thread Chas. Owens
On Wed, Dec 29, 2010 at 09:03, Moritz Lenz  wrote:
snip
> What do you think about the relation between 5 and 6
>  * I don't
>  * Perl 6 hurts Perl 5
>  * Perl 5 benefits from Perl 5
>  * The two are mostly independent
snip

As for the third option, I think Perl 5 is hurt by Perl 5, but
benefits from Perl 6.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.


Re: Questions for Survey about Perl

2010-12-31 Thread Chas. Owens
On Wed, Dec 29, 2010 at 21:39, Xue, Brian  wrote:
> I want to adding one more answer about what are people waiting for before they
> start using Perl 6.
>
> There hasn't an official release of PERL6.0, just Rakudo. I'm afraid of 
> Rakudo is cancelled, I don't want to make my product based on an uncertainty 
> matter.
snip

This shows a fundamental misunderstanding of what Perl 6 is.  As far
as I know there will never be a release of Perl 6.0 (it definitely
won't be PERL6.0).  Perl 6 is a specification and a set of tests.  Any
program that can pass the test suite and conforms to the specification
IS a Perl 6.  Right now the program that passes the most tests and
conforms most closely to the specification is Rakudo.



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.