cat
concatenating expressions
Calling Sequence
Parameters
Description
Thread Safety
Examples
Compatibility
cat( a, b, c, ... )
a, b, c, ...
-
any expressions
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.
For more information on thread safety, see index/threadsafe.
The type (name or string) of the result depends on the type of the left-hand operand.
cat⁡a,b
ab
Use an empty name or string as the leading argument to force the return type to be what you want.
cat⁡``,b
b
cat⁡,b
Other types will be converted to form part of the name or string.
cat⁡a,2
a2
cat⁡a,2,x2+1
a2x^2+1
cat⁡a = ,2.5
a = 2.5
Uneval quotes will suppress evaluation causing the named variable to be part of the result instead of its assigned value.
l≔left:
r≔right:
cat⁡l,r
leftright
lright
Multiple arguments can be concatenated together to form messages. See sprintf for more control over the formatting of numbers.
i≔5
cat⁡The value of i is ,i,.
The value of i is 5.
Functions are not converted to strings, rather || structures are returned.
cat⁡a,b⁡
a‖b⁡
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:
cat⁡f⁡,c
abc
f⁡‖c
When leading arguments appear before an indexed name, the concatenation is based on the name part, excluding the index.
cat⁡a,b,c1
abc1
Arguments that follow an indexed name do not treat the index specially.
cat⁡,a,b1,c
ab[1]c
Indexed variables that are not names are not treated specially.
cat⁡a,F⁡1
aF()[1]
Be careful to note what is part of the name and what is not. The following is entirely a name, not an indexed object:
lprint⁡cat⁡a,f⁡1
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;
tr ≔ procs::string,src::string,dst::stringlocali;cat⁡op⁡map⁡x→if⁡x=src,dst,x,seq⁡i,i=send proc
tr⁡, ,:
The:value:of:i:is:5.
These examples illustrate the use of ranges to produce sequences of names. The range endpoints must be integers or single-character strings.
cat⁡a,1..10
a1,a2,a3,a4,a5,a6,a7,a8,a9,a10
cat⁡a,1..2,5..6
a15,a16,a25,a26
cat⁡a,1..2,5..6,3..4
a153,a154,a163,a164,a253,a254,a263,a264
cat⁡a,x..z
ax,ay,az
cat⁡A..D,a
Aa,Ba,Ca,Da
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
g⁡
2
The cat command was updated in Maple 2015.
See Also
length
sprintf
StringTools:-FormatMessage
substring
type/||
||
Download Help Document