Re: Name of calling program

2022-12-07 Thread Gianni Ceccarelli
On Wed, 7 Dec 2022 08:58:19 -0800
ToddAndMargo via perl6-users  wrote:

> When I am in a module (pm6), is there one of those
> fancy system variables that will tell me the
> name of calling (pl6) program?

https://docs.raku.org/language/variables#index-entry-$*PROGRAM

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: shorter way to set states in -n?

2022-07-02 Thread Gianni Ceccarelli
On 2022-07-02 Marc Chantreux  wrote:
> AFAIK about raku -n, I need 2 lines to setup a
> state with a default value
> 
>   seq 2| raku -ne '
>   state (@o, @f);
>   BEGIN @o = 0 xx 3;
>   @o.push: "ok";
>   say @o;
>   '
> 
> but is there a shorter way ?

Something feels wrong to me… From the documentation, the equivalent
perl switch, and what I can see from the Rakudo source, `raku -ne
$something` should be the same as `raku -e "for lines -> $_ is copy {
$something }"`

but while this does what I expect:

seq 2|raku -e 'for lines() -> $_ is copy {
 state @x=; @x.push($_); say @x
  }'
[a b c 1]
[a b c 1 2]

this doesn't (as you noticed):

seq 2|raku -ne 'state @x=;@x.push($_);say @x'
[1]
[1 2]

Is this a bug, or are my (our?) expectations wrong?

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: Removing ' characters

2022-01-10 Thread Gianni Ceccarelli
On Mon, 10 Jan 2022 15:41:04 +
Richard Hainsworth  wrote:

> Using REPL I got
> 
>  > my $s = '\'\''  
> ''
>  > $s.subst( / \' ~ \' (.+) /, $0)  
> Use of Nil in string context
>    in block  at  line 1

That error message (which is a bit LTA) refers to the `$0`. As
https://docs.raku.org/routine/subst#Callable shows, you need to write:

$s.subst( / \' ~ \' (.+) /, { $0 })

>  > my $t = '{}'  
> {}
>  > $t.subst( / \{ ~ \} (.+) /, $0)  
> 

This only appear to work because you're running it in the same REPL
session; the previous `subst` had the side-effect of setting `$0`
(well, it sets `$/`, but `$0` is an alias for `$/[0]`…)

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: Depreciated code????

2021-07-27 Thread Gianni Ceccarelli
On 2021-07-27 Elizabeth Mattijsen  wrote:
> So the deprecation logic is pointing at the wrong line.
> 
> Where does this RunNoShellLib.pm6 live?  It's must be something
> inside that.

Given the error message says:

> Please use exitcode and/or signal methods (status is to be
> in 2022.06) instead.

I guess the cause is a call to `Proc.status`, which has just been
deprecated in 2021.07, in favour of those two other methods.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: File::Find using a junction with exclude

2021-05-25 Thread Gianni Ceccarelli
On Tue, 25 May 2021 15:16:03 +
Andy Bach  wrote:

> > However I had to use "Int" instead of "int":
> Ah, "int" is the "lower" level, native integer and "Int" is the raku.
> An "int" is immutable or something?

It's a bug in the REPL. The example from the documentation works when
fed to the compiler directly::

  $ raku -e 'my int $x = 2⁶³-1;say ++$x;'
  -9223372036854775808

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: File::Find using a junction with exclude

2021-05-24 Thread Gianni Ceccarelli
On 2021-05-24 William Michels via perl6-users 
wrote:
> Daniel: Thank you for your confirmation on EVAL. Also, I tried parsing
> the ATOM SYMBOL character to look at classification, and this is the
> best I could do (in the Raku REPL):
> 
> > say "⚛".uniprop
> So

Not-terribly-human-friendly abbreviation for "Symbol, other", see also
https://en.wikipedia.org/wiki/Unicode_character_property#General_Category

> > say "{uniparse 'ATOM SYMBOL'}".uniprop('Alphabetic')
> False

> say '⚛'.uniprop('Symbol')
1
> say '⚛'.uniprop('Letter')
0
> say '⚛'.uniprop('Alphabetic')
False

(I feel that `False` is out of place…)

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: Weird! When legal?

2021-02-24 Thread Gianni Ceccarelli
On 2021-02-24 rir  wrote:
> It is just an odd puzzle for me that "UnknownBareId  KnownClassId"
> is accepted has the start of a valid statement.  How would such
> a statement be completed?

Let's go through a few examples::

  raku -e 'foo 1'
  ===SORRY!=== Error while compiling -e
  Undeclared routine:
  foo used at line 1

simple and clear error: syntax is correct, ``foo`` must be the name of
a sub, but it's never defined.

Closer to what you got::

  raku -e 'foo 1 2'
  ===SORRY!=== Error while compiling -e
  Two terms in a row
  at -e:1
  --> foo 1⏏ 2
expecting any of:
infix
infix stopper
postfix
statement end
statement modifier
statement modifier loop

notice the list of expected things. Did we mean ``foo 1 + 2``, ``foo
1, 2``, ``foo 1 if 2``?

Now for what you saw::

  raku -e 'foo 1 { 2; }'
  ===SORRY!=== Error while compiling -e
  Unexpected block in infix position (missing statement control word before the 
expression?)
  at -e:1
  --> foo 1⏏ { 2; }
expecting any of:
infix
infix stopper
postfix

Again, did we mean ``foo 1 ~~ { 2; }``, ``foo 1, { 2; }``, ``foo 1 if
{ 2; }``?

In all these cases, ``foo`` is presumed to be the name of a sub,
because (I think) it's at the start of the statement, and it's not a
known keyword. Then the parser tries to make sense of the following
tokens, and gets confused.

So, to answer "How would such a statement be completed?":

* with an infix (a comma, any infix operator that can take (in your
  case) a type and a block, …)
* I'm not sure what an "infix stopper" is
* a postfix (like ``if``, ``for``, ``with``…)

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: ^methods doesn't show all methods

2021-02-16 Thread Gianni Ceccarelli
On 2021-02-16 Joseph Brenner  wrote:
> But I don't see them in the list from .^methods:
> 
>   say $s.^methods;
>
>   say so $s.^methods.gist.grep(/<>/); # False

``say`` calls ``.gist``, which produces a *truncated* string
representation for long lists::

$ raku -e 'say (^1000).List'
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...)

If you grep the list itself, instead of its gist::

$ raku -e 'Set.^methods.map(*.name).grep(/keys/)>>.say'
keys

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: LTA documentation page

2021-01-06 Thread Gianni Ceccarelli
On 2021-01-06 yary  wrote:
> I have been going through quite a few contortions to look at the
> source code for installed modules in raku, and would very much like
> rakudoc to have an option similarly to perldoc -l showing the cached
> path and hashed local file names of installed modules.


zef does that::

   $ zef locate Zef
   ===> From Distribution: zef:ver<0.8.4>:auth:api<0>
   Zef => /home/dakkar/.raku/sources/65C34BD7E4A3F74D2F2637DFFF9507F33639635A

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: Nested `whenever` (was Re: Help with bug)

2021-01-05 Thread Gianni Ceccarelli
On 2021-01-05 David Emanuel da Costa Santiago 
wrote:
>  > so the inner ``whenever`` really sets up a separate tap every time
>  > it's executed.  
> Is this behaviour expected? It kinda looks weird to me, specially
> when looking to the output...

Well, it's what *I* expected: a ``whenever`` sets up a tap (or a
"then", or a "receive"…), so if you run it multiple times, you get
multiple taps. And on a Supply, each tap receives a copy of each
emitted value, hence that output.

>  > (If I change ``$outer`` to a Supplier/Supply pair… the program
>  > hangs without printing anything, because there's a race between
>  > the main process and the ``start``ed one, so all the
>  > ``$outer.emit`` happen  
> Don't you mean the $outer.send ?

``.send`` is for channels, ``.emit`` is for suppliers

>  > before the ``react / whenever`` can tap, and ``$done-with-outer``
>  > never gets kept. Using ``Supplier::Preserving`` fixes that)
> 
> So IO::Socket::Async::SSL needs to use it, instead of a normal
> Supply?

No, the problem we saw with the socket were primarily what Liz
noticed, that we were deadlocking between ``await $conn.print`` and ``whenever
$conn.Supply``.

There *might* be a buffering issue somewhere too, but it's harder to
trigger, and not related to the use of a Supply, anyway.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: LTA documentation page

2021-01-05 Thread Gianni Ceccarelli
On 2021-01-05 William Michels via perl6-users 
wrote:
> Raiph's suggestion works for me (on rakudo-2020.10). I mean, p6doc
> installs

Oh, that points to new, different, problems.

https://modules.raku.org/search/?q=p6doc links to
https://github.com/Raku/doc which does not contain a ``p6doc`` script,
which means that what I get with ``zef install p6doc`` is not the same
thing (this is a general problem with pointing at repositories instead
of distribution artifacts, it's not specific to p6doc)

Then, ``zef install p6doc`` fails here, because::

  Failed to create directory '/usr/share/perl6/site/doc' with mode
  '0o777': Failed to mkdir: Permission denied

AIUI, distributions should install to the CompUnit::Repository in my
home directory, not into the system-wide one.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: LTA documentation page

2021-01-05 Thread Gianni Ceccarelli
On 2021-01-05 Brad Gilbert  wrote:
> There really shouldn't be that much difference between what the
> documentation says and how your version works.

I've worked on machines stuck with perl 5.8 when the online
documentation was for 5.26

I'd like to live in a world where:

* raku is popular and widespread enough that you find old versions it
  on old machines
* I won't have to struggle to remember the differences between 6.d and
  6.l

For now, yes, the online docs are "good enough" (when I have network
connectivity, at least!)

> Even if rakudoc did install, it would just copy the most recent docs
> as of the time you installed it.

rakudoc != p6doc

rakudoc looks at the POD6 in installed distributions / modules

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: LTA documentation page

2021-01-05 Thread Gianni Ceccarelli
On 2021-01-05 JJ Merelo  wrote:
> Gianni is basically right. rakudoc has not really been released yet
> into the ecosystem, and p6doc will get you the documentation itself,
> which you will have to build then. So LTA is true, and there's some
> work to be done. There's probably an issue already created, but it
> will pop up if you create another one, so please do raise the issue
> and focus it on the documentation part if it does not.

https://github.com/Raku/doc/issues/3769

> We really encourage people to peruse the documentation online, though.
> https://docs.raku.org

Why? The online documentation will not, in the general case, match the
rakudo version I have installed.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Nested `whenever` (was Re: Help with bug)

2021-01-05 Thread Gianni Ceccarelli
On 2020-12-30 Gianni Ceccarelli  wrote:
> Also, my understanding of ``whenever`` is that it's adding a hook into
> the event loop, and only leaving the surrounding ``react`` (or
> ``supply``) will remove that hook (people who understand this better
> than I do: please correct me!). If that's true, adding a hook many
> times on the same condition looks wrong to me…

My understanding seems to be mostly correct::

  use v6.d;

  my Channel $outer .=new;
  my Supplier $inner .=new;
  my $inner-s = $inner.Supply;
  my Promise $done-with-outer .=new;

  my $receiver = start {
  react {
  whenever $outer -> $outer-value {
  say "received outer $outer-value";
  whenever $inner-s -> $inner-value {
  say "received inner $inner-value for outer $outer-value";
  done if $inner-value >= 3 && $outer-value >= 3;
  }
  $done-with-outer.keep() if $outer-value >= 3;
  }
  }
  }

  $outer.send($_) for ^4;
  await $done-with-outer;
  $inner.emit($_) for ^4;
  await $receiver;

prints::

  received outer 0
  received outer 1
  received outer 2
  received outer 3
  received inner 0 for outer 0
  received inner 0 for outer 1
  received inner 0 for outer 2
  received inner 0 for outer 3
  received inner 1 for outer 0
  received inner 1 for outer 1
  received inner 1 for outer 2
  received inner 1 for outer 3
  received inner 2 for outer 0
  received inner 2 for outer 1
  received inner 2 for outer 2
  received inner 2 for outer 3
  received inner 3 for outer 0
  received inner 3 for outer 1
  received inner 3 for outer 2
  received inner 3 for outer 3

so the inner ``whenever`` really sets up a separate tap every time
it's executed.

If I change ``$inner`` to be a Channel, we only get 4 "received inner"
lines, as expected, because values in a channel are received exactly
once.

(If I change ``$outer`` to a Supplier/Supply pair… the program hangs
without printing anything, because there's a race between the main
process and the ``start``ed one, so all the ``$outer.emit`` happen
before the ``react / whenever`` can tap, and ``$done-with-outer``
never gets kept. Using ``Supplier::Preserving`` fixes that)

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



LTA documentation page

2021-01-05 Thread Gianni Ceccarelli
https://docs.raku.org/programs/02-reading-docs says to use ``rakudoc``
to read the documentation of installed modules.

I don't have it installed::

  $ rakudoc
  -bash: rakudoc: command not found

Not a problem, that same page says to use zef::

  $ $ zef install rakudoc
  ===> Searching for: rakudoc
  No candidates found matching identity: rakudoc

Ok, this is not great. https://modules.raku.org/search/?q=rakudoc also
doesn't know anything about that distribution.

What happened?

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: Help with bug

2020-12-30 Thread Gianni Ceccarelli
On 2020-12-30 David Santiago  wrote:
> Thanks! It's indeed much clearer. However i have a question, why the 
> react on line 24?
> 
> The react there isn't required right?

I think it is ☺ The code, without the debugging bits::

react {
whenever $channel -> $val {
$conn.print("SENDING\r\n");

react {
whenever $conn-supply -> $line {
if $line ~~ /^340/ {
$conn.print("[$consumer]: value $val\r\n");
} else {
done;
}
}
}
}
}

I read this as:

* loop as long as the channel has values, then exit
* for each value in the channel:
  * write to the server
  * then loop reading from the server
  * and exit *this inner loop* when you get a non-340 line

Without the second ``react``, that ``done`` would exit the first ``react``,
essentially terminating the client. There's probably a way to write
the whole thing differently (keeping more explicit state, probably).

Also, my understanding of ``whenever`` is that it's adding a hook into
the event loop, and only leaving the surrounding ``react`` (or
``supply``) will remove that hook (people who understand this better
than I do: please correct me!). If that's true, adding a hook many
times on the same condition looks wrong to me…

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: Help with bug

2020-12-30 Thread Gianni Ceccarelli
Liz is, as usual, correct: there's no reason to wait until our write
buffers are flushed (``await $conn.print``) before ``react``ing to
what's in our *read* buffers.

In https://github.com/dakkar/raku-socket-test-from-demanuel I've
removed all ``await`` but one (the ``await .connect``), and the
program is much more reliable. I have seen it hang once, though,
so I feel there's still some weirdness going on with buffers
*somewhere*.

David: please look at my version of your code, I really think it's
clearer and simpler to work with, without the explicit ``.tap`` and
``.then`` (ok, I have a few ``.then``, but they're for debugging, they
don't affect the actual working of the program!)

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: Help with bug

2020-12-29 Thread Gianni Ceccarelli
On 2020-12-29 David Santiago  wrote:
> i don't want it to exit, i want it to keep reading from the socket
> until a "200" code happens.

Sorry, I had mis-understood the protocol.

I've put the code on Github so it's easier to look at it
https://github.com/dakkar/raku-socket-test-from-demanuel (those
certificates are from a random apache test installation)

> Like you said it looks like it's getting stuck in a react, but why?

Adding a bunch of ``print``, it looks like it most commonly hangs this
way:

* client sends ``SENDING``
* server reads it, sends the 340
* the client does *not* see a new line from the connection

But, if I replace ``IO::Socket::Async::SSL`` with plain
``IO::Socket::Async``, I can't make it hang anymore.

I fear we've uncovered a hard-to-diagnose bug in
``IO::Socket::Async::SSL`` …

-- 
dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: Help with bug

2020-12-29 Thread Gianni Ceccarelli
On 2020-12-29 David Santiago  wrote:
> I need some help in debugging my script. Sometimes it hangs and i
> don't know why.

I'm pretty sure it hangs in the inner ``react``::

if $line ~~ /^340/ {
await $conn.print("[$consumer]: value $val\r\n");
} else {
done;
}

Notice that if the client receives a 340, it sends stuff back to the
server, and *does not exit*. You may want to add a ``done`` after that
``await``.

Attached: a slightly-reworked version of your client, which I find
easier to read.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



client.raku
Description: Binary data


Re: spurt and array question

2020-11-14 Thread Gianni Ceccarelli
On 2020-11-13 ToddAndMargo via perl6-users  wrote:
> Hi All,
> 
> I am writing out an array of text lines to a file.
> I just can't help but thinking I am doing it the
> hard way.
> 
> unlink( $Leafpadrc );
> for @LeafpadrcNew -> $Line  { spurt( $Leafpadrc, $Line ~ "\n", 
> :append ); }
> 
> If I spurt the array, it converts the array into a
> single text line.

Some alternatives:

  $Leafpadrc.spurt(@LeafpadrcNew.join($Leafpadrc.nl-out));

  $Leafpadrc.put($_) for @LeafpadrcNew;

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: Junctions wrapped in singleton lists

2020-11-14 Thread Gianni Ceccarelli
On 2020-11-13 Sean McAfee  wrote:
> I just tried making a sequence of junctions and found that each one
> ended up wrapped in a singleton list somehow:
> 
> > ({ 1 | -1 } ... *)[^3]
> ((any(1, -1)) (any(1, -1)) (any(1, -1)))

oh, that's weird::

> ({ 'a' } ... *)[0].^name
Str
> ({ any(1,2) } ... *)[0].^name
List
> { any(1,2) }().^name
Junction

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: How to unbuffer $*IN

2020-09-26 Thread Gianni Ceccarelli
On 2020-09-26 David Santiago  wrote:
> I'm trying to capture key presses in the terminal and according to 
> raku's documentation i need to have $*IN unbuffered.

You have to tell the terminal to stop buffering (AFAIK Raku doesn't
buffer its inputs), which is not exactly trivial.

You may be better off using
https://modules.raku.org/dist/Term::ReadKey:cpan:JKRAMER (for example)

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: Extended identifiers in named attributes

2020-08-26 Thread Gianni Ceccarelli
On Wed, 26 Aug 2020 14:31:06 +0200
Marcel Timmerman  wrote:

> I was experimenting with extended identifiers and found that it is
> not possible to use it in named attributes. E.g.
> 
> > sub a (:$x:y) { say $x:y; }
> ===SORRY!=== Error while compiling:
> Unsupported use of y///.  In Raku please use: tr///.
> --> sub a (:$x:y⏏) { say $x:y; }
> 
> > sub a (:$abc:def) { say $abc:def; }
> ===SORRY!=== Error while compiling:
> Invalid typename 'def' in parameter declaration.
> --> sub a (:$abc:def⏏) { say $abc:def; }

Also::

  > sub a( :foo($a:x) ) { say $a:x; }
  ===SORRY!=== Error while compiling:
  Unable to parse named parameter; couldn't find right parenthesis
  --> sub a( :foo($a⏏:x) ) { say $a:x; }

feels like a parse problem to me. I'd say submit a bug report.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: subs and the type system

2020-07-20 Thread Gianni Ceccarelli
On Mon, 20 Jul 2020 14:00:33 +0200
Tobias Boege  wrote:
> You cannot write `Walkable ` in the signature of  because the
> combination of a type and the &-sigil apparently means that ``
> should be Callable and return a Walkable. That's why I use the
> $-sigil.

Aha! That's the bit I got wrong, thank you! with that change, my
example works.

I'd still like opinions on the subtyping situation between `Signature`

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: subs and the type system

2020-07-20 Thread Gianni Ceccarelli
On Mon, 20 Jul 2020 12:37:33 +0200
Theo van den Heuvel  wrote:
> The situation: I have a function, let's call in 'walker', whose first 
> parameter is a callback.
> I wish to express that only callbacks with a certain Signature and 
> return type are acceptable.
> Let's say the callback should follow :(Numeric $n --> Numeric). My 
> callback is going to be more complicated, but for simplicity sake.

Interesting problem!

I tried::

  use v6.d;

  subset Walkable of Callable where { $^c.signature ~~ :(Numeric $--> Numeric) 
};

  sub walker(Walkable ) {
  say callback(1);
  }

  sub callback(Numeric $x --> Numeric) { 1+$x }

  say 'is Callable? ',  ~~ Callable;
  say 'does the signature match? ',  ~~ :(Numeric $n --> 
Numeric);
  say 'is Walkable? ',  ~~ Walkable;

  walker();

which prints::

  is Callable? True
  does the signature match? True
  is Walkable? True
  Type check failed in binding to parameter ''; expected Walkable but 
got Sub+{Callable[Numeric]} (sub callback (Numeric...)
in sub walker at /tmp/s.raku line 5
in block  at /tmp/s.raku line 15

which is quite surprising to me.

Aside:

``(sub (Int $ --> Int) {}) ~~ Walkable`` is false, because
``:(Int $ --> Int) ~~ :(Numeric $ --> Numeric)`` is false, which is
correct because function subtypes should be contravariant in the parameter
types and covariant in the return type (i.e. if the caller passes a
Numeric, the callback should accept a Numeric or a *more general*
type, and if the caller expects a Numeric back, the callback should
return a Numeric or a *more specific* type).

But then ``:(Numeric $ --> Int) ~~ :(Numeric $ --> Numeric)`` is also
false, and I feel like it should be true. Opinions?

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: proto and multi

2020-06-29 Thread Gianni Ceccarelli
On 2020-06-29 Richard Hainsworth  wrote:
> a) I don't understand why the white space matters, but clearly it
> does. So the token is '{*}' and not braces around a Whatever-star.

Yep. Weird, but it's a special token.

> Not sure why the List:D is not being matched to Positional. Is the 
> List:D refering to the |c signature capture ??

Your method wants a `Positional @s`, which is an array/list/seq
containing only objects that do the `Positional` role. You're passing
it a list of strings. Either write `@s` (the @ implies you want a
positional thing) or `Positional $s` (a scalar containing a positional
object)

> c) Writing out all the code in each method is what I already have.
> But I'm looking for ways to factor out common code.

This works::

  class NewClass {
  has $.debug is rw = False;
  has $.value is rw = 'Initial value';

  proto method handle( |c ) {
note "before value is $.value" if $.debug;
{*}
note "after value is $.value" if $.debug;
  }
  multi method handle(Str $s) {
  $.value = $s;
  say 'in string'
  }
  multi method handle(@s) {
  $.value = @s[0];
  say 'in positional'
  }
  }

  my NewClass $x .= new(:debug);

  $x.handle('hello world');
  $x.handle();

and prints::

  before value is Initial value
  in string
  after value is hello world
  before value is hello world
  in positional
  after value is hello

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: Help with grammar

2020-05-21 Thread Gianni Ceccarelli
On 2020-05-21 David Santiago  wrote:
> Can someone explain me why my grammar isn't working? Unfortunately i
> can't figure it out :-(

Mixing ``rule``, ``token``, and ``regex`` apparently at random doesn't
make for a good grammar…

The text at
https://docs.raku.org/language/grammar_tutorial#The_technical_overview
is a bit confusing.

This https://docs.raku.org/language/regexes#Sigspace is more precise:
a ``rule`` inserts a ``<.ws>`` wherever there's whitespace in the
source code, so your::

   rule header-value { + }

is equivalent to::

  token header-value { + <.ws> }

which, as you saw in the trace, eats up the newline.

Short version: the only ``rule``s should be ``TOP``, ``request-line``,
and ``headers``, the others are all ``token``s

Extending the grammar to recognise more than one header is left as an
exercise.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: More questions on the "-pe" one-liner flag: in conjunction with s/// and tr///

2020-05-07 Thread Gianni Ceccarelli
On 2020-05-06 William Michels via perl6-users 
wrote:
> Are there any other "operators that modify their operands" in
> Raku/Perl6 that don't require an initializing "." (dot)?

The dot is used to call a method on an object.

> I checked the "subst" command and it requires an initial ".=" when
> used with the "-pe" one-liner flag:

``subst`` is a method https://docs.raku.org/type/Str#method_subst

To summarise:

* ``-e`` tells raku "execute the next argument as a program"

* both the ``-p`` and ``-n`` command-line switches wrap the program in
  a loop like::

for $*ARGFILES.lines -> {

}

  ``-p`` additionally puts a ``say $_`` at the end of the block

* inside that loop, the variable ``$_`` will have its value set to
  each line of the input, one at a time

* you can do whatever you want inside the loop

* the dot calls a method, and if you don't specify an object to call
  the method on (on the left hand side of the dot), ``$_`` is used

* some operators (like ``s///`` or ``tr///``) operate on ``$_`` unless
  told otherwise

* assignment (``=``) can be combined with other operators (``+=``,
  ``/=``, ``.=``, ``~=``, )

If, having seen all that, the behaviour of all your examples is still
not clear, maybe you should start writing your programs without
shortcuts and implicit terms: the languages in the Perl family are
very good at letting you write compact code, but sometimes this comes
at the expense of clarity. While learning, code that's clear,
explicit, and straightforward is often more helpful.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: More questions on the "-pe" one-liner flag: in conjunction with s/// and tr///

2020-05-06 Thread Gianni Ceccarelli
On 2020-05-06 William Michels via perl6-users 
wrote:
> Can anyone answer why--in a one-liner using the "-pe" flag--the s///
> and tr/// functions do not require a "." (dot) preceding the function
> call?

Because they're not function calls, but *mutating* operators. As the
documentation says
https://docs.raku.org/language/operators#s///_in-place_substitution
``s///`` is an "in-place substitution":

s/// operates on the $_ topical variable, changing it in place

and ``tr///``
https://docs.raku.org/language/operators#tr///_in-place_transliteration
says the same:

tr/// operates on the $_ topical variable and changes it in place

And as usual, ``-p`` prints the value of ``$_`` at the end of each
loop, so you get the modified value.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: Inconsistency between one-liner flags (-ne, -pe) using chop example?

2020-05-06 Thread Gianni Ceccarelli
On 2020-05-06 William Michels via perl6-users 
wrote:
> So if the following code does useless work:
> 
> perl6 -pe '.chop' demo1.txt
> 
> why doesn't it fail with an error, "Useless use of ... in sink context
> (line 1)"?

That's a very good question!

My best attempt at an answer:

* subroutines that are "pure functions" (i.e. have no side effects)
  can be marked with the ``pure`` trait (e.g. ``sub sqrt($) is pure``
  is in the standard library)
* the parser or the optimiser (whoever notices first) will indeed emit
  the warning "useless use of ..." when they see that the result of
  calling a pure function is sunk
* but we're not calling a function, we're calling a method!
* and (currently) Rakudo can't infer the type of the object we're
  using (it could, since the return value of ``IO::CatHandle::lines``
  can be declared, and thus the type of ``$_`` in that loop could be
  inferred, but it's hard and hasn't been done yet)
* so Rakudo can't currently know what code that ``.chop`` will end up
  calling, and if it has side-effects or not
* so it can't safely warn (it would be like warning that you're not
  checking the return value of ``say``)
* yes, there is a sub version of ``chop`` (you can write ``chop($_)``
  instead of ``$_.chop``), but it just delegates to the method, so
  without full type inference and data-flow analysis we still can't
  know if the method "is pure"

Hope this helps!

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: Inconsistency between one-liner flags (-ne, -pe) using chop example?

2020-05-05 Thread Gianni Ceccarelli
On 2020-05-05 William Michels via perl6-users 
wrote:
> If the only difference between the "-n" and "-p" flags is really that
> the second one autoprints $_, I would have expected the "-pe" code
> above to work identically to the "-ne" case (except "-ne" requires a
> print, put or say). Presumably  'perl6 -ne "put .chop" '  is the same
> as  'perl6 -ne ".chop.put" ' , so if  ".put"  isn't returning $_ ,
> what is it returning then?

Ok, let's ask rakudo what the difference is between the two programs::

  $ diff -uw <(rakudo --target=ast -ne '.chop') \
 <(rakudo --target=ast -pe '.chop')

  --- /dev/fd/632020-05-05 20:36:57.262256451 +0100
  +++ /dev/fd/622020-05-05 20:36:57.263256462 +0100
  @@ -78,6 +78,7 @@
 - QAST::Op(p6scalarfromdesc) 
   - QAST::WVal(ContainerDescriptor::Untyped) 
 - QAST::Var(local __lowered_param_decont__1) 
  +  - QAST::Stmts 
 - QAST::Stmts  .chop
   - QAST::Stmt  .chop
 - QAST::Want 
  @@ -90,6 +91,8 @@
 - QAST::Op(hllize)  :statement_id<1>
   - QAST::Op(callmethod chop)  chop
 - QAST::Var(lexical $_) 
  +- QAST::Op(call ) 
  +  - QAST::Var(lexical $_) 
 - QAST::Stmts 
   - QAST::Op(bind) 
 - QAST::Var(local ctxsave :decl(var)) 

Which tells us that the only difference is (as documented) that ``-p``
adds a ``say $_`` at the end of the body of the loop.

So, ``-ne 'put .chop'`` is roughly equivalent to::

  for $*ARGFILES.lines { put .chop }

Here ``.chop`` (or its fully explicit version, ``$_.chop``) returns
the chopped line, which gets passed to ``put``, which prints it.

On the other had, ``-pe '.chop'`` is roughly equivalent to::

  for $*ARGFILES.lines { .chop; say $_ }

Here, ``.chop`` still returns the chopped line, but that value is
thrown away. Then, independently of that, we print the value of
``$_``.

In both cases, nothing is changing the value of ``$_`` inside each
iteration of the loop.

The two programs behave differently because they are not the same
program! Two pairs of equivalent programs would be::

  raku -pe '.chop'
  raku -ne '.chop; .say'

  raku -pe '.=chop'
  raku -ne '.=chop; .say'

Does this help?

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: Inconsistency between one-liner flags (-ne, -pe) using chop example?

2020-05-05 Thread Gianni Ceccarelli
On 2020-05-05 William Michels via perl6-users 
wrote:
> mbook:~ homedir$ perl6 -ne 'put .chop' demo1.txt
> this is a test
> I love Unix
> I like Linux too
> mbook:~ homedir$ perl6 -pe '.chop' demo1.txt
> this is a test,
> I love Unix,
> I like Linux too,

The ``.chop`` method does not mutate its argument, it only returns a
chopped value. If you want to mutate, you need to say so::

  raku -pe '.=chop' demo1.txt

Notice that the ``.=`` operator is:

* not specific to ``chop``
* not even specific to calling methods

In the same way that ``$a += 1`` is the same as ``$a = $a + 1``, so
``$a .= chop`` is the same as ``$a = $a.chop``.

So, if you wanted, you could do::

  raku -pe '.=uc' # print upper-case

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: split to walk into an HoH ?

2019-11-22 Thread Gianni Ceccarelli
On 2019-11-22 Marc Chantreux  wrote:
> ";" to walk in the hoh is really awesome but i don't know even know
> from where i know it and what's the object underneath.
> it isn't listed in the list of operators

It's mentioned in the page about subscripts:
https://docs.perl6.org/language/subscripts#Multiple_dimensions (it's
not easy to find, though, unless you know already that it's there)

The method seems to be::

  multi sub postcircumfix:<[; ]>(\SELF, @indices)

and its adverbial variants.

This works::

  my %section = ( a => %( b => %( c => 1 ) ) );

  my @path = «a b c»;

  say postcircumfix:<{; }>(%section,@path);

and prints ``(1)`` (the return value is a list)

From a quick look through ``Perl6/Grammar.nqp`` and
``Perl6/Actions.nqp``, I think that the semicolon is special-cased by
the compiler, so the slightly ugly way above (call the operator
directly) is probably the only way that works.

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: Variable character class

2019-09-05 Thread Gianni Ceccarelli
On Wed, 4 Sep 2019 21:44:29 -0700
William Michels via perl6-users  wrote:

> Hi Gianni, I'm not sure of the Perl5 case, but what you're saying is,
> if your target string is backslashed, be sure to "quote-interpolate
> it" in Perl6? (see below):

Re-reading what I wrote, I realise it was really not clear. Let me try
again.

yary's original code was::

  sub matching_chars {
(my $chars_to_match, local $_) = @_;
/([$chars_to_match]+)/
  }
  say matching_chars('+\/\]\[', 'Apple ][+//e'); # says ][+//

If ``matching_chars`` took "a set of characters expressed as a string"
as its first argument, you'd expect to be able to say::

  say matching_chars('+/][', 'Apple ][+//e');

but this doesn't work, because it tells Perl5 to compile this regex::

  ([+/][])+

which doesn't compile ("Unmatched [ in regex").

Sidhekin's Perl6 version doesn't have this issue. On the other hand,
this happens::

  sub matching_chars(Str $chars_to_match, Str $target) {
my @chars-to-match = $chars_to_match.comb;
return $target ~~ m:g/@chars-to-match + /;
  }

  is matching_chars('+/][', Q{Apple ][+//\\e}),['][+//'];
  is matching_chars('+\/][', Q{Apple ][+//\\e}),[Q{][+//\\}];


The "fixed" Perl5 version would be::

  /([\Q$chars_to_match\E]+)/

or, equivalently::

  $chars_to_match = quotemeta($chars_to_match);
  /([$chars_to_match]+)/

Does that help?

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

You have literary talent that you should take pains to develop.


Re: Variable character class

2019-09-03 Thread Gianni Ceccarelli
On Tue, 3 Sep 2019 09:15:54 -0700
William Michels via perl6-users  wrote:

> Just a short note that Eirik's array-based code seems to work fine,
> with-or-without backslash-escaping the first input string (minimal
> testing, below):

Oh, sure. But when the target string contains backslashes, it will
behave differently from the P5 version, in that the P5 version won't
report the backslashes as matching (because of the way it builds its
regex).


-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


Re: Variable character class

2019-09-02 Thread Gianni Ceccarelli
On 2019-09-02 The Sidhekin  wrote:
>   To have the (1-character) strings used a literals, rather than
> compiled as subrules, put them in an array instead of a block wrapped
> in angle brackets:
> 
> sub contains( Str $chars, Str $_ ) {
>   my @arr = $chars.comb;
>   m:g/@arr+/

This looks to be the correct solution. Notice that yary's initial code
had::

  matching_chars('+\/\]\[', 'Apple ][+//e')

but those backslashes are an implementation artefact (the Perl5
version interpolates the given string into a regex without calling
``quotemeta``).

If we remove the backslashes, Sidhekin's code works::

  #!perl6
  use v6;
  use Test;

  sub matching_chars(Str $chars_to_match, Str $target) {
my @chars-to-match = $chars_to_match.comb;
return $target ~~ m:g/@chars-to-match + /;
  }

  is matching_chars("24680", "19584203"),['8420'];
  is matching_chars("Lorem ipsum dolor sit amet, consectetueradipiscing elit.",
"abcdef"), ['a','cde'];
  is matching_chars('+/][', 'Apple ][+//e'),['][+//'];
  is matching_chars('24680', '19584203'),['8420'];
  is matching_chars('24680', '24680x'),['24680'];
  is matching_chars('246','13 91 1462 7'),['462'];

  done-testing;

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

Just because it's not nice doesn't mean it's not miraculous.
-- (Terry Pratchett, Interesting Times)


Re: Modulino in Perl 6

2017-05-02 Thread Gianni Ceccarelli
On Tue, 2 May 2017 17:02:40 +0200
Gabor Szabo  wrote:
> Is there some way in Perl 6 to tell if a file was executed directly or
> loaded into memory as a module?

One way that seems to work: define a ``sub MAIN``; it will be invoked
when you execute the file as a program, but won't be touched if you
load it as a module.

Example: in file ``/tmp/x/Foo.pm6``::

  class Foo {
has $.value;
  }

  sub MAIN($value) {
say Foo.new(:$value).value;
  }

then::

  $ perl6 -I /tmp/x -e 'use Foo;say Foo.new(:value(5)).value'
  5

  $ perl6 /tmp/x/Foo.pm6
  Usage:
/tmp/x/Foo.pm6 

  $ perl6 /tmp/x/Foo.pm6 12
  12

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

Leela: You buy one pound of underwear and you're on their list forever.


NativeCall and memory management

2016-08-30 Thread Gianni Ceccarelli
Hello all! I'm trying to figure out how the NativeCall interface
releases memory for objects with native representation, and I could
use some help.

For what I can see:

* CPointer never frees anything
  https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CPointer.c#L148
* CStr always frees the allocated memory
  https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CStr.c#L63
* CStruct never frees, but has a comment saying maybe it should
  https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CStruct.c#L664

I agree that CPointer shouldn't do anything special: it's essentially
a number, in general we don't know anything about it, so it's best to
leave it alone.

For CStr, I'm not clear on what happens: I haven't found code that
actually uses it.

For CStruct (and CPPStruct, and CUnion), I'm pretty sure that both
"never free" and "always free" are bad. Some C functions will return
pointers to data they have allocated, and expect you to free, either
with the normal "free" function or with some library-specific
call. Some other will return pointers to internal data that you should
not touch. Some will expect you to allocate memory, and will write
there.

The current behaviour of not freeing is definitely better than going
around and calling "free" on every pointer, but it leaks.

I'd like to be able to mark an instance as "owned by the Perl side",
and specify how to free it. It has to be per-instance, since different
values of the same type may be owned by different "sides". I see these
four cases:

* object allocated by Perl, passed to C
  * becomes owned by C
  * or stays owned by Perl
* object allocated by C, returned to Perl
  * becomes owned by Perl
  * or stays owned by C

A C-owned object will be freed as a side-effect of some future call.

A Perl-owned object may need to to be freed by:
* a normal call to "free"
* a call to a specific C function

Does the above make any sense? Am I on the right track? How would I go
about implementing that thing?

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

The first time, it's a KLUDGE!
The second, a trick.
Later, it's a well-established technique!
-- Mike Broido, Intermetrics


pgpF62DYdtiTD.pgp
Description: OpenPGP digital signature


NativeCall and memory management

2016-08-30 Thread Gianni Ceccarelli
Hello all! I'm trying to figure out how the NativeCall interface
releases memory for objects with native representation, and I could
use some help.

For what I can see:

* CPointer never frees anything
  https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CPointer.c#L148
* CStr always frees the allocated memory
  https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CStr.c#L63
* CStruct never frees, but has a comment saying maybe it should
  https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CStruct.c#L664

I agree that CPointer shouldn't do anything special: it's essentially
a number, in general we don't know anything about it, so it's best to
leave it alone.

For CStr, I'm not clear on what happens: I haven't found code that
actually uses it.

For CStruct (and CPPStruct, and CUnion), I'm pretty sure that both
"never free" and "always free" are bad. Some C functions will return
pointers to data they have allocated, and expect you to free, either
with the normal "free" function or with some library-specific
call. Some other will return pointers to internal data that you should
not touch. Some will expect you to allocate memory, and will write
there.

The current behaviour of not freeing is definitely better than going
around and calling "free" on every pointer, but it leaks.

I'd like to be able to mark an instance as "owned by the Perl side",
and specify how to free it. It has to be per-instance, since different
values of the same type may be owned by different "sides". I see these
four cases:

* object allocated by Perl, passed to C
  * becomes owned by C
  * or stays owned by Perl
* object allocated by C, returned to Perl
  * becomes owned by Perl
  * or stays owned by C

A C-owned object will be freed as a side-effect of some future call.

A Perl-owned object may need to to be freed by:
* a normal call to "free"
* a call to a specific C function

Does the above make any sense? Am I on the right track? How would I go
about implementing that thing?

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

Empires do not suffer emptiness of purpose at the time of their
creation. It is when they have become established that aims are lost
and replaced by vague ritual.

  -- Words of Muad'dib by Princess Irulan.


pgpxl8lUobR_8.pgp
Description: OpenPGP digital signature


Re: Is there another way to define a regex?

2016-01-18 Thread Gianni Ceccarelli
On 2016-01-17 Tom Browder  wrote:
> My question: Is there a way to have Perl 6 do the required escaping
> for the regex programmatically, i.e., turn this:
> 
> my $str = '/home/usr/.cpan';
> 
> into this:
> 
> my regex dirs {
>   \/home\/usr\/\.cpan
> }
> 
> automatically?  

Yes! And it's also simpler than in Perl 5. I Perl 5, you would have to
do something like:

  my $dirs = qr{\Q$str};

but in Perl 6 you just do:

  my $dirs = regex { $str };

because the other behaviour, to interpret the contents of $str as
another regex to match, has more explicit syntax:

  regex { <$another_regex> }

For your initial use-case there is also another shortcut: an array is
interpreted as an alternation, so you could write:

  my @dirs = < /home/user/.cpan /home/tbrowde/.emacs >;
  my $regex = regex { @dirs };

and it would do what your Perl 5 example does.

If you want to be more restrictive, you can anchor the alternation:
  
  my $regex = regex { ^ @dirs };

Here is a complete program:

  use v6;

  my @dirs = < foo bar baz >;

  my $matcher = regex { ^ @dirs $ };

  for $*IN.lines -> $line {
  if $line ~~ $matcher {
  say "<$line> matched";
  }
  else {
  say "<$line> didn't match";
  }
  }

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

To spot the expert, pick the one who predicts the job will take the
longest and cost the most.


Re: [perl #65878] Rakudo shouldn't allow metaops with the same modifier twice in a row

2009-05-21 Thread Gianni Ceccarelli
On 2009-05-21 Larry Wall la...@wall.org wrote:
 : dakkar rakudo: sub infix:R($a,$b) { $a ~ '-' ~ $b }; sub
 : infix:RR($a,$b) { $a ~ '_' ~ $b }; say 'x' R 'y'; say 'x' RR 'y';
 : p6eval rakudo e6b463: OUTPUT«x-y␤x_y␤»
 : dakkar now, apart from don't do that, what should happen?
 : [snip]
 : dakkar jnthn: about the meta-operator collision thing, S03 says
 : that you can't modify with '!' forms that start with '!', and you
 : can't modify with '=' forms that end with '='

Ok, let me try to explain what I was aiming at…

If we have a normal operator, whose spelling is the same as a
meta-modified version of another operator, which one should get
called? The normal (like rakudo does today), or the meta-modified? IN
my example, is the output correct, or should it have been «x-y␤y-x␤» ?

 I don't see a bug here.  First, there's no prohibition on multiple
 similar metas anymore.  But with regard to the example above, metas
 are parsed as their own tokens, and the infix:RR is longer than
 the meta R, so should take precedence under LTM.

Ok, so this means that rakudo does the right thing, which looks pretty
sensible to me.

So normal operators will always take precedence against meta-modified
operators. Should there be a way to explicitly say I mean a
meta-operator here? If I write:

  sub infix:»ö«($a,$b) { return butterfly between $a and $b }
  sub infix:ö($a,$b) { return abs($a-$b) }

how do I make:

  say (1,2,3) »ö« (3,4,5)

print:

  2 2 2

(apart from doing it the hard way with map, zip, etc)?

-- 
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

   This one's tricky. You have to use imaginary numbers, like
   eleventeen ... -- Hobbes


signature.asc
Description: PGP signature


Re: [PATCH] Add .trim method

2009-01-12 Thread Gianni Ceccarelli
On 2009-01-12 Ovid publiustemp-perl6interna...@yahoo.com wrote:
 Um, er.  Damn.  Now I'm wondering how my leading and trailing
 trimming works with Hebrew.  How are the strings implemented
 internally?

RTL (and bidi) languages are written in strings so that the character
order is the logical, reading, order. That is, the character nearer
to the beginning of the string is the first one to be read by a human
reader (so, such character would be displayed on the right for a RTL
language, on the left for a LTR language, at the top for a TTB language)

Short answer: your implementation is right :)

-- 
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

You possess a mind not merely twisted, but actually sprained.


signature.asc
Description: PGP signature


Re: Character sets PDD ready for review

2008-03-14 Thread Gianni Ceccarelli
(Here follows various comments and opinions on PDD28 draft, written
while reading it)

As has been pointed out, the expression «A grapheme is our concept» is
not really clear. I think «The term grapheme in this document
defines a concept local to Parrot» or some such.

I'm not sure that UTF-16 can be called a fixed-width encoding (what
with surrogate pairs and all that...)

«we don’t standardize on Unicode internally»: the intent is clear, but
the expression feels ambiguous to me. Do you mean we don't fixate on
a UTF-*, we don't use Unicode-specified semantics and tables, or
what? (I think the text is simply referring to encodings for internal
representations)

«Parrot_Rune»: whoever came up with this short-form for grapheme can
collect a beer from me at the next YAPC::Europe. Brilliant!

«out-of-band» usually does not mean using special values in the same
stream as normal values... again, the intent is clear enough, but the
terminology is misleading.

«0x0438 0x00030F» is not a byte-stream, it's an int-stream.

«need to take the overload of peeking» s/overload/overhead/ ?

Stupid serialization of Parrot_Rune arrays are not portable between
Parrot runs, right? That is, Parrot_Rune(-1) can refer to different
graphemes from one run to the next. Better bang it into the heads of
everyone from the earliest possible moment...

I've always defined an encoding as a function from streams of
characters to strings of bytes (and back, for decoding). Why not
include a similar definition at the beginning of the IMPLEMENTATION
section?

«encoding_get_codepoint» may return something which is not, strictly
speaking, what Unicode calls a codepoint. Ok, calling it runepoint
might be seen as a pun, but confusion is (sadly) the norm whet dealing
with text nowadays, and overloading such a badly-understood term may
not help clear the issue...

Warnings to add to the checklist:

- arithmetical comparison of string data elements is a red flag
- string sorting is ill-defined generally, but it's well-defined
  inside a locale (that is, it's dependent on the language of the
  user, which may or may not have any relation with the language of
  the data, which in turn may or may not have any relation with the
  script of a character)
- tr/// or similar simple-minded table-based transformations are a red
  flag
- the Parrot_Rune value-space is not connected (that is, given that $a
  and $b are valid Parrot_Rune values, there may be a value $c ($a 
  $c  $b) that is not a valid Parrot_Rune), so don't use Parrot_Rune
  in for-loops
- string element count (length) and string display width are quite
  unrelated (Han characters are wider than Latin characters almost
  always, for example)

Hope this helps, and is not too jumbled (I tend to brain-dump)

-- 
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

To save a single life is better than to build a seven story pagoda.


Re: pluralization idea that keeps bugging me

2008-01-26 Thread Gianni Ceccarelli
On 2008-01-26 Larry Wall [EMAIL PROTECTED] wrote:
 Last night I got a message entitled: yum: 1 Updates Available.
 [snip a lot]
 I think that probably handles most of the Indo-European cases, and
 anything more complicated can revert to explicit code.  (Or go though
 a localization dictionary...)

Please don't put this in the language. The problem is harder than it
seems (there are European languages that pluralize differently on $X %
10, IIRC; 0 is singular or plural depending on the language, etc etc).

Look at the documentation of GNU gettext, or the translation
guidelines for KDE, to get the whole mess.

We already have Locale::MakeText. To get the whole magical
interpolation, we'd just have to define a suitable quoting construct,
right?

I know Perl is not minimal, but sometimes I feel that it will end up
being maximal... and the more you put in the core, the less
flexibility you get in the long term.

-- 
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

printk(%s: Boo!\n, dev-name);
linux-2.6.19/drivers/net/depca.c


signature.asc
Description: PGP signature


Re: Definition of Order in S29

2008-01-24 Thread Gianni Ceccarelli
On 2008-01-24 Thom Boyer [EMAIL PROTECTED] wrote:
 Joe Gottman wrote:
In the definition of cmp, S29 says the function returns 
  |Order::Increase|, |Order::Decrease|, or |Order::Same| (which
  numify to -1, 0, +1).  Shouldn't the enumerations and their
  numerical values be listed in the same order?
 
  Joe Gottman
 The enumerations and the numerical values are both in correct order.  
 Since abc is less than xyz,  abc cmp xyz is being invoked
 with its arguments in increasing order, So it returns
 Order::Increase. That numifies to -1 because that's how less-than
 is usually encoded.

Correct about Increase. But would ::Decrease numify to 0, and ::Same
to +1? :)

-- 
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

That's one small step for a man; one giant leap for mankind.
-- Neil Armstrong


signature.asc
Description: PGP signature


Re: $obj.can(bark); # or can it?

2008-01-03 Thread Gianni Ceccarelli
On 2008-01-03 Ovid [EMAIL PROTECTED] wrote:
 Perl 5 couldn't really solve this and programmers just had to know
 that all methods were implicitly variadic.  I seem to recall that
 Larry had an idea about how to specify a signature (I could be
 misremembering and I can't find the response).

Hmmm. Could it have been with the C:() construct?

So that we might one day say

  $object.HOW.can('bark',:(Int))

I feel, though, that saying

  $object.HOW.can('bark',\(42))

would be more useful, since the dispatcher unifies signatures with
captures, and after all I want to know if I can invoke a method called
Cbark with the number 42.

By the way, what happened to Cmethod bark(Int $a where { $a  10
}) ? I can't find it in the Synopses ( http://perlcabal.org/syn/ )

-- 
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

No violence, gentlemen -- no violence, I beg of you!  Consider the
furniture! -- Sherlock Holmes