Skip to main content Accessibility help
×
Hostname: page-component-78c5997874-dh8gc Total loading time: 0 Render date: 2024-11-05T19:35:16.651Z Has data issue: false hasContentIssue false

6 - Programs

Published online by Cambridge University Press:  05 December 2015

Get access

Summary

Most of the programs we have created in the first five chapters are relatively short and compact, focused on solving problems that are quite manageable. These pieces of code are often sufficient when working on a problem and you are looking for a quick result. But before long, something more is needed: a series of computations that have to be repeated perhaps, with slight variations each time; or you need to share your code with colleagues or students; or perhaps you are developing an application for a client who knows little of the Mathematica environment or language and is looking for a solution that integrates with what they are already comfortable with.

Whether you are writing code for yourself or others, it is important to develop programs that are not dependent upon the current state of the user's Mathematica session: previously defined symbols should not interfere with code in any way; side-effects of an evaluation should not cause surprises; programs should respond gracefully when things go wrong. All modern programming languages have frameworks designed to deal with these things, and Mathematica is no exception. This chapter introduces these structures and incorporates them throughout the rest of the book.

The first construct we will look at is localization of variables. This is a mechanism to isolate symbols and definitions that are local to a function in order to keep them from interfering with, or being interfered by, global symbols.

Providing options to functions and issuing messages when things go wrong are common mechanisms for getting your programs to look and behave like built-in functions; they are introduced in Section 6.2.

The chapter concludes with several larger pieces of code that put many of these pieces together in one program.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2015

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Programs
  • Paul Wellin
  • Book: Essentials of Programming in <I>Mathematica</I>®
  • Online publication: 05 December 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9781316337738.007
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Programs
  • Paul Wellin
  • Book: Essentials of Programming in <I>Mathematica</I>®
  • Online publication: 05 December 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9781316337738.007
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Programs
  • Paul Wellin
  • Book: Essentials of Programming in <I>Mathematica</I>®
  • Online publication: 05 December 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9781316337738.007
Available formats
×