NSB Cosmic Center Image

N.S.B. Cosmic Center

NSB Cosmic Center Image

JavaScript & MathScript Interactive Document Generator-Demo-08

This document is generated by N.S.B. JavaScript & MathScript Interactive Document Generator version 001.

Introduction to N.S.B. JavaScript & MathScript Interactive Document Generator

MathScript Functions (cont.)

The functions first[] and last[] are convenient ways of accessing the first and the last elements of a MathScript function. For instance, consider the following code sequence:

input(1)=>  ff={F[a,b], x, g[i,j], y, z^2}
output(1)=> {F[a, b], x, g[i, j], y, (z^2)}
input(2)=> ff//first 
output(2)=> F[a, b]
input(3)=> %//first 
output(3)=> a
input(4)=> %%//last 
output(4)=> b
input(5)=> ff//last 
output(5)=> (z^2)
input(6)=> %//first 
output(6)=> z
input(7)=> %%//last 
output(7)=> 2

Two other convenient functions are rgt[] and lft[]. These give the original MathScript function excluding the first element and the last element, respectively:

input(8)=> ff//rgt
output(8)=> {x, g[i, j], y, (z^2)}
input(9)=> ff//lft 
output(9)=> {F[a, b], x, g[i, j], y}

If you wish to access an element at any particular position in a MathScript function, you need to use the function part[]. For instance:

input(10)=> part[ff,2]
output(10)=> x
input(11)=> part[ff,3] 
output(11)=> g[i, j]

At this point, you might wonder whether it is possible to use the postfix operator // in association with a function that requires two parameters like part[]. In this regard, it is useful to learn the following notation:

input(12)=> ff//part[#,3]
output(12)=> g[i, j]
input(13)=> %//part[#,1] 
output(13)=> i

You should have noticed the use of the symbol # as a reference to the desired argument.

Before proceeding to the next demodoc, where we shall continue to introduce more functions and features of MathScript, why don't you practice using MathScript live by clicking the program page below, and apply what you learned on this page.

Program Page
NSB Cosmic Center Image

N.S.B. Cosmic Center

NSB Cosmic Center Image