You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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: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 handcreate-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.
The text was updated successfully, but these errors were encountered: