Consider the following
; CLISP Port: 1604 Pid: 3572 CL-USER> PG-USER> (register-groups-bind (x y z) ('(:sequence (:alternation (:register #\a) #\1) (:alternation (:register #\b) #\2) (:alternation (:register #\c) #\3)) "123") (values x y z)) NIL NIL NIL PG-USER> (register-groups-bind (x y z) ('(:sequence (:alternation (:register #\a) #\1) (:alternation (:register #\b) #\2) (:alternation (:register #\c) #\3)) "abc") (values x y z)) "a" "b" "c" PG-USER>
-----Original Message----- From: cl-ppcre-devel-bounces@common-lisp.net [mailto:cl-ppcre-devel-bounces@common-lisp.net] On Behalf Of dsb@prairienet.org Sent: Friday, April 06, 2007 10:09 AM To: cl-ppcre-devel@common-lisp.net Subject: [cl-ppcre-devel] register-groups-bind tests all groups for nil
Using register-groups-bind, sbcl generates a compiler warning if the user doesn't make sure each bound variable is non-nil before using it. Since the body is evaluated only if there's a match, testing bound variables seems kind of redundant for the first N variables, where N is the number of groups in the regex.
It looks like an IF form in register-groups-bind is the source of the warning. It checks all groups for nil-ness, even the first ones. I thought variables that match groups would be guaranteed to be non-nil. I would be nice to be able to use matching variables immediately as long as the user is careful not to bind extra ones.
I guess eliminating individual tests for bound groups would require that scan returns another value containing the number of matches, or truncates the register-groups array so that the number of matches is just the length of the array. Then matching variables could be bound directly, and extras could be set to nil without the IF.
--Dan prairienet.org/~dsb/
_______________________________________________ cl-ppcre-devel site list cl-ppcre-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/cl-ppcre-devel