develooper Front page | perl.perl6.language | Postings from September 2005

Re: Stringification, numification, and booleanification of pairs

Thread Previous | Thread Next
From:
Nathan Gray
Date:
September 23, 2005 03:26
Subject:
Re: Stringification, numification, and booleanification of pairs
On Thu, Sep 22, 2005 at 11:59:32AM -0400, Matt Fowles wrote:
> Well said!  I completely agree that string interpolation should be
> handled exactly the same as stringification.  I would like C< ("foo is
> $foo of course") eq ("foo is " ~ $foo ~ " of course") > at all times.

Yes.

S03 states:

  Unary ~ now imposes a string context on its argument, and + imposes a
  numeric context (as opposed to being a no-op in Perl 5). Along the
  same lines, ? imposes a boolean context, and * imposes a list context.

That seems to indicate that ~$foo eq "$foo".

If however, you want $foo to interpolate to something else, you can do
that in several ways:

  "hello { +$foo }"
  "hello { $foo.as(...) }"

Or when concatenating:

  "" ~ +$foo ~ ""
  "" ~ $foo.as(...) ~ ""

-kolibrie

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About