Development: Creating Applications and Extensions

Adam Berry
Wolfram Research
training@wolfram.com

Extending the Language

Functions and Symbols

Creating new symbols or functions is the minimal way of adding new functionality to Mathematica. Often this is done without really thinking that you are extending, but at least for the lifetime of the session you are.

MyFunction[x_]:=x^2+10

MyFunction[2]

Contexts

Contexts are the namespace system. Using appropriately named contexts is a good way to start separating or grouping functions together.

Begin["MyContext`"]

anotherFunc[y_]:=y^3+15

anotherFunc[2]

End[]

Names["Global`*"]

Names["MyContext`*"]

Packages

A package is the base file unit of extension. What we mean by a package file is a .m file that will declare a context typically linked to the name of the package. Symbols declared in this file will be available from that context. These files will include BeginPackage statements that declare the context and any packages/contexts that are required.

Although contexts are more flexible than this, linking contexts in this way makes for a nice declarative system that is easy to navigate and organize.

Applications

Mathematica applications are typically housed in a hierarchy in a single folder somewhere on Mathematica’s path. The layout of an application allows for automatic discovery of a number of different types of contribution, based on so-called “magic folders”.

$UserBaseDirectory

System Extensions

There are a number of ways that you can use other systems to extend Mathematica. For some, there are also magic folders that you can add in your layout. For the other cases, it’s normally simply adding a location to a search path.

Java

.NET

C/C++

Databases

Other

User Interface Extensions

Documentation

You can document your application using tools provided with Wolfram Workbench. This uses the same system that developers at Wolfram Research use to produce documentation, allowing your application to appear the same as built-in functionality.

Palettes and Stylesheets

You may well want to include these with your application; palettes are a nice way to add user assistance for your application.

Applications for Delivery

Applications

Because applications are just a file hierarchy, you can simply archive (such as in a zip file) to deliver these for installation. You can even use File ▶ Install menu item in Mathematica to get them in the appropriate location on your system.

Paclets

Packaged and delivered the same way as applications, paclets simply add the file pacletinfo.m file that declares the additions (such as documentation) that the paclet makes.

Putting it Together

Example Application