Mailing List ArchiveSupport open source code!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: Python discussion, anybody?
- To: tlug@example.com
- Subject: Re: Python discussion, anybody?
- From: Simon Cozens <simon@example.com>
- Date: Fri, 27 Oct 2000 11:34:41 +0100
- Content-Disposition: inline
- Content-Type: text/plain; charset=us-ascii
- In-Reply-To: <14841.13182.409147.227175@example.com>; from turnbull@example.com on Fri, Oct 27, 2000 at 04:49:18PM +0900
- References: <14840.56067.908544.308032@example.com> <Pine.GSO.4.21.0010271326000.13029-100000@example.com> <14841.13182.409147.227175@example.com>
- Reply-To: tlug@example.com
- Resent-From: tlug@example.com
- Resent-Message-ID: <1J3UqD.A.DrE.x3V-5@example.com>
- Resent-Sender: tlug-request@example.com
- Sender: Simon Cozens <simon@example.com>
- User-Agent: Mutt/1.2.5i
On Fri, Oct 27, 2000 at 04:49:18PM +0900, Stephen J. Turnbull wrote: > Simon gave me an example the other day: > > perl -e 'print reverse "backwards"' > produces > backwards > > on output. Why? Reverse operates on arrays. "backwards" is a > string, and therefore scalar. But Perl promotes that scalar to a > one-element array, and reverses it. And then, covering its tracks, > converts the result back to a scalar and returns it. Ouch. Hm, that's not what happens at all. Built-ins like 'reverse' do different things when you're asking for a list and when you're asking for a scalar. If you ask for a scalar, reverse *will* reverse the scalar argument, hence this will work: perl -e '$a = reverse "backwards"; print $a' However, "print" takes a list, so reverse goes into list context, which means it reverses the order of its arguments. There's no "promoting to a one-element array": all functions take a list of arguments. There's no "converting back into a scalar": "print" prints a list. -- `First Up Against The Wall When The Revolution Comes! Woohoo! So long as they promise to use latex gloves, I'm happy. :)' - Thorfinn, in the Monastery.
- Follow-Ups:
- Re: Python discussion, anybody?
- From: "Stephen J. Turnbull" <turnbull@example.com>
- References:
- Python discussion, anybody?
- From: "Stephen J. Turnbull" <turnbull@example.com>
- Re: Python discussion, anybody?
- From: Todd.Rudick@example.com
- Re: Python discussion, anybody?
- From: "Stephen J. Turnbull" <turnbull@example.com>
Home | Main Index | Thread Index
- Prev by Date: Re: Python discussion, anybody?
- Next by Date: Re: Python discussion, anybody?
- Prev by thread: Re: Python discussion, anybody?
- Next by thread: Re: Python discussion, anybody?
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links