cat - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Names and Strings : cat

cat

concatenating expressions

 

Calling Sequence

Parameters

Description

Thread Safety

Examples

Compatibility

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, ``.

Thread Safety

• 

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

• 

For more information on thread safety, see index/threadsafe.

Examples

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

cata,b

ab

(1)

cata,b

ab

(2)

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

cat``,b

b

(3)

cat,b

b

(4)

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

cata,2

a2

(5)

cata,2

a2

(6)

cata,2,x2+1

a2x^2+1

(7)

cata = ,2.5

a = 2.5

(8)

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

lleft:

rright:

catl,r

leftright

(9)

cat'l',r

lright

(10)

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

i5

i:=5

(11)

catThe value of i is ,i,.

The value of i is 5.

(12)

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

cata,b

a||b

(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:

catf,c

abc

(14)

cat'f',c

f||c

(15)

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

cata,b,c1

abc1

(16)

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

cat,a,b1,c

ab[1]c

(17)

Indexed variables that are not names are not treated specially.

cata,F1

aF()[1]

(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:

cata,F1

aF()[1]

(19)

lprintcata,f1

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::stringcatopmapx→ifx=src,dst,x,seqi,i=send proc

(20)

tr, ,:

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.

cata,1..10

a1,a2,a3,a4,a5,a6,a7,a8,a9,a10

(22)

cata,1..2,5..6

a15,a16,a25,a26

(23)

cata,1..2,5..6,3..4

a153,a154,a163,a164,a253,a254,a263,a264

(24)

cata,x..z

ax,ay,az

(25)

catA..D,a

Aa,Ba,Ca,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

a

2

(28)

Compatibility

• 

The cat command was updated in Maple 2015.

See Also

length

sprintf

StringTools:-FormatMessage

substring

type/||

||

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam