Tcl Source Code

View Ticket
Login
Ticket UUID: 3551813
Title: Use @ to report offset in [binary scan]
Type: RFE Version: None
Submitter: stwo Created on: 2012-07-30 05:51:05
Subsystem: 12. ByteArray Object Assigned To: dkf
Priority: 7 High Severity: Minor
Status: Open Last Modified: 2021-04-10 10:36:30
Resolution: None Closed By: nobody
    Closed on:
Description:
Currently, using @ without an index in [binary scan] is an error.
The [binary scan] implementation can be easily modified to allow an @ without an index to report the 'current' offset, storing it in a variable, like with other format specifiers.
This makes it easier to track the offset; it must currently be done manually.
Attached is a patch for the code and a patch for some tests, for Tcl 8.5.12.
If this is 'approved' then I'll write more tests, adjust the documentation and submit new patches.
User Comments: q3cpma added on 2021-04-10 10:36:30:
After making a patch using '>' instead of 'p' (as this match the use of a symbol for '@' better, in my opinion), I just noticed the existence of this TIP. Any updates on this?

avl42 added on 2012-12-08 22:51:51:
The difference between "@ 42" and "p 42":  "@..."  with a count requires only a value argument (namely the count), not a variable name. If a blank crept into it, it would merrily treat some value argument as a variable and write a value into it, before it stumbles over the numeric literal and throws an error. At the time of error thrown, some random variable is already overwritten.  With "p 42", also an error would be thrown, but p would at least be given a variable name, to which a sane value is written, before the error get thrown on hitting blank 42.

That's my reason. If it is entirely unconvincing for you, then so be it. I'd consider the feature added your way with only @ to be still an improvement over current state, but I do think that using a new "p" is still better.

stwo added on 2012-12-08 18:08:48:
The reasoning in tip 410 for not wanting to use "@" is:      

'I consider a typo "@ 42 ..." to be common enough to not
want to give it a new unexpected meaning and side-effect.'

What sort of typo is "@ 42" and how would that be
different from "p 42"?

I like having "@" mean the same thing in [binary scan]
and [binary format]; it's less work for my brain.  

I'd like to move forward with this.
It's easy to do, makes sense and is useful.   
It's much more lightweight than anything tip'ed.
And there is an implementation. :)

dkf added on 2012-08-27 00:08:04:
See TIP #410 http://tip.tcl.tk/410.html

avl42 added on 2012-08-26 07:26:40:
I've just submitted a new TIP, where (among other things) I prefer a new character "p" to a no-count-@.
Once the TIP shows up, please read and judge my reasoning (in section "rejected alternatives").

stwo added on 2012-08-05 22:21:53:
Development continues in the stwo-dev86 branch on core.tcl.tk.

dkf added on 2012-07-30 17:09:26:
Seems like a reasonable idea. Not looked at the changes yet.

stwo added on 2012-07-30 12:52:05:

File Added - 450117: patch-tests_binary_test

stwo added on 2012-07-30 12:51:06:

File Added - 450116: patch-generic_tclBinary_c

Attachments: