Creating Objects: Make, Let and :=

Objects are created using the Make or Let command, or by using the creation operator :=. Thus a vector called vec might be created in 3 ways:

  1. make vec [1,2];

  2. let vec be [1,2];

  3. vec := [1,2];

The Make and Let commands have the same syntax. The syntax of the creation operator := is:

<name> := <form> for objects that are not of function type, or

<name>(args) := <form> for function objects

(name is the function name, args is the comma-separated list of arguments, and there must be no spaces in <name>(args))

For example, y := x^2 sets y to the expression x^2, and

f(x,y) := x+y^2 creates a function f of two variables, x and y.

The difference between
Make and Let is that Make creates global objects and installs them in the Lexicon. Let creates only local objects of restricted scope (See Scope of an Object ). The creation operator := is essentially the same as Make.

Existing objects may have their values changed by
let or make. Viewed in this light, these commands act also as assignment operators, assigning new values to objects that already had values. These objects retain the new values until they are reassigned, or until the objects go out of scope.

Within any block, a
make statement or a := statement is interpreted as a let statement. Thus, the only places where it is appropriate to use make statements are at the top level of a script (not within a block) , or on a command line. In the examples that follow, the word make could be replaced with let, and the keyword be can be added for legibility. For example:

make f(x) value d(sin(x),x) has the local form:

let f(x) be value d(sin(x),x)

There are two basic forms of the commands, the
simple form, and the extended form. The simple forms are again divided into command form and operator form. The variety of options, while perhaps confusing at first, is intended to make the commands colloquial and easy to use. The extended forms give more precise control. These are also generally useful for documentation purposes. Since types are declared explicitly, it is easier to understand scripts, programs or commands that use the extended syntax.

Another reason for extended form is that objects such as vectors or equations are often created by substituting in other objects of the same type. The protocol is like:

make newobject substitute(x,y,oldobject)

The return type of substitute is
expression, and so, without explicit declaration,

newobject would be an
expression. Equations and vectors may use the extended style in cases like this to assign the correct type to the new object.

We discuss both forms for each of the categories of object.

Functions: First Simple Form

Functions: Second Simple Form

Functions: Extended Form

Functions: Symbolic

Vectors: Simple Form

Vectors: Extended Form

Vector Components: Setting and Getting

Matrices: Simple Form

Matrices: Extended Form

Matrix Components: Setting and Getting

Variables

Strings: Simple Form

Strings: Extended Form

Lists: Simple Form

Lists: Extended Form

Note on List Evaluation

Equations: Simple Form

Equations: Extended Form