factor/contrib/xml/example.factor

25 lines
552 B
Factor

IN: xml-stupid-math
USING: xml io kernel math sequences strings ;
PROCESS: calculate ( tag -- n )
: calc-2children ( tag -- n n )
children-tags first2 >r calculate r> calculate ;
TAG: number calculate
children>string string>number ;
TAG: add calculate
calc-2children + ;
TAG: minus calculate
calc-2children - ;
TAG: times calculate
calc-2children * ;
TAG: divide calculate
calc-2children / ;
TAG: neg calculate
children-tags first calculate neg ;
: calc-arith ( string -- n )
string>xml first-child-tag calculate ;