Re: A grammar to provide substitution

2018-08-29 Thread Timo Paulssen
There's a problem with your code, if any of the substitutions contains something that looks like the placeholder thing, and if it comes later in the iteration of the hash keys (which is randomized now) it will substitute again. This is very likely not what you want, though. HTH   - Timo On 28/08/

Re: A grammar to provide substitution

2018-08-29 Thread Laurent Rosenfeld via perl6-users
Surely, Timo, it might happen with some data, but not with the type of data shown by the OP (where the words to be replaced were all in the form $(something) and not the replacements. In fact, I suspect that many other things might go wrong with spurious data. The point is that my suggestion was j

Introspection

2018-08-29 Thread Parrot Raiser
Could someone supply a link to a clear example of a Perl 6 subroutine finding its own name, please? I know there's a method, but haven't managed to produce an effective search string for an example of its use.

Re: Introspection

2018-08-29 Thread Fernando Santagata
That's documented here: https://docs.perl6.org/language/variables#&?ROUTINE On Wed, Aug 29, 2018 at 5:51 PM Parrot Raiser <1parr...@gmail.com> wrote: > Could someone supply a link to a clear example of a Perl 6 subroutine > finding its own name, please? > I know there's a method, but haven't man

Re: Introspection

2018-08-29 Thread Parrot Raiser
Thanks. That's exactly what I wanted. On 8/29/18, Fernando Santagata wrote: > That's documented here: > > https://docs.perl6.org/language/variables#&?ROUTINE > > On Wed, Aug 29, 2018 at 5:51 PM Parrot Raiser <1parr...@gmail.com> wrote: > >> Could someone supply a link to a clear example of a Perl

Re: A grammar to provide substitution

2018-08-29 Thread Timo Paulssen
I should point out that the trans method has a mode that lets you pass placeholders and substitutions and it will Do The Right Thing regarding overlaps and order and everything. On 29/08/18 16:21, Timo Paulssen wrote: > There's a problem with your code, if any of the substitutions contains > some

Re: A grammar to provide substitution

2018-08-29 Thread Patrick Spek via perl6-users
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 It's supposed to be simple, since I don't need much. The most basic of substitution is all I care about right now. I've implemented it with a simple regex now, and it seems to work just fine. It's available as a module[1] now, and it's used in anothe

Re: A grammar to provide substitution

2018-08-29 Thread yary
Let's use "trans" instead of a regular expression, updating my example: sub format-string(Str:D $source, *%vars --> Str:D) { return $source.trans( [%vars.keys.map: '$(' ~ * ~ ')' ] => [%vars.values] ); } so simple! But, it does not catch missing variables... I bet we can fix th