[2/2]
There are however two issues with your code. First, because
programs must be written for people to read, and only incidentally for machines to execute
keeping part of the iota count computation as (+ (- last first) 1) is the right thing to do, instead of having to pause for a second to satisfy oneself that the -1 is indeed right because it is inside the subtraction. The second issue is that your code actually introduces a performance downgrade. Because you have switched to a vanilla 'let', on the consequent branch of 'last' you are redoing the entire parsing and limiting work of 'first' from scratch for non-interval quote pieces. While expand-range is not in the innermost loop of posts-range, it is still in a loop, that of 'map'. As such, if I had control over what goes into SchemeBBS, which I don't, I would not accept such gratuitous duplication of the parsing and limiting work of the most frequent type of quote piece, when it is easily avoided. You need to switch back to let*, move the 'if' to the top level of 'last' and immediately reuse 'first' in the consequent.
I would also recommend using the name ``thunk'' instead of ``lamb''.
This is a very good idea.
Do you usually use these ``SYNC'' annotations in your projects?
I do not, because in code that I control I avoid having two sources of truth. The copypasting between quotelink and range? comes from the admin's same "check if posts range are valid" commit of "Feb 20, 2020". While I cannot speak for Bitdiddle, it is virtually certain that it was done this way because a quick fix was needed for a class of 500 errors in the previous posts-range, as you can see further up the thread. This is also why the assembled regex was included in >>32 in addition to the rules to assemble it from. The structure was kept in the performance fix as per the piggybacking explanation above. If you wish to submit a procedure to assemble the regex once, using the computed digit count, and use the result in range? and quotelink, you are welcome to do so. It would improve maintainability and clean up the code.
If you are interested in code organization improvements, you may wish to take a look at lib/markup.scm:line-scanner and the obvious copypasting going on there. That function is ripe for refactoring by extracting the repeated part. Here is one possible path:
https://textboard.org/prog/49#t49p4