[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Translator
Date: Fri, 14 Sep 90 10:59:53+0900
From: kddlab!atr-ln.atr.co.jp!myers@uunet.UU.NET (John K. Myers)
The question is how to rapidly associate a name with a rewriting function.
Three methods come immediately to mind:
1) Use a CASE on the names, to get to the functions;
2) Use the name as a key to a hash-table that stores the functions;
3) Use the name to build a function-name, using (intern (string-append )).
Then call the function using (apply func-name).
Which one do you think is fastest? Does CASE somehow use pointers, or
does it have to cycle through its indices while comparing them (giving
O(n/2) time)? How efficient are Symbolics hash-tables?
Does intern need to look up the name in a hash-table? How about apply?
CASE has to cycle through all the names, so it will almost certainly be the
slowest (the only time CASE is optimized is when all the keys are integers
within a small range, as the case value can then be used as an index into a
dispatch table).
Packages are implemented as hash tables, so INTERN has to do a hash table
lookup. Therefore, the INTERN case should be slower than the plain hash
table.
APPLY of a symbol doesn't do any lookup, it just extracts the function from
the symbol's function cell.
Is there any good way to intercept the "function undefined" trap
when method (3) is used with a new named structure unknown to my system?
Bind a handler for the SYS:UNDEFINED-FUNCTION condition. You can send
messages to the condition to find out the name of the function that it was
trying to call.
- References:
- Translator
- From: kddlab!atr-ln.atr.co.jp!myers@uunet.UU.NET (John K. Myers)