Buf.pm: FIFO and grammar

2010-08-11 Thread Oha

after speaking with masak, i come up with some ideas about Buf
i would like to share with you, maybe you can find them usefull

http://register.oha.it/buf.pod

HTH

Oha


Re: exponentiation of Duration's

2010-11-17 Thread Oha

On 11/17/2010 01:46 PM, Moritz Lenz wrote:

Just as a data point, in physics duration squared does exist.
On the other hand, i can see why an Instant can't be used as a linear 
value: it does not have a clear origin (or zero value).


Therefore the multiplication of two Instant may results in different 
results based on where you place the zero, unless you first convert

the Instant in a Duration (e.g. seconds since 1 jan 1970)

Oha


Re: exponentiation of Duration's

2010-11-17 Thread Oha

On 11/17/2010 02:56 PM, Carl Mäsak wrote:

Or, by Ockham, since Duration is now deprived of its only task --
making life harder for the programmer -- remove it altogether from the
language and just put a number type in its place, representing number
of seconds.
   
I could be wrong but this reminds me that a Duration could not be only 
based in seconds, but also in other units (which may automagically be 
converted to seconds) and also those seconds may be leap or not.


Maybe the point is that really the power of a Duration should not be 
performed, unless you coerce the Duration in a specific unit value?


Extending a bit more, does an Instant be specified in a TimeZone? Could 
an Instant be incremented by Day units? What happen if this increment 
change from daylight saving to normal time?


HTH

Oha


sql idea

2010-11-26 Thread Oha

Hi,

I was thinking how to abuse the p6 grammar to simplify the interface to 
SQL DBs.


- First i wanted to have a SELECT which works like a map.

- Then i wanted to use a pointy block to bind fields to variables.

- And i wanted also to make it lazy.


I come up to the following code:

my $db = FakeDBI.new;
my ($state, $dept) = active storage;

my @out := $db.SELECT:
- $username, $age, $salary {
say fetched '$username';
$username = $salary, $age;
}, 'from users where state = ? and dept = ?', 
($state, $dept);


say 2nd: , @out[1];
say 1st: , @out[0];
say 4th: , @out[3];


the fake module which make the above code to work (but do not really 
connect to a db):


class FakeDBI {

method SELECT(block, $stm, *...@binds) {
my $sig = block.signature;
my @fields = map {
$_.name ~~ /\$(\w+)/ or die invalid 
signature params: ~$_.perl;

$/[0];
}, $sig.params;

my @stm = (SELECT);
if @fields ~~ ('_') { push @stm, '*'; }
else { push @stm, join ', ', @fields; }
push @stm, $stm;

say 'DBG prepare ', join ' ', @stm, '';

gather {
say 'DBG fake execute, fetching rows...';
for john paul sara - $row {
my @data = map { $row ~ _$_ }, 
@fields;

take block.(|@data);
}
say 'DBG no more rows...';
}
}
}

and the output:

DBG prepare SELECT username, age, salary from users where state = 
? and dept = ? 

DBG fake execute, fetching rows...
fetched 'john_username'
fetched 'paul_username'
2nd: paul_username = paul_salary, paul_age
1st: john_username = john_salary, john_age
fetched 'sara_username'
DBG no more rows...
4th: Any()


I found the usage very nice, and the lazyness may be removed by 
assigning instead of binding,

so i thought i should share this little useless example, HTH!

TODO: i would like to find a way to use the Signature for table names 
(select a.foo, b.bar),

but i don't want to make it too complex, any suggestion?


Oha