Re: Differences between q and Q

"[email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
Thanks. Yes, I think it deserves a mention. For the record, here are some thoughts from some discussion I had with Paolo offline.
 

 --------- Should Q suppress scheduled output? 
 
Suppress - Q means "Bail out immediately". That is what it does right now, including suppressing scheduled output. So keep suppressing.
 
Do not suppress - The decision to schedule output was already made and should be honored. So do not suppress.
 
According to Paolo, Q was modeled after d. The idea of "Q" was basically "same as d, but quit instead of starting the next cycle". That is a good reason not to suppress scheduled output, assuming d works "correctly". 
 
 

 --------- Does d work "correctly"?
 
The original paper by Lee McMahon said - "The d function deletes from the file (does not write to the output) all those lines matched by  its address(es). It also has the side effect that no further commands are attempted on the corpse of a deleted line; as soon as the d function is executed, a new line is read from the input, and the list of  editing commands is re-started from the beginning on the new line."
 
Read literally, "as soon as the d function is executed, a new line is read from the input" argues that d should suppress (not allow) scheduled output. I doubt the behavior of d is going to be changed at this point, but it does seem different from the original stated behavior.
 

 --------- Maybe i should schedule output? 
 
I always thought of i and a being closely related. But i does not schedule output, so is not that close. 
 
Again from the McMahon paper - "The i function behaves identically to the a  function, except  that <text> is written to the output before the matched line.  All other comments about the a  function apply to the i function as well."
 
Well, "identically" and "all other comments apply" suggest to me that i should also schedule output for later. Currently, we have: 
 
$ echo y | sed -e ix -e p 
x 
y 
y 
 
So currently, of course, i prints immediately, just like the GNU sed manual says. It would be like this if i command scheduled output: 
 
$ echo y | sed -e ix -e p 
y 
x 
y 
 
The proposed alternative would have i schedule to print before AutoPrint ("before the matched line"), analogous to a, and in accord with what was originally written by McMahon. Again, I doubt this is going to change at this point. I don't see any particular advantage between scheduling or printing immediately. Just seems like the current behavior differs from original stated behavior.
 
 

 ------------------- FWIW, my opinions
 
I think scheduled output should always get printed. So I think Q should be "fixed" so that scheduled output is printed. 
 
I think d should stay as is (print scheduled output), regardless of possibly mistaken wording by Lee McMahon, written many decades ago. 
 
I think i should schedule (not immediately print) output, analogous to a, and in accord with how the language was apparently intended. 
 
-------------- 
 
This discussion does not cover fundamental parts of using sed. These are just minor issues that were brought to my attention by Anders. The suggested changes to i or Q would probably affect very few, if anyone. But perhaps there is some incredibly imaginative sed script playing Sudoku or other game that would be impacted. So maybe better to leave things the (somewhat arbitrary) way they are, and just make sure everything is documented correctly (my original reason for posting).
 
Thanks, 
Daniel 
 



[Non-text portions of this message have been removed]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.