From joao.galamba at runbox.com Tue Apr 3 22:49:31 2007 From: joao.galamba at runbox.com (Joao Galamba) Date: Tue, 03 Apr 2007 23:49:31 +0100 (WEST) Subject: [cl-utilities-devel] FILTER and more Message-ID: Hi Peter, After adding cl-utilities to my projects and reimplementing my own set of utilities in terms of it, I wrote some code that might be useful (I hope) for cl-utilities: - filter/-if I don't know if this qualifies as one of those "semi-standard things that everybody writes", but I can't think of a reason for not to, specially because it's so handy and mentioned in several books. So I decided to send you my filter implementation, which I reimplemented after browsing through the cl-utilities code. The signatures are: (defun filter-if (fn list &key (key #'identity)) "Filter LIST using function FN returning whatever FN returns." (defun filter (item/filter-set list &key (key #'identity) (test #'equal) (filter-set nil) (filter-key #'identity)) "Filter ITEM/FILTER-SET from LIST. Similar to FIND but all 'found' items are returned. If ITEM/FILTER-SET is a list, FILTER can either filter each of its elements or just consider that list to be an item. This behaviour is controlled by FILTER-SET being set to T or not. Note that the first behaviour is similar to INTERSECTION but one can use key functions for both lists." - When writing 'filter/-if' I also wrote a macro that is similar to 'once-only' but suited for function calls. While still preventing multiple-evaluation problems, it tries to avoid funcalling when it already knows the function designator to use. The name probably it's not the best but for now it's called 'once-only-calls'. 'once-only-calls' is useful to write macros when you want to inline calls to functions, namely key and test functions. 'filter/-if' both need this macro. - A macro to define 'switchable compiler-macros'. Signature and usage are the same of define-compiler-macro. Basically, if you define a compiler macro with this macro you can then easily switch it off/on (ex: to trace function calls when debugging/profiling) by calling the method 'switch-compiler-optimizations' and then recompiling the code. 'filter/-if' compiler macros are defined with this macro. It's in file 'utilities/compilation-utilities.lisp' - times This is just a handy iteration macro. (times 10 (bla1) (bla2)) executes 10 times 'bla1' and 'bla2'and returns the value of the last 'bla2'. It's an emulation of the Ruby syntax '10.times {do_something}'. I don't use anywhere elsewhere except in the testing code. Probably there is a 'loop' construct that is better than this one. I have no idea since I don't use 'loop' and none of the books that I have checked refer to a shorter syntax. I'm sending you as well some unit (5am) and benchmarking (for a small and untested benchmark profiler devoped by moi) tests. These are found in asdf module utilities-testing. Everything was tested with sbcl, cmucl, lispworks and clisp, all under FreeBSD. All the above utilities are defined in their own files which are extensively commented. Hope this is of any use and let me know if you any questions or comments. Cheers, Joao -------------- next part -------------- A non-text attachment was scrubbed... Name: utilities.tgz Type: application/x-compressed-tar Size: 9434 bytes Desc: not available URL: