noreply | 4 May 2011 21:35

[perl6/specs] a29e38: [S32/Exceptions] move %.payload into a separate cl...

Branch: refs/heads/master
Home:   https://github.com/perl6/specs

Commit: a29e38794ae5a388ca25af482a851273ed103c81
    https://github.com/perl6/specs/commit/a29e38794ae5a388ca25af482a851273ed103c81
Author: Moritz Lenz <moritz <at> faui2k3.org>
Date:   2011-05-04 (Wed, 04 May 2011)

Changed paths:
  M S32-setting-library/Exception.pod

Log Message:
-----------
[S32/Exceptions] move %.payload into a separate class, based on feedback by sorear++

z3r0_f4ct0r | 3 May 2011 16:47
Picon

Perl6/Catalyst on Cloud Foundry?

Any thoughts on Cloud Foundry http://www.cloudfoundry.org/ and getting Perl6/Catalyst to run on it?

Where would Parrot/LLVM fit in?

What about Perl 6 package managers (similar to RubyGems)?

Thanks,
Juan
Carl Mäsak | 6 May 2011 22:25
Picon
Gravatar

Base conversion: not enough rope

S02:3185-3280 does a nice job of explaining what can and cannot be
done with the radix syntax (i.e. :2<1010> etc). I'm left with two
questions, however:

* If :2<1010> is the way to way to "interpret" a string as a number in
base two, giving the number 10 -- what's the way to go in the other
direction?

* What's the way to interpret a number of some *parameterized* base $r
? The syntax :$r<123> is legal, but doesn't have anything to do with
base conversion.

Both of these concerns have come up in the context of trying to solve
practical problems in Perl 6. The radix conversion syntax is nice, but
it feels like something is missing in the above two areas. Maybe a
generalized builtin or two?

// Carl

Michael G Schwern | 7 May 2011 07:45
Picon
Favicon
Gravatar

eval should throw an exception on compile error

I was just playing around with eval, trying to figure out if you can define an
operator overload at runtime (seems you can't, good) and noticed this in the
spec... [1]

    "Returns whatever $code returns, or fails."

How does one get the compile error from an eval?  What's the equivalent to $ <at> ?
 I don't see anything in the eval tests [2] that's checking for the error,
just that it returned false.

In addition, I'm surprised that eval doesn't throw an error when it fails.

    try { eval $code; CATCH { ... } }

Using eval STRING in Perl 5 is pretty rare, and should hopefully be rarer in
Perl 6 than Perl 5.  While it can be used as a "does this compile" check, it's
overwhelmingly used with the expectation that the code will compile and so it
is an exception if it does not.  More pragmatically, this resolves the problem
of $ <at>  by putting it into an exception rather than a side global.

It also resolves this trap:

    if eval $code {
        say "code returned true";
    }
    else {
        # this will also happen if $code fails to compile
        say "code returned false";
    }

(Continue reading)

Stefan O'Rear | 7 May 2011 09:27
Picon

Re: eval should throw an exception on compile error

On Sat, May 07, 2011 at 03:45:02PM +1000, Michael G Schwern wrote:
> I was just playing around with eval, trying to figure out if you can define an
> operator overload at runtime (seems you can't, good) and noticed this in the
> spec... [1]
> 
>     "Returns whatever $code returns, or fails."
> 
> How does one get the compile error from an eval?  What's the equivalent to $ <at> ?
>  I don't see anything in the eval tests [2] that's checking for the error,
> just that it returned false.

The error goes into $!, which is automatically lexical.

What you're seeing is a bug-of-omission in Rakudo; if $! is not checked by
the end of the scope, Perl 6 is supposed to raise an immediate exception.

> In addition, I'm surprised that eval doesn't throw an error when it fails.
> 
>     try { eval $code; CATCH { ... } }
> 
> Using eval STRING in Perl 5 is pretty rare, and should hopefully be rarer in
> Perl 6 than Perl 5.  While it can be used as a "does this compile" check, it's
> overwhelmingly used with the expectation that the code will compile and so it
> is an exception if it does not.  More pragmatically, this resolves the problem
> of $ <at>  by putting it into an exception rather than a side global.
> 
> It also resolves this trap:
> 
>     if eval $code {
>         say "code returned true";
(Continue reading)

Moritz Lenz | 7 May 2011 09:30
Gravatar

Re: Base conversion: not enough rope

On 05/06/2011 10:25 PM, Carl Mäsak wrote:
> S02:3185-3280 does a nice job of explaining what can and cannot be
> done with the radix syntax (i.e. :2<1010> etc). I'm left with two
> questions, however:
> 
> * If :2<1010> is the way to way to "interpret" a string as a number in
> base two, giving the number 10 -- what's the way to go in the other
> direction?

Sounds like a job for sprintf of fmt.

> * What's the way to interpret a number of some *parameterized* base $r
> ? The syntax :$r<123> is legal, but doesn't have anything to do with
> base conversion.

FWIW in NQP you can cheat and reuse the internal function of the compiler:

09:24 < moritz> nqp: use NQPHLL; say(HLL::Actions::string_to_int('14', 8))
09:24 <+p6eval> nqp: OUTPUT«12␤»

I think in the end it should come down to exposing more number parsing
primitives as functions or methods.

On a related note, we had this discussion about a generic string parser
that would parse any Perl 6 literals, but I don't know if it ever got
specced.

If such a function exists, you could call literal(":{$base}<123>"), and
have no fear of code injection like you'd have to have with eval.

(Continue reading)

Moritz Lenz | 7 May 2011 09:33
Gravatar

Re: eval should throw an exception on compile error

On 05/07/2011 07:45 AM, Michael G Schwern wrote:
> I was just playing around with eval, trying to figure out if you can define an
> operator overload at runtime (seems you can't, good) and noticed this in the
> spec... [1]
> 
>     "Returns whatever $code returns, or fails."
> 
> How does one get the compile error from an eval? 

It's in $!, like all other errors.

> I don't see anything in the eval tests [2] that's checking for the error,
> just that it returned false.
> 
> In addition, I'm surprised that eval doesn't throw an error when it fails.

I agree that eval shouldn't be catching errors, that's what try { } /
CATCH are for (and i know that other #perl6 regulars things similarly).

I dimly recall that Larry had an objection, but I can't remember what it
was :(

Cheers,
Moritz

noreply | 7 May 2011 12:57

[perl6/specs] 03f8d3: [S32/Numeric] spec Real.base

Branch: refs/heads/master
Home:   https://github.com/perl6/specs

Commit: 03f8d38e1b5832b1fa6f93a613692e98c39d3048
    https://github.com/perl6/specs/commit/03f8d38e1b5832b1fa6f93a613692e98c39d3048
Author: Moritz Lenz <moritz <at> faui2k3.org>
Date:   2011-05-07 (Sat, 07 May 2011)

Changed paths:
  M S32-setting-library/Numeric.pod

Log Message:
-----------
[S32/Numeric] spec Real.base

noreply | 7 May 2011 13:12

[perl6/specs] bf245c: [S32/Numeric] added $base condition

Branch: refs/heads/master
Home:   https://github.com/perl6/specs

Commit: bf245c0d16e1758515c32122e90d6ecef9bf6615
    https://github.com/perl6/specs/commit/bf245c0d16e1758515c32122e90d6ecef9bf6615
Author: Carl Masak <cmasak <at> gmail.com>
Date:   2011-05-07 (Sat, 07 May 2011)

Changed paths:
  M S32-setting-library/Numeric.pod

Log Message:
-----------
[S32/Numeric] added $base condition

$base in the conversion method .base must be at least 2.

noreply | 7 May 2011 13:26

[perl6/specs] 9019a8: [S32/Numeric] Real.base: $base <= 36, upper case i...

Branch: refs/heads/master
Home:   https://github.com/perl6/specs

Commit: 9019a8e14063b1d89b3fd30192ab9eab1272d20b
    https://github.com/perl6/specs/commit/9019a8e14063b1d89b3fd30192ab9eab1272d20b
Author: Moritz Lenz <moritz <at> faui2k3.org>
Date:   2011-05-07 (Sat, 07 May 2011)

Changed paths:
  M S32-setting-library/Numeric.pod

Log Message:
-----------
[S32/Numeric] Real.base: $base <= 36, upper case in result


Gmane