wengland@stephsf.stephsf.com (Bill England) (12/15/90)
In article <111028@convex.convex.com> tchrist@convex.COM (Tom Christiansen) writes: >: return (); >:} >Hmm... shouldn't that last one be: > > return ''; # or return undef > Good point ... "perl lint" with return type checking anyone ? -- +- Bill England, wengland@stephsf.COM -----------------------------------+ | * * H -> He +24Mev | | * * * ... Oooo, we're having so much fun making itty bitty suns * | |__ * * ___________________________________________________________________|
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (12/15/90)
In article <454@stephsf.stephsf.com> wengland@stephsf.stephsf.com (Bill England) writes: : In article <111028@convex.convex.com> tchrist@convex.COM (Tom Christiansen) writes: : : >: return (); : >:} : : >Hmm... shouldn't that last one be: : > : > return ''; # or return undef : > : : Good point ... "perl lint" with return type checking anyone ? Remember that Perl subroutines can be context sensitive. A Perl lint would probably have to punt on any routine containing the wantarray function, or do some rather hairy analysis. And this still wouldn't solve the "problem" that a routine can return () in a scalar context even when the return type is consistent. And it's not always possible to look at a subroutine call and tell easily if it's in a scalar or array context, since it can vary dynamically (if the call is embedded in another subroutine). You'd have to construct the entire call graph. Probably not worth it, given that () in a scalar context Does the Right Thing anyway. It might possibly be worth putting in a warning about, if -w is set and it can determine at runtime that there's an inconsistency. (I can tell I've been writing the Book too long\*-I wanted to write .P \-w instead.) Larry
worley@compass.com (Dale Worley) (12/18/90)
X-Name: Larry Wall You'd have to construct the entire call graph. Probably not worth it, given that () in a scalar context Does the Right Thing anyway. OK, Larry, clue me in -- what does () in a scalar context do? It's not in the manual. Dale Dale Worley Compass, Inc. worley@compass.com -- SunOSish /suhnasish/ adj. requiring 32-bit bug numbers
tchrist@convex.COM (Tom Christiansen) (12/18/90)
From the keyboard of worley@compass.com: : You'd have to construct the entire call graph. Probably not worth : it, given that () in a scalar context Does the Right Thing anyway. :OK, Larry, clue me in -- what does () in a scalar context do? It's :not in the manual. Empirical evidence suggests that it returns a null, except that it's of the undefined, not the defined flavor. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "With a kernel dive, all things are possible, but it sure makes it hard to look at yourself in the mirror the next morning." -me
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (12/19/90)
In article <1990Dec18.003438.21694@uvaarpa.Virginia.EDU> worley@compass.com writes:
:
: X-Name: Larry Wall
:
: You'd have to construct the entire call graph. Probably not worth
: it, given that () in a scalar context Does the Right Thing anyway.
:
: OK, Larry, clue me in -- what does () in a scalar context do? It's
: not in the manual.
It returns the same thing as any other list evaluated in a scalar context,
namely the last value. This is because a list in a scalar context is treated
as a series of comma operators, as in C. Of course, the last element of
a null list is undefined, so that's what you get for the return value.
Larry