Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: [pugs]weird thing with say ++$: msg#00141

lang.perl.perl6.compiler

Subject: Re: [pugs]weird thing with say ++$

On 21 Apr, fayland wrote:

: It has been published at perl6.language, but have no reply.

That was to be expected, as it's no language-design specific issue,
and therefore, unsuitable for p6l.


: In perl v5.8.6 built for MSWin32-x86-multi-thread:
:
: my $i = 1;
: print $i++, ++$i; # 1 3
: my $i = 1;
: print ++$i, $i++; # 3 2

You're misleaded here, by thinking, scalar context is being enforced,
which is not the case; the results of the increment operator operations (ops)
on the scalar are being passed in (implicit) array context to the print builtin.

Every Perl program, that gets compiled and interpreted, will be
converted to a syntax tree initially. The following is a selected excerpt
from the output of the core module B::Terse, which displays, what syntax
tree we actually got hold of.

LISTOP (0x3c013760) print
OP (0x3c013780) pushmark
UNOP (0x3c013700) postinc [2]
OP (0x3c0136e0) padsv [1]
UNOP (0x3c013740) preinc
OP (0x3c013720) padsv [1]

So, LISTOP indicates, that a list context is being encountered, which is
not, what we actually want. The syntax trees for the two examples,
provided above, don't differ that much, except, as you'd assume, in case
of the ordering of the UNOPs. I don't see any way to explain, what's
going wrong *exactly* by examining the syntax tree; that'd require
digging into the internals, I'd assume.


my $i = 1;

and either

print $i++; print ++$i;
or
print ++$i; print $i++;


does what you assumed, it was supposed to do, but without
having the compiler struggling against implicit assumptions.


: in pugs:
:
: my $i = 1;
: say $i++, ++$i; # 1 3
:
: my $i = 1;
: say ++$i, $i++; # 2 2

This leads me to think, Pugs has implemented the behaviour, that has
been outlayed in Apocalypse 03: Operators, RFC 082 - Arrays: Apply
operators element-wise in a list context,
http://dev.perl.org/perl6/doc/design/apo/A03.html


: which is right?(I think perl5 is) or it's different between Perl5 and
Perl6?

I'm not inclined to think, that Perl 5 is wrong here, as letting it
assume array context, is in this context, like assuming, filling your
fridge with food, it consists of, by randomly throwing some of it in,
will come out sorted again; Perl 6 does, what the specifications urge
upon it to do.


: /Fayland Lam/

Steven




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    gcc.libstdc++.c...    solaris.opensol...    information-ret...    misc.misterhous...    web.catalyst.ge...    apache.webservi...    redhat.release....    hardware.lirc/2...    kernel.autofs/2...    technology.sust...    linux.vdr/2003-...    editors.lyx.gen...    org.user-groups...    netbsd.devel.pk...    xdg.devel/2004-...    version-control...    jakarta.slide.d...    debian.packages...    creativecommons...    ports.ppc.embed...    bug-tracking.bu...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe