############################################################ # # Illustrates Maple mechanism for extending type-checking # procedure 'type' to user-defined types. Similar # mechanisms exist for many other Maple procedures such # as 'diff', 'int', 'evalf', etc. # ############################################################ ############################################################ # Our representation of a tensor will be a four-element # list whose first element is the literal `TENSOR`. ############################################################ `type/tensor` := proc(x) type(x,list) and (nops(x) = 4) and (x[1] = `TENSOR`) end: ttype := proc(x) if type(x,tensor) then printf(`Object %a IS of type tensor\n`,x); else printf(`Object %a IS NOT of type tensor\n`,x); fi; end: t1 := [TENSOR,foo,foo,foo]: t2 := [VECTOR,foo,foo,foo]: t3 := [TENSOR,foo,foo]: t4 := {TENSOR,foo,foo}: ttype(t1): ttype(t2): ttype(t3): ttype(t4):