cast($)

Syntax

X $ Y

Arguments

X can be any data form.

Y is a data type or a pair.

Details

X $ Y can be used to:

  • Convert a data type to another data type.

  • Reshape a matrix.

  • Convert a matrix to a vector.

  • Convert a vector to a matrix.

Examples

$ x=8.9$INT;
$ x;
9

$ x=1..10;
$ x;
[1,2,3,4,5,6,7,8,9,10]
$ typestr x;
FAST INT VECTOR
$ x/2;
[0,1,1,2,2,3,3,4,4,5]
$ x=x$DOUBLE;
$ typestr x;
FAST DOUBLE VECTOR
$ x/2;
[0.5,1,1.5,2,2.5,3,3.5,4,4.5,5]

$ x=`IBM`MS;
$ typestr x;
STRING VECTOR
$ x=x$SYMBOL;
$ typestr x;
FAST SYMBOL VECTOR

$ x=`128.9;
$ typestr x;
STRING
$ x=x$INT;
$ x;
128
$ typestr x;
INT

// convert a vector to a matrix
$ m=1..8$2:4;
$ m;

#0

#1

#2

#3

1

3

5

7

2

4

6

8

// reshape a matrix
$ m$4:2;

#0

#1

1

5

2

6

3

7

4

8

$ m$1:size(m);

#0

#1

#2

#3

#4

#5

#6

#7

1

2

3

4

5

6

7

8