From ... From: Erik Naggum Subject: Re: Get subseq of alist using regexp mathcing on cars Date: 2000/07/26 Message-ID: <3173631943791755@naggum.net>#1/1 X-Deja-AN: 651124041 References: <8ln0j7$1qa$1@newsx.cc.uic.edu> <8ln4d4$2kk$1@newsx.cc.uic.edu> mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 964643352 11665 195.0.192.66 (26 Jul 2000 20:29:12 GMT) Organization: Naggum Software; vox: +47 8800 8879; fax: +47 8800 8601; http://naggum.no; http://naggum.net User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7 Mime-Version: 1.0 NNTP-Posting-Date: 26 Jul 2000 20:29:12 GMT Newsgroups: comp.lang.lisp * "Bruce Lambert" | This is what I came up with myself. It seems to work in the simple | case where the cars are all single-character symbols. This will | work for my current application. It could, of course, be much | fancier. I still welcome suggestions. I must admit to not having understood your original request, as "assoc" is just not what you're asking for. | "Takes a regular expression and an alist and returns the subsequence | of alist whose cars match the regexp. Assume cars are all symbols | whose print-names are single characters." It doesn't really assume that. The cars may be one-character strings, characters, or symbols with one-character names. (defun regexp-subseq (sequence regexp &key (key #'car)) (destructuring-bind (match &optional (start . end)) (multiple-value-list (match-regexp regexp (map 'string (compose #'character key) sequence) :return :index)) (if match (subseq sequence start end) nil))) compose is either a macro or a function that composes functions. In this case, it produces (lambda (x) (character (funcall key x))). #:Erik -- If this is not what you expected, please alter your expectations.