1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
%mathpiper
/*
This is the beginnings of a Kind function which will return:
1) If u is an atomic expression, return the type of the expression.
2) If u is a compund expression, return the operator at the root of the
expression tree.
pp.104 "Computer Algebra And Symbolic Computation: Elementary Algorithms" Cohen.
*/
Retract("Kind",*);
RuleBase("Kind",{u});
//HoldArg("Kind",u);
10 # Kind(_u) <--
[
Write(u,,);
Local(result);
if(IsInteger(u))
[
result := integer;
Echo(1);
]
else if(IsString(u))
[
result := string;
Echo(2);
]
else if(IsList(u))
[
result := list;
Echo(3);
]
else if(Not IsBound(Eval(u)))
[
result := symbol;
Echo(10);
]
else
[
];
result;
];
Kind({3});
%/mathpiper
%output,preserve="false"
Result: list
Side Effects:
{3},3
. %/output
|