Download ALisp User's Guide
Transcript
(MAKE-BTREE) Elements of a B-tree are accessed with (GET-BTREE KEY BTREE) SETF is used for modifying accessed B-tree element. For example: > (setq bt (make-btree)) #[BTREE 3396632] > (setf (get-btree "hello" bt) "world") "world" > (get-btree "hello" bt) "world" > System functions operating on main memory B-trees: Function Type Description (GET-BTREE K BT) EXTFN Get value of element with key K in B-tree BT. Comparison uses COMPARE. Allocate a new B-tree. (MAKE-BTREE) EXTFN (MAP-BTREE BT LOWER UPPER FN) EXTFN (PUT-BTREE K BT V) 3.10. EXTFN Apply ALisp function (FN KEY VAL) on each key-value pair in Btree BT whose key is larger than or equal to LOWER and less than or equal to UPPER. If any of LOWER or UPPER are the symbol ’*’ it means that the interval is open in that end. If both LOWER and UPPER are ’*’ the entire B-tree is scanned. Set the value stored in the B-tree BT under the key K to V. Same as (SETF (GET-BTREE K BT) V). V=NIL => marking element as deleted. NOTICE that the elements are not physically removed when V=NIL; they are just marked as deleted. To physically remove them you have to copy the B-tree. Functional arguments and dynamic forms Variables bound to functions or even entire expression can be invoked or evaluated by the system. Functional arguments (higher order functions) provide a very powerful abstraction mechanism that actually can replace many control structures in conventional programming languages. The map functions in Sec. 3.11 are examples of elaborate use of functional arguments. The simplest case for functional arguments is when a function is passed as arguments to some other function. For example, assume we want to make a max function, (SUM2 X Y FN) that calls the functional argument FN with X and Y as actual parameters and then adds together the result (i.e. sum2 = fn(x) + fn(y)): > (defun sum2 (x y fn) (+ (funcall fn x)(funcall fn y))) The system function FUNCALL calls FN 21