Linguistics 408/508 |
Fall 2003 |
Hammond |
Handout 8
Overview
Subroutines (continued)
- ...
- When
shift()
is given without an argument in a subroutine,
it automatically takes the special array variable @_
as an
argument. That special variable is roughly analogous to @ARGV
,
but at the level of a subroutine: all the arguments given to a subroutine are
elements in that arrray. They can be called directly, rather than by using
shift()
(example).
- Returning an argument allows your subroutine to spit out something,
like a number or string. You simply use the
return()
command in
the last line of the subroutine (example).
- There are three arguments for using subroutines. First, if some command
or sequence of commands is repeated, use a subroutine to eliminate the
redundancy. Second, you can use subroutines to show the logical
structure of your code. If some sequence of commands is a conceptual unit,
put it in a separate subroutine.
- The third argument is that with subroutines, you can create
recursive functions (example. (Using factorials here may seem
excessively mathmatical, but if you're familiar with Optimality Theory, then
you know about factorial typology....)