factor/libs/xml/example.factor

27 lines
647 B
Factor
Raw Normal View History

2006-11-23 19:37:41 -05:00
! Copyright (C) 2005, 2006 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
IN: xml-arith
2006-11-18 01:01:11 -05:00
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 ;