: , @ , /@ , .. , NFunction .

Functional operators

These operators can help the user to program in the style of functional programming languages like Miranda and Haskell.

: Prepend item to list, or concatenate strings
@ Apply a function
/@ Apply a function to all entries in a list
.. Construct a list of consecutive integers
NFunction make wrapper for numeric functions


: -- Prepend item to list, or concatenate strings

Standard math library
Calling format:
item : list (prec. 7)
string1 : string2 (prec. 7)

Parameters:
item -- an item to be prepended to a list

list -- a list

string1 -- a string

string2 -- a string

Description:
The first form prepends "item" as the first entry to the list "list". The second form concatenates the strings "string1" and "string2".

Examples:
In> a:b:c:{}
Out> {a,b,c};
In> "This":"Is":"A":"String"
Out> "ThisIsAString";

See also:
Concat , ConcatStrings .


@ -- Apply a function

Standard math library
Calling format:
fn @ arglist (prec. 60)

Parameters:
fn -- function to apply

arglist -- single argument, or a list of arguments

Description:
This function is a shorthand for Apply. It applies the function "fn" to the argument(s) in "arglist" and returns the result. The first parameter "fn" can either be a string containing the name of a function or a pure function.

Examples:
In> "Sin" @ a
Out> Sin(a);
In> {{a},Sin(a)} @ a
Out> Sin(a);
In> "f" @ {a,b}
Out> f(a,b);

See also:
Apply .


/@ -- Apply a function to all entries in a list

Standard math library
Calling format:
fn /@ list (prec. 60)

Parameters:
fn -- function to apply

list -- list of arguments

Description:
This function is a shorthand for MapSingle. It successively applies the function "fn" to all the entries in "list" and returns a list contains the results. The parameter "fn" can either be a string containing the name of a function or a pure function.

Examples:
In> "Sin" /@ {a,b}
Out> {Sin(a),Sin(b)};
In> {{a},Sin(a)*a} /@ {a,b}
Out> {Sin(a)*a,Sin(b)*b};

See also:
MapSingle , Map , MapArgs .


.. -- Construct a list of consecutive integers

Standard math library
Calling format:
n .. m (prec. 60)

Parameters:
n -- integer. the first entry in the list

m -- integer, the last entry in the list

Description:
This command returns the list {n, n+1, n+2, ..., m}. If m is smaller than n, the empty list is returned. Note that the .. operator should be surrounded by spaces to keep the parser happy, if "n" is a number. So one should write "1 .. 4" instead of "1..4".

Example:
In> 1 .. 4
Out> {1,2,3,4};

See also:
Table .


NFunction -- make wrapper for numeric functions

Standard math library
Calling format:
NFunction("newname","funcname", {arglist})

Parameters:
"newname" -- name of new function

"funcname" -- name of an existing function

arglist -- symbolic list of arguments

Description:
This function will define a function named "newname" with the same arguments as an existing function named "funcname". The new function will evaluate and return the expression "funcname(arglist)" only when all items in the argument list arglist are numbers, and return unevaluated otherwise.

This can be useful when plotting functions defined through other Yacas routines that cannot return unevaluated.

Example:
Suppose we need to define a complicated function t(x) which cannot be evaluated unless x is a number:

In> t(x) := If(x<=0.5, 2*x, 2*(1-x));
Out> True;
In> t(0.2);
Out> 0.4;
In> t(x);
In function "If" :
bad argument number 1 (counting from 1)
CommandLine(1) : Invalid argument
Then, we can use NFunction() to define a wrapper t1(x) around t(x) which will not try to evaluate t(x) unless x is a number.

In> NFunction("t1", "t", {x})
Out> True;
In> t1(x);
Out> t1(x);
In> t1(0.2);
Out> 0.4;
Now we can plot the function.

In> GnuPlot(-0.1, 1.1, 30, t1(x))
Out> True;

See also:
MacroRule .