The type (name or string) of the result depends on the type of the left-hand operand.
Use an empty name or string as the leading argument to force the return type to be what you want.
Other types will be converted to form part of the name or string.
Uneval quotes will suppress evaluation causing the named variable to be part of the result instead of its assigned value.
Multiple arguments can be concatenated together to form messages. See sprintf for more control over the formatting of numbers.
Functions are not converted to strings, rather || structures are returned.
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:
|
When leading arguments appear before an indexed name, the concatenation is based on the name part, excluding the index.
Arguments that follow an indexed name do not treat the index specially.
Indexed variables that are not names are not treated specially.
Be careful to note what is part of the name and what is not. The following is entirely a name, not an indexed object:
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;
|
These examples illustrate the use of ranges to produce sequences of names. The range endpoints must be integers or single-character strings.
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:
|