It would be nice if there was a function which, given a regexp (or the source of one), would return a count of the number of registers in it (in other words the length of the arrays that scan will return on a match for this regexp. It's not quite clear to me that that's fixed for a specific regexp (things like "(x)|y" for instance) but I think it is in fact.
The reason this would be useful is that it would enable case-like macros which treat regexps as literals to move a check from run-time to macroexpansion-time and hence catch program errors ealier. As an example I have a macro called regexp-case where this:
(regexp-case v
("^fo(o)?" (:registers (a b))
...))
is an error (more register variables than registers) but that error must be checked at run time, when it could be checked at macroexpansion time. The run-time check is extremely cheap (a known constant against the length of a vector) but having it at macroexpansion time would mean errors got caught earlier.
For the non ACL case an easy solution would be to return the number of registers from create-scanner as an additional value as it knows it. But that's arguably an incompatible change as anything which actually checks the number of values would break, if there is anything that does that. On the other hand create-scanner can already return only one value in the case of a function.
I don't know how it could be fixed for ACL since I'm not familiar with it any more.
This is probably too rare a case to justify a change, but I thought I would suggest it.
It would be nice if there was a function which, given a regexp (or the source of one), would return a count of the number of registers in it (in other words the length of the arrays that
scanwill return on a match for this regexp. It's not quite clear to me that that's fixed for a specific regexp (things like"(x)|y"for instance) but I think it is in fact.The reason this would be useful is that it would enable case-like macros which treat regexps as literals to move a check from run-time to macroexpansion-time and hence catch program errors ealier. As an example I have a macro called
regexp-casewhere this:is an error (more register variables than registers) but that error must be checked at run time, when it could be checked at macroexpansion time. The run-time check is extremely cheap (a known constant against the length of a vector) but having it at macroexpansion time would mean errors got caught earlier.
For the non ACL case an easy solution would be to return the number of registers from
create-scanneras an additional value as it knows it. But that's arguably an incompatible change as anything which actually checks the number of values would break, if there is anything that does that. On the other handcreate-scannercan already return only one value in the case of a function.I don't know how it could be fixed for ACL since I'm not familiar with it any more.
This is probably too rare a case to justify a change, but I thought I would suggest it.