11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.3 Packages • 751 −1 + 1 21k x(k + 1) x1 − 1 (k − 1) x61 + 1 (k + 2) x6 1 + ‘...‘Writing Maple Packages by Using ModulesThis section describes how to write Maple packages by using modules.The following subsections present several examples that illustrate how todo this.The LinkedList PackageThe first example package is a small package called LinkedList. Thisexample illustrates the basic structure of a package implemented by usingmodules.Background Linked lists are a basic data structure used in programsfor many different purposes. There are many kinds of linked lists, withvariations on the basic idea intended to address performance and functionalityissues. The example package shown in this subsection providesa few operations on the simplest possible form of linked lists.The links in a linked list are formed from a very simple data structuredcalled a pair. A pair is essentially a container with space for exactly twoelements. Pairs can be modeled by fixed length records with two slots.When used to implement linked lists, the first slot holds the data for thelist entry, and the second slot stores a pointer to the next pair in the list.The LinkedList package implements an abstract data definition forthe pair data structure, and adds some higher level operations on pairsto effect the list abstraction. A linked list is effectively represented by itsfirst pair.The pair abstract data structure is very simple. It consists of a constructorpair, and two accessors called head and tail that satisfy thealgebraic specificationp = pair(head(p), tail(p))for each pair p. In addition, there is a distinguished pair nil, satisfyingthis algebraic relation, that is unequal to any other pair, and satisfieshead(nil) = nil, tail(nil) = nil.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!