develooper Front page | perl.perl5.porters | Postings from June 2022

Re: pre-RFC: template strings

Thread Previous | Thread Next
From:
breno
Date:
June 16, 2022 04:06
Subject:
Re: pre-RFC: template strings
Message ID:
CAHS-WQYLOiDRbZtbaXfjGLOkrvCdeM-SUfw5MfwpXWvJBbYSsw@mail.gmail.com
I really like this, and would definitely use it. But, just to make sure I
understand it correctly, are we talking about this?

my $name = 'p5p'; say qt(Hello, #{$name}!);  # Hello, p5p!

say qt(This also #{'works!'}); # This also works!

say qt(What would $name print?); # What would $name print?

say qt(What would this print? #{ qw(a b c) }); # What would this print? c

my $x = qw(a b c); say qt(What about this: #{ $x });  # What about this: 3

say qt(What about this: #{ [1,2,3] }?);  # What about
this: ARRAY(0x123456789)?

my $s = qt( #{ 1/0 } compile time or runtime error?);   # illegal division
by zero at compile time.

my $secret = 42; say qt(secret is #{print $secret});  # 42secret is 1

my $secret = 42; my $input = 'print $secret'; say qt(secret is #{ $input
});  # secret is print $secret


To me, qt() would behave just like q() but "split" on #{} on compile time
and concatenate the results back into the original string, e.g.
   qt(abc #{ def } ghi #{ jkl } mno)
is compiled as:
   q(abc ) . def . q( ghi ) . jkl . q( mno)

Is this about right?

Cheers!

On Sun, Jun 12, 2022 at 10:40 PM Ricardo Signes <perl.p5p@rjbs.manxome.org>
wrote:

> On Sun, Jun 12, 2022, at 17:36, Graham Knop wrote:
>
> I like the general idea. I don't really like the spelling though, as ${ }
> already has meaning in the language and in interpolated strings.  I'd say
> that the @{} form is not needed. Eliminating it could allow a better
> spelling for the ${ } form.
>
> Prior art: https://metacpan.org/pod/Quote::Code
>
>
> Thanks.  If we have only one form, I'd suggest we use #{ ... } from Ruby.
>
> Quote::Code raises a good point:  this would be useful in heredocs.  I'll
> think about it.
>
> --
> rjbs
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About