Permalink
Browse files

s/subroutine/function/g

  • Loading branch information...
chromatic committed Jul 1, 2010
1 parent 0ffa70d commit 33a6e25812a8e96ee55da72a331e6312c453fe59
@@ -55,7 +55,7 @@ input with behavior:
The C<dispatch()> function takes arguments of the form C<(2, 'times', 2)> and
returns the result of evaluating the operation.
-You may use anonymous functions in place of subroutine references. To Perl,
+You may use anonymous functions in place of function references. To Perl,
they're equivalent. Nothing I<necessitates> the use of anonymous functions to
perform these mathematical operations, but for functions this short, there's
little drawback to writing them this way.
@@ -251,7 +251,7 @@ wart on otherwise helpful syntax, courtesy of a quirk of the Perl 5 parser.
=end sidebar
The implementation of both functions does not care which mechanism you use to
-pass subroutine references. You can pass named functions by reference as well:
+pass function references. You can pass named functions by reference as well:
=begin programlisting
View
@@ -301,7 +301,7 @@ Within the function, C<@_> will contain seven elements, not two.
As well, list assignment to arrays is I<greedy>. An array will consume as many
elements from the list as possible. After the assignment, C<@cats> will
-contain I<every> argument passed to the subroutine. C<@dogs> will be empty.
+contain I<every> argument passed to the function. C<@dogs> will be empty.
This flattening behavior sometimes confuses novices who attempt to create
nested arrays in Perl 5:
@@ -321,7 +321,7 @@ containing the numbers one through 30, inclusive. Remember that parentheses do
not I<create> lists in these circumstances--they only group expressions.
The solution to this flattening behavior is the same for passing arrays to
-subroutines and for creating nested arrays (L<references>).
+functions and for creating nested arrays (L<references>).
=head3 Array Interpolation
View
@@ -20,7 +20,7 @@ Consider the program:
=end programlisting
When you run it, Perl will throw an exception due to the call to the undefined
-subroutine C<bake_pie()>. Now add a function called C<AUTOLOAD()>:
+function C<bake_pie()>. Now add a function called C<AUTOLOAD()>:
=begin programlisting
@@ -9,7 +9,7 @@ combine to form the simple--though effective--basic object system:
=item * A class is a package.
-=item * A method is a subroutine.
+=item * A method is a function.
=item * A (blessed) reference is an object.
View
@@ -5,7 +5,7 @@ Z<closures>
You've seen how functions work (L<functions>). You understand how scope works
(L<scope>). You know that every time control flow enters a function, that
function gets a new environment representing that invocation's lexical scope.
-You can work with subroutine references (L<references>) and anonymous functions
+You can work with function references (L<references>) and anonymous functions
(L<anonymous_functions>).
You know everything you need to know to understand closures.
View
@@ -108,7 +108,7 @@ C<unless> is much rarer than its postfix form:
=end programlisting
C<unless> works very well for postfix conditionals, especially parameter
-validation in subroutines (L<postfix_parameter_validation>):
+validation in functions (L<postfix_parameter_validation>):
=begin programlisting
@@ -359,7 +359,7 @@ Review the rules on truthiness of scalars again.
=begin sidebar
The C<Want> module available from the CPAN allows you to detect boolean context
-within your own subroutines. The core C<overloading> pragma (L<overloading>,
+within your own functions. The core C<overloading> pragma (L<overloading>,
L<pragmas>) allows you to specify what your own data types produce when
evaluated in a boolean context.
@@ -1080,9 +1080,9 @@ Do I need to explain recursion? I fear so.
=end for
-A I<tailcall> occurs when the last expression within a subroutine is a call to
-another subroutine--the return value of the outer subroutine is the return
-value of the inner subroutine:
+A I<tailcall> occurs when the last expression within a function is a call to
+another function--the return value of the outer function is the return
+value of the inner function:
=begin programlisting
View
@@ -255,7 +255,7 @@ contain.
=cell (none)
-=cell A hash which maps OS and low-level Perl signals to subroutine references
+=cell A hash which maps OS and low-level Perl signals to function references
used to handle those signals. Trap the standard Ctrl-C interrupt by catching
the C<INT> signal, for example. See C<perldoc perlipc> for more information
about signals and especially safe signals.
@@ -52,13 +52,13 @@ takes arguments. The indirect style may resemble:
=end programlisting
-... thus making the classname C<Class> look like a subroutine call. Perl 5
+... thus making the classname C<Class> look like a function call. Perl 5
I<can> disambiguate many of these cases, but its heuristics depend on which
package names the parser has seen at the current point in the parse, which
barewords it has already resolved (and how it resolved them), and the I<names>
-of subroutines already declared in the current package.
+of functions already declared in the current package.
-Imagine running afoul of a subroutine with (prototypes) L<prototypes> with a
+Imagine running afoul of a function with (prototypes) L<prototypes> with a
name which just happens to conflict somehow with the name of a class or a
method called indirectly. This is infrequent, but so difficult to debug that
avoiding this syntax is always worthwhile.
View
@@ -183,7 +183,7 @@ A module can make certain global symbols available to other packages through a
process known as I<exporting>. This is the flip side of passing arguments to
C<import()> through a C<use> statement.
-The standard way of exporting subroutines or variables to other modules is
+The standard way of exporting functions or variables to other modules is
through the core module C<Exporter>. C<Exporter> relies on the presence of
package global variables--C<@EXPORT_OK> and C<@EXPORT> in particular--which
contain a list of symbols to export when requested.
View
@@ -57,7 +57,7 @@ These rules only apply to literal names found in source code. The rules are
different for I<symbolic lookups>. Perl's dynamic nature makes it possible to
refer to entities with names generated at runtime or provided as input to a
program. This is more difficult than the straightforward approach, but it's
-also more flexible--if more dangerous. In particular, invoking subroutines or
+also more flexible--if more dangerous. In particular, invoking functions or
methods indirectly or looking up namespaced symbols lets you bypass Perl's
parser, which is the only part of Perl that enforces these grammatic rules. Be
aware that doing so can produce confusing code; usually using a hash
View
@@ -4,12 +4,12 @@ Z<prototypes>
X<prototypes>
-Novices commonly assume that they serve as subroutine signatures. They do not;
+Novices commonly assume that they serve as function signatures. They do not;
instead they serve two separate purposes. They offer hints to the parser to
-change the way it parses subroutines and their arguments. They also modify the
-way Perl 5 handles arguments to those subroutines when it executes them.
+change the way it parses functions and their arguments. They also modify the
+way Perl 5 handles arguments to those functions when it executes them.
-To declare a subroutine prototype, add it after the name:
+To declare a function prototype, add it after the name:
=begin programlisting
@@ -19,9 +19,9 @@ To declare a subroutine prototype, add it after the name:
=end programlisting
-You may add prototypes to subroutine forward declarations. You may also omit
+You may add prototypes to function forward declarations. You may also omit
them from forward declarations. If you use a forward declaration with a
-prototype, that prototype must be present in the full subroutine declaration;
+prototype, that prototype must be present in the full function declaration;
Perl will give a prototype mismatch warning if not. The converse is not true:
you may omit the prototype from a forward declaration and include it for the
full declaration.
@@ -34,7 +34,7 @@ for the desire to write too-clever code.
=end sidebar
The original intent of prototypes was to allow users to define their own
-subroutines which behaved like (certain) built-in operators. Consider the
+functions which behaved like (certain) built-in operators. Consider the
behavior of the C<push> operator, which takes an array and a list. While Perl
5 would normally flatten the array and list into a single list at the call
site, the Perl 5 parser knows that a call to C<push> must effectively pass the
@@ -76,7 +76,7 @@ block. See C<perldoc perlsub> for full documentation.
Prototypes can change the parsing of subsequent code and they can coerce the
types of arguments. They don't serve as documentation to the number or types
-of arguments subroutines expect, nor do they map arguments to named parameters.
+of arguments functions expect, nor do they map arguments to named parameters.
Prototype coercions work in subtle ways, such as enforcing scalar context on
incoming arguments:
@@ -111,7 +111,7 @@ prototypes.
=head3 Good Uses of Prototypes
-As long as code maintainers do not confuse them for full subroutine signatures,
+As long as code maintainers do not confuse them for full function signatures,
prototypes have a few valid uses.
X<overriding core keywords>
@@ -139,9 +139,9 @@ regardless of any lexical scoping.
X<constants>
The second reason to use prototypes is to define compile-time constants. A
-subroutine declared with an empty prototype (as opposed to I<no> prototype)
+function declared with an empty prototype (as opposed to I<no> prototype)
which evaluates to a single expression becomes a constant in the Perl 5 optree
-rather than a subroutine call:
+rather than a function call:
=begin programlisting
@@ -169,7 +169,7 @@ X<modules; Test::Exception>
The final reason to use a prototype is to extend Perl's syntax to operate on
anonymous functions as blocks. The CPAN module C<Test::Exception> uses this to
good effect to provide a nice API with delayed computation. Its C<throws_ok()>
-subroutine takes three arguments: a block of code to run, a regular expression
+function takes three arguments: a block of code to run, a regular expression
to match against the string of the exception, and an optional description of
the test. Suppose that you want to test Perl 5's exception message when
attempting to invoke a method on an undefined value:
@@ -186,7 +186,7 @@ attempting to invoke a method on an undefined value:
=end programlisting
-The exported C<throws_ok()> subroutine has a prototype of C<&$;$>. Its first
+The exported C<throws_ok()> function has a prototype of C<&$;$>. Its first
argument is a block, which Perl upgrades to a full-fledged anonymous function.
The second requirement is a scalar. The third argument is optional.
@@ -216,7 +216,7 @@ You can use this API without the prototype. It's slightly less attractive:
=end programlisting
-A sparing use of subroutine prototypes to remove the need for the C<sub>
+A sparing use of function prototypes to remove the need for the C<sub>
keyword is reasonable. Few other uses of prototypes are compelling enough to
overcome their drawbacks.
View
@@ -142,7 +142,7 @@ useful for several reasons:
=over 4
-=item * To pass and return arrays from subroutines without flattening
+=item * To pass and return arrays from functions without flattening
=item * To create multi-dimensional data structures
View
@@ -229,7 +229,7 @@ package global variables. You cannot C<local>ize lexical variables.
=begin sidebar
-You I<can> localize subroutines and methods, but that's deep magic you should
+You I<can> localize functions and methods, but that's deep magic you should
avoid wherever possible.
=end sidebar
View
@@ -60,7 +60,7 @@ is apparent in the different storage mechanisms of these variables within Perl
5 itself. Lexical variables get stored in I<lexical pads> attached to scopes.
Every new entry into such a lexical scope requires Perl to create a new pad to
contain the values of the variables for that particular entry into the scope.
-(This is how a subroutine can call itself and not clobber the values of
+(This is how a function can call itself and not clobber the values of
existing variables.)
Package variables have a storage mechanism called symbol tables. Each package

0 comments on commit 33a6e25

Please sign in to comment.