EasyManuals Logo
Home>Texas Instruments>Calculator>TI-89

Texas Instruments TI-89 Developer's Guide

Texas Instruments TI-89
1398 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #222 background imageLoading...
Page #222 background image
180
Chapter 15: Expressions and The Expression Stack
TI
-
89 / TI
-
92 Plus Developer Guide
Not for Distribution
Beta Version January 26, 2001
Here is a pair of functions that combine to compute the square root of each
element of a list.
void push_sqrt_list (EStackIndex i)
{ /* i indexes a list */
push_sqrt_tail (i – 1u); /* compute the sqrt of the tail */
push_quantum (LIST_TAG); /* push a LIST_TAG on top */
}
void push_sqrt_tail (EStackIndex i)
{ /* i indexes a tail.
Pushes a tail of the square roots of the elements. */
if (END_TAG == ESTACK (i)) /* if at the bottom of the tail */
push_quantum (END_TAG); /* push bottom of new tail */
else
{ /* recur to next element of tail */
push_sqrt_tail (next_expression_index (i));
/* on the way out, compute sqrt of each element */
push_sqrt (i);
}
}
The recursive alternative has the advantage of automatically creating the new list
in the correct order. The disadvantage is that recursion consumes more
hardware stack for the recursive stack frames. This approach makes a recursive
subroutine call, thereby using a stack frame for each element of the list, and
finally, the END_TAG that terminates the list.
The recursive pattern for computing a list result from a list input is so common
that the system includes a generalized procedure that provides the recursion.
The
map_tail
routine makes it unnecessary to write the recursive subroutine as
shown in the previous example. The first argument in
map_tail
is a pointer to a
function that pushes a single result value based on a single input value. Its
second argument is a tail of input values. It performs the recursion, applying the
specified function to each element of the tail. Thus, push_sqrt_list can be
implemented as follows, making push_sqrt_tail unnecessary.
void push_sqrt_list (EStackIndex i)
{ /* apply sqrt function to the tail */
map_tail (push_sqrt, i – 1u);
/* push the LIST_TAG on top of the tail */
push_quantum (LIST_TAG);
}

Table of Contents

Other manuals for Texas Instruments TI-89

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Texas Instruments TI-89 and is the answer not in the manual?

Texas Instruments TI-89 Specifications

General IconGeneral
Display size (HxV)100 x 160 mm
Memory type639K FLASH ROM, 188K bytes RAM
Compatible operating systemsOperating System 2.09
Battery typeAAA

Related product manuals