From: SourceForge.net <no...@so...> - 2005-07-03 19:44:22
|
Feature Requests item #1230253, was opened at 2005-06-30 11:07 Message generated for change (Comment added) made by dkf You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=360894&aid=1230253&group_id=10894 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: 18. Commands M-Z Group: None >Status: Deleted Resolution: Rejected >Priority: 1 Submitted By: Markus Elfring (elfring) Assigned to: Donal K. Fellows (dkf) Summary: match array Initial Comment: http://tcl.tk/man/tcl8.5/TclCmd/regexp.htm: I want that matches can be stored into an array instead of "subMatchVars". I imagine cases where I can not use finite and predefined variable names because the search pattern was dynamically constructed. ---------------------------------------------------------------------- >Comment By: Donal K. Fellows (dkf) Date: 2005-07-03 20:44 Message: Logged In: YES user_id=79902 To reaffirm: requested feature can be implemented using a Tcl procedure, and adding it to the core is a fair bit of effort which would be better spent elsewhere. All significant costs can be worked around in one way or another with existing facilities. ---------------------------------------------------------------------- Comment By: miguel sofer (msofer) Date: 2005-07-02 20:02 Message: Logged In: YES user_id=148712 The variable name "-" is just a mnemonic for "a variable that I actually do not care about, and will not be dereferencing". As to the performance win: trust me, it is not there in any simple implementation. It will actually be slower. It could be made marginally faster, at a complexity cost that is way beyond reasonable. Returning the ticket to dkf, as (a) this is not my area and (b) he did claim it. Please do not alter maintainer assignments arbitrarily. ---------------------------------------------------------------------- Comment By: Markus Elfring (elfring) Date: 2005-07-02 19:30 Message: Logged In: YES user_id=572001 What is your intention with the use of the variable name "-"? Well, I guess that this kind of loop for the conversion from a list to an array can be more efficiently implemented in C code. I assume that there are speed improvements and reduced memory consumption possible because the value copies to the variables (key, val) can be avoided in the internal processing. ---------------------------------------------------------------------- Comment By: miguel sofer (msofer) Date: 2005-07-02 14:36 Message: Logged In: YES user_id=148712 I still do not quite get it. I think you are proposing to have a builtin capability to do something like foreach {- key val} [regexp -all -inline $pattern $source] { set vector($key) $val } What should happen if the pattern does not always produce an even number of submatches? Would that be an error? What if the pattern is capable of producing an odd number of submatches, but doesn't with the particular input : error or not? As it is, I do not think the complication is really worth it. You can easily get this functionality in a proc. It is quite unlikely that the performance impact will be noticeable, if this is what is worrying you: proc calls and [set] are quite a bit faster than [regexp] in any case. ---------------------------------------------------------------------- Comment By: Markus Elfring (elfring) Date: 2005-07-02 08:45 Message: Logged In: YES user_id=572001 How do you think about this use case? I imagine the following function calls to import mapping tables into corresponding data structures. set source1 {Pi/3.1415,Tax/0.16,} set pattern1 {([^/]+)/(.+),} regexp -all -array vector1 $pattern1 $source1 regexp -all -list contents1 $pattern1 $source1 set source2 {1-title:23-name:456-address:} set pattern2 {([^\-]+)-(.*):} regexp -all -type array -param vector2 $pattern2 $source2 regexp -all -type list -param contents2 $pattern2 $source2 ---------------------------------------------------------------------- Comment By: miguel sofer (msofer) Date: 2005-07-01 23:57 Message: Logged In: YES user_id=148712 Correcting a bad typo in my last comment here: "... my opinion is that the core should NOT be doing it for you." ---------------------------------------------------------------------- Comment By: Donal K. Fellows (dkf) Date: 2005-07-01 22:57 Message: Logged In: YES user_id=79902 I see no need for such a thing. Quite apart from the -inline option described by Miguel, the -about option returns (among other things) the maximum number of subMatchVars required by a particular RE, so allowing for the construction of a command to perform the matching and place the submatches directly into any variable(s) chosen. This means that this would all be syntactic sugar at best (and is, of course, easily simulated using a procedure). (Maintainer Note: The [regexp] command, as opposed to the RE guts, is in Category 18) ---------------------------------------------------------------------- Comment By: miguel sofer (msofer) Date: 2005-07-01 17:14 Message: Logged In: YES user_id=148712 I do not fully understand the spec for your request: what would be the array keys for the different matches? If it is the order in which they are found, the list result is the correct format - just access themby [lindex], or [foreach]. Or convert to an array if you think you must. In that case, my opinion is that the core should be doing it for you. If the array keys are something else (maybe some part of the regular expression itself?), maybe ... Although it is not at all clear to me yet how we could do this. Can you please provide an example of what would happen if this feature is implemented? ---------------------------------------------------------------------- Comment By: Markus Elfring (elfring) Date: 2005-07-01 17:03 Message: Logged In: YES user_id=572001 Well, it can be one way for a solution. Can the extra conversion step of this list into an array be avoided? (Each data type has got its own advantages.) ---------------------------------------------------------------------- Comment By: miguel sofer (msofer) Date: 2005-06-30 12:01 Message: Logged In: YES user_id=148712 Doesn't the '-inline' option provide what you need? It returns the matches in a list. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=360894&aid=1230253&group_id=10894 |