cat - Maple Help

cat

concatenating expressions

 Calling Sequence cat( a, b, c, ... )

Parameters

 a, b, c, ... - any expressions

Description

 • The cat function is commonly used to concatenate strings and names together. The arguments are concatenated to form either a string, a name, or an object of type || .
 • The type of the result returned by cat will be || when one or more of the arguments are of type '||' or type 'function'. When the arguments contain an integer or character range, a sequence will be returned. When trailing arguments are of type 'indexed', the base name will be concatenated. In all other cases the argument will be turned into a string or name. See the examples later.
 • Note that if the result of cat is a name, then it is in fact a global name, even though there might be a local variable of the same name currently active.
 • To form a sequence of names (or strings), specify a symbol (or string) as the first argument, then one or more integer ranges as the subsequent arguments. Maple returns the sequence of names (or strings) formed by concatenating the symbol (or string) with the integers produced by iterating over the ranges.
 • When called with no arguments, or with arguments that evaluate to NULL, cat returns the empty name, .

 • The cat command is thread-safe as of Maple 15.

Examples

The type (name or string) of the result depends on the type of the left-hand operand.

 > $\mathrm{cat}\left(a,b\right)$
 ${\mathrm{ab}}$ (1)
 > $\mathrm{cat}\left("a","b"\right)$
 ${"ab"}$ (2)

Use an empty name or string as the leading argument to force the return type to be what you want.

 > $\mathrm{cat}\left(\mathrm{},"b"\right)$
 ${b}$ (3)
 > $\mathrm{cat}\left("",b\right)$
 ${"b"}$ (4)

Other types will be converted to form part of the name or string.

 > $\mathrm{cat}\left(a,2\right)$
 ${\mathrm{a2}}$ (5)
 > $\mathrm{cat}\left("a",2\right)$
 ${"a2"}$ (6)
 > $\mathrm{cat}\left("a",2,{x}^{2}+1\right)$
 ${"a2x^2+1"}$ (7)
 > $\mathrm{cat}\left("a =",2.5\right)$
 ${"a = 2.5"}$ (8)

Uneval quotes will suppress evaluation causing the named variable to be part of the result instead of its assigned value.

 > $l≔"left":$
 > $r≔"right":$
 > $\mathrm{cat}\left(l,r\right)$
 ${"leftright"}$ (9)
 > $\mathrm{cat}\left('l',r\right)$
 ${\mathrm{lright}}$ (10)

Multiple arguments can be concatenated together to form messages. See sprintf for more control over the formatting of numbers.

 > $i≔5$
 ${i}{≔}{5}$ (11)
 > $\mathrm{cat}\left("The value of i is",i,"."\right)$
 ${"The value of i is 5."}$ (12)

Functions are not converted to strings, rather || structures are returned.

 > $\mathrm{cat}\left("a",b\left(\right)\right)$
 ${"a"}{‖}\left({b}{}\left(\right)\right)$ (13)

Uneval quotes are needed to prevent execution when using a function as an argument to cat.

 > f := proc() local a, b; a,b; end proc:
 > $\mathrm{cat}\left(f\left(\right),c\right)$
 ${\mathrm{abc}}$ (14)
 > $\mathrm{cat}\left('f\left(\right)',c\right)$
 ${f}{}\left(\right){‖}{c}$ (15)

When leading arguments appear before an indexed name, the concatenation is based on the name part, excluding the index.

 > $\mathrm{cat}\left(a,b,c\left[1\right]\right)$
 ${{\mathrm{abc}}}_{{1}}$ (16)

Arguments that follow an indexed name do not treat the index specially.

 > $\mathrm{cat}\left("",a,b\left[1\right],c\right)$
 ${"ab\left[1\right]c"}$ (17)

Indexed variables that are not names are not treated specially.

 > $\mathrm{cat}\left("a",F\left(\right)\left[1\right]\right)$
 ${"aF\left(\right)\left[1\right]"}$ (18)

Be careful to note what is part of the name and what is not. The following is entirely a name, not an indexed object:

 > $\mathrm{cat}\left(a,F\left(\right)\left[1\right]\right)$
 ${\mathrm{aF\left(\right)\left[1\right]}}$ (19)
 > $\mathrm{lprint}\left(\mathrm{cat}\left(a,f\left(\right)\left[1\right]\right)\right)$
 aa

This example shows how cat can work with a sequence of arguments; in this case interleaving a colon character between words.

 > tr := proc(s::string,src::string,dst::string) cat( op( map( x -> if( x = src, dst, x ), [ seq( i, i = s ) ] ) ) ); end proc;
 ${\mathrm{tr}}{≔}{\mathbf{proc}}\left({s}{::}{\mathrm{string}}{,}{\mathrm{src}}{::}{\mathrm{string}}{,}{\mathrm{dst}}{::}{\mathrm{string}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{i}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{cat}}{}\left({\mathrm{op}}{}\left({\mathrm{map}}{}\left({x}{→}{\mathrm{if}}{}\left({x}{=}{\mathrm{src}}{,}{\mathrm{dst}}{,}{x}\right){,}\left[{\mathrm{seq}}{}\left({i}{,}{i}{=}{s}\right)\right]\right)\right)\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (20)
 > $\mathrm{tr}\left(,"",":"\right)$
 ${"The:value:of:i:is:5."}$ (21)

These examples illustrate the use of ranges to produce sequences of names. The range endpoints must be integers or single-character strings.

 > $\mathrm{cat}\left(a,1..10\right)$
 ${\mathrm{a1}}{,}{\mathrm{a2}}{,}{\mathrm{a3}}{,}{\mathrm{a4}}{,}{\mathrm{a5}}{,}{\mathrm{a6}}{,}{\mathrm{a7}}{,}{\mathrm{a8}}{,}{\mathrm{a9}}{,}{\mathrm{a10}}$ (22)
 > $\mathrm{cat}\left(a,1..2,5..6\right)$
 ${\mathrm{a15}}{,}{\mathrm{a16}}{,}{\mathrm{a25}}{,}{\mathrm{a26}}$ (23)
 > $\mathrm{cat}\left(a,1..2,5..6,3..4\right)$
 ${\mathrm{a153}}{,}{\mathrm{a154}}{,}{\mathrm{a163}}{,}{\mathrm{a164}}{,}{\mathrm{a253}}{,}{\mathrm{a254}}{,}{\mathrm{a263}}{,}{\mathrm{a264}}$ (24)
 > $\mathrm{cat}\left(a,"x".."z"\right)$
 ${\mathrm{ax}}{,}{\mathrm{ay}}{,}{\mathrm{az}}$ (25)
 > $\mathrm{cat}\left(A..\mathrm{D},a\right)$
 ${\mathrm{Aa}}{,}{\mathrm{Ba}}{,}{\mathrm{Ca}}{,}{\mathrm{Da}}$ (26)

The following shows how to make global assignments from within procedures. It illustrates the fact that only global names are returned by cat.

 > gassign := proc(n::name,e::anything)   assign(cat(n),e); end proc:
 > g := proc()   local a;   a := 5;   gassign( 'a', 2 ); end proc:
 > $a$
 ${a}$ (27)
 > $g\left(\right)$
 > $a$
 ${2}$ (28)

Compatibility

 • The cat command was updated in Maple 2015.