Re: run-once code
David Storrs wrote: Given this code: if ( some_expensive_lookup_function() >= $MAX_RECORDS ) { mark_that_we_have_reached_max_records(); return; } After I enter that block once, I never want to evaluate the condition again--I want the code to completely disappear from the bytecode (or, at least, be jumped around). How would I do that in Perl 6? How about $test = sub { if ( some_expensive_lookup_function() >= $MAX_RECORDS ) mark_that_we_have_reached_max_records(); $test = sub{}; }; Then call &$test() as needed; R. -- Richard Nuttall Nuttall Consulting www.nuttall.uk.net
Re: Exegesis 7: Fill Justification
Damian Conway wrote: Gregor N. Purdy wrote: In the section "He doth fill fields..." we see an example of Fill Justification where two spaces fit between every word. This doesn't give us an idea of how spaces are distributed if the number of spaces needed does not divide evenly into the number of interstices. Currently extra spaces are fitted into the rightmost gaps (as this seems -- to me at leats- to produce the least weird results). I've tried all sorts of other schemes but none seem as satisfactory to me. An alternative is to have "fill rightmost gaps" and "fill leftmost gaps" on alternate lines. This produces more balanced looking columns, so they don't all look heavier on the left. -- Richard Nuttall
Re: Default program
Therefore, I recommend that, when given an empty program or -e string, Perl 6 should print "Hello world!", emit a newline, and exit. I believe that this feature would be fairly trivial to implement. I cannot agree with this. In fact, if someone types "perl" on the command line without any arguments, it seems obvious to me that they are intending to begin development of a script. On the DWIM principle, shouldn't Perl then just autoload the DWIM::AI module and provide as output the script that they are intending to write ? R. -- Richard Nuttall Nuttall Consulting 01353 649878 www.nuttall.uk.net
Re: Yadda yadda yadda some more (2)
Austin Hastings wrote: Maybe this is how they'll teach perl at religious schools: #! /usr/bin/perl6 -w # # TEMPLATE.P6 -- standard template for programs at Abstemious U. # use no ...; sub usage() {...} sub main() {...} Aha, this is where the DWIM::AI module I suggested on 01-Apr comes in. Create a template like the above and then DWIM::AI::Yadda will join the dots and create the program for you ! R. -- Richard Nuttall Nuttall Consulting 01353 649878 www.nuttall.uk.net
Re: DBI v2 - The Plan and How You Can Help
- support for automatically pulling database DSN information from a ~/.dbi (or similar) file. This is constantly re-invented poorly. Let's just do a connect by logical application name and let the SysAdmins sort out which DB that connects to, in a standard way. This reminds me one one thing I hate about DB access, and that is having the DB password stored in plain text. Of course there are ways to provide some concealment, but nothing particularly good or integrated into the access. If the "connecting by logical application name" could also include some level of security access, that would be a big improvement. R.
Hyper concat ^_ ?
Will Hyper operators work on strings as well ? e.g. ('pic1','pic2','pic3') ^_ ('.jpg') or even my @images = qw( pic1 pic2 pic3) ^_ ('.jpg'); R. -- Richard Nuttall
RE: dor (was RE: General Feelings on Apoc 3 )
> Bart Lateur: > # On Thu, 4 Oct 2001 03:22:55 -0400, Michael G Schwern wrote: > # > # >Binary // > # > > # >The analogy to || is probably a bit too clever. My first reaction > # >was it's some sort of weird division operator. But it's > servicable. > # > # I think it's very cute. I think of it as a "skewed or", > which is, er, > # both what it both is, and what it looks like. > > If we have 'and', 'or' and 'xor', can we have 'dor' (defined > or) to be a low-precedence version of this? Should this be pronounced "duh" ? :-) R.
RE: Apoc 5 questions/comments
> I have no doubt that, once Perl 6 is available, we'll see a > rash of modules released in the Grammar:: namespace. > Including Grammar::Romana, > Grammar::Klingon, Grammar::Buffy, Grammer::Mispelt, and others... :-) Grammar::Python, Grammar::Ruby, Grammar::PHP ? R.
Re: Indeterminate math
[EMAIL PROTECTED] wrote: >From: Michael G Schwern [EMAIL PROTECTED] > > >>This came up at YAPC::Europe. Someone [1] wanted to know if 1/0 >>would produce a divide by zero error in Perl 6, or if it would >>return a value representing an indeterminate result (undef?) >>It would make more sense for Perl, upon being given a simple bit >>of impossible math, to return undef (like other functions do on >>failure) than to generate an error. The error seems a throwback >>to earlier days of hardwired calculators. >> >> > >The problem with returning undef is that undef numifies to zero. > Why can't it return "undef but +Inf", or "undef but NaN" for 0/0, which would then cause a warning/error/nothing, as required by pragma, following the "0 but true" that has been discussed previously. Normal numification would presumably propogate the "undef but +Inf" value. R. -- Richard Nuttall Invisible Networks DDI: 01954 206361 Tel: 01954 22 Mob: 07798 528923 Fax: 01954 206360 Web: www.invisible.uk.net
Re: Perl6 Operator List, TAKE 4
explicit radix specifications for integers: 0123- decimal 2:0110- binary [also b:0110?] 8:123 - octal [also o:123?] 16:123- hex[also h:123?] 256:192.168.1.0 - base 256 (...etc...) Could this be used to do explicit conversion between bases, and/or strings, rather than using pack/unpack/sprintf, etc. ? my $macaddr = '00022D3F7659'; my $hex = 16:$macaddr; How about $a = 'DEADBEEF'; $hexres = 16:$a + 16:FEED; print ~16:$hexres; does that give me "DEAEBDDC" ? R. -- Richard Nuttall
Re: [perl6/specs] 5277fe: Add expmod and is-prime as built-ins in Int
A quick search throws up http://primes.utm.edu/prove/prove2_3.html Which says that for/n/< 341,550,071,728,321 it is enough to test 2, 3, 5, 7, 11, 13 and 17 to be definitive (and fewer specific tries for smaller n) That also verifies the 75/25 figures mentioned below. So, depending on the implementation, the documentation should be able to be explicit about how accurate it is. R. On 21/09/2012 06:32, Stephen Pollei wrote: On Thu, Sep 20, 2012 at 9:22 PM, Martin Kealey wrote: On Thu, 20 Sep 2012, Stephen Pollei wrote: According to Wolfram, it's 75/25; so a positive result after 10 iterations leaves about a one-in-a-million chance of being composite (more precisely, one in 1048576). I'd believe wolfram over me, it's been a while since I've read Applied Cryptography by Schneier . multi method is-prime ( Int $x: Int $tries = 100) is export should also at least document that tries is never a negative number, or if it is that it has same behaviour as zero. Logically if "tries" is zero, is-prime shouldn't do any testing at all, and should always return "true". (There's a chance it might be prime!) A good built in test before you try Miller-Rabin is at least test against some of the small prime numbers 2,3,5,7,11,13 otherwise even if if tries is zero saying 42 is prime is too wrong . However if only a miller-rabin style tests are used then a value of tries being zero should always return true. If "tries" is negative, which idiom should we follow: multi method is-prime ( Int $x: UInt $tries = 100) is export I think I read somewhere that perl6 has both Int and UInt , just change the prototype multi method is-prime ( Int $x: UInt $tries = 100 where { $^n > 0 } ) is export I think I even read you can constrain it so if zero tries is completely useless you can outlaw it so document at least or change prototype to account for negative and zero values.