On 4/25/2023 2:26 PM, Lawrence Emke wrote:structure. You can use on any literal lists or variable that satisfies this condition.
I understand the syntax to create a dict variable:
set dname [ dict create a b ]
Now compare these two commands:
dict append dname d e
and
dict get $dname d
in the first case the dict name does not require the de-reference $ character.
In the second command it does require the deference $ character.
This seems to be confusing. Don't force me to remember which case requires the de-reference $ character and which does not accept the $ character.
Maybe there is a hidden explanation (reason) other than the implementation of the command that does not just pop up to a new student. Please make it consistent. It will save time and effort to learn the language syntax.
I agree dict is hard to get used to.
Think of dict not as some new data structure in Tcl but rather as an interface consisting of a set of commands that operate on lists with an even number of elements. In fact, I suspect that many dict use cases are on lists that happen to have this
Under this light, the first one makes sense: you don't want to append to a literal list, i.e., a constant value. This will be like doing "5 = x + y" in C for example.
The second makes sense too because it acts as a get-method on a list that has an even number of elements. You don't want to be forced into creating a temporary dict variable out of your normal lists just to get some elements out of it.
I understand the syntax to create a dict variable:
set dname [ dict create a b ]
Now compare these two commands:
dict append dname d e
and
dict get $dname d
in the first case the dict name does not require the de-reference $ character.
In the second command it does require the deference $ character.
This seems to be confusing. Don't force me to remember which case requires the de-reference $ character and which does not accept the $ character.
Maybe there is a hidden explanation (reason) other than the implementation of the command that does not just pop up to a new student. Please make it consistent. It will save time and effort to learn the language syntax.
On 4/25/2023 11:51 AM, saitology9 wrote:structure. You can use on any literal lists or variable that satisfies this condition.
On 4/25/2023 2:26 PM, Lawrence Emke wrote:
I understand the syntax to create a dict variable:
set dname [ dict create a b ]
Now compare these two commands:
dict append dname d e
and
dict get $dname d
in the first case the dict name does not require the de-reference $ character.
In the second command it does require the deference $ character.
This seems to be confusing. Don't force me to remember which case requires the de-reference $ character and which does not accept the $ character.
Maybe there is a hidden explanation (reason) other than the implementation of the command that does not just pop up to a new student. Please make it consistent. It will save time and effort to learn the language syntax.
I agree dict is hard to get used to.
Think of dict not as some new data structure in Tcl but rather as an interface consisting of a set of commands that operate on lists with an even number of elements. In fact, I suspect that many dict use cases are on lists that happen to have this
Under this light, the first one makes sense: you don't want to append to a literal list, i.e., a constant value. This will be like doing "5 = x + y" in C for example.
The second makes sense too because it acts as a get-method on a list that has an even number of elements. You don't want to be forced into creating a temporary dict variable out of your normal lists just to get some elements out of it.
Commands that modify an existing variable, are call by name
if the variable's value is needed, then it's by value $value
that's how I remember them. Similar to say, lappend, lset etc.
which modify a current list are by name vs. lindex, lrange,
which take a list and return a new one or part of one are by value.
Incidentally, the dict append manual entry does not say that
if the variable doesn't exist, then it is created first as
an empty dict. But that is consistent with such commands as
[incr]. And so too [dict incr] which also doesn't mention that
a non existent key is treated as a 0 and then incremented.
On Tuesday, April 25, 2023 at 1:59:22 PM UTC-5, et99 wrote:structure. You can use on any literal lists or variable that satisfies this condition.
On 4/25/2023 11:51 AM, saitology9 wrote:
On 4/25/2023 2:26 PM, Lawrence Emke wrote:
I understand the syntax to create a dict variable:
set dname [ dict create a b ]
Now compare these two commands:
dict append dname d e
and
dict get $dname d
in the first case the dict name does not require the de-reference $ character.
In the second command it does require the deference $ character.
This seems to be confusing. Don't force me to remember which case requires the de-reference $ character and which does not accept the $ character.
Maybe there is a hidden explanation (reason) other than the implementation of the command that does not just pop up to a new student. Please make it consistent. It will save time and effort to learn the language syntax.
I agree dict is hard to get used to.
Think of dict not as some new data structure in Tcl but rather as an interface consisting of a set of commands that operate on lists with an even number of elements. In fact, I suspect that many dict use cases are on lists that happen to have this
Under this light, the first one makes sense: you don't want to append to a literal list, i.e., a constant value. This will be like doing "5 = x + y" in C for example.
The second makes sense too because it acts as a get-method on a list that has an even number of elements. You don't want to be forced into creating a temporary dict variable out of your normal lists just to get some elements out of it.
reference the dict data via de-reference, to make itCommands that modify an existing variable, are call by name
if the variable's value is needed, then it's by value $value
that's how I remember them. Similar to say, lappend, lset etc.
which modify a current list are by name vs. lindex, lrange,
which take a list and return a new one or part of one are by value.
Incidentally, the dict append manual entry does not say thatThe problem is that the dict "name" is hard coded in the append command without the $ de-reference action. In the get sub command it must contain
if the variable doesn't exist, then it is created first as
an empty dict. But that is consistent with such commands as
[incr]. And so too [dict incr] which also doesn't mention that
a non existent key is treated as a 0 and then incremented.
a reference variable syntax. If you switch the $ syntax on the both statements,
neither statement executes correctly.
My goal is to separate the application data namespace from the proc/methods. By that I mean, having all of the app data in one namespace and the methods in one or more other namespaces. I want to avoid little namespaces hanging off
the applications data namespace. This means the dict append sub-command executed in a proc
that receives the data via a parameter should use a reference to the dict structure rather than coding its name.
The append sub-command needs receive the dict structure via a proc parameter variable. In this
way the dict structure can be passed as a parameter. The unset sub-command takes either the DictName
or a de-reference variable to the dict element. Both work. The same should be for the append sub-command
I have tried several configurations in proc calls. None of them work. I have considered the
level command. However, the actual dict structure may be a member of the caller's
namespace. I assume in this situation, the search for the parameter in the caller's namespace would fail, because it is a variable in the namespace passed to the caller. It might work? Don't know. Still the dict append sub-command needs to allow
simpler and more consistent. I have not tried the "set" sub-command, but if it is like you said, then
it also needs to be able to refer to the dict element via de-referenced variable name.
If I am not clear in my response, let me know.
thanks for the help. I will say no more.
I found out how to do it. just place the name of the dict variable in a variable and pass that variable as the dict element name proc parameter. Then the "dict append $n a b" gets executed with the correct DictNameOn 4/25/2023 2:26 PM, Lawrence Emke wrote:
I understand the syntax to create a dict variable:
set dname [ dict create a b ]
Now compare these two commands:
dict append dname d e
and
dict get $dname d
in the first case the dict name does not require the de-reference $ character.
In the second command it does require the deference $ character.
This seems to be confusing. Don't force me to remember which case requires the de-reference $ character and which does not accept the $ character.
I understand the syntax to create a dict variable:
set dname [ dict create a b ]
Now compare these two commands:
dict append dname d e
and
dict get $dname d
in the first case the dict name does not require the de-reference $ character.
In the second command it does require the deference $ character.
This seems to be confusing. Don't force me to remember which case requires the de-reference $ character and which does not accept the $ character.
Maybe there is a hidden explanation (reason) other than the implementation of the command that does not just pop up to a new student. Please make it consistent. It will save time and effort to learn the language syntax.
El martes, 25 de abril de 2023 a las 15:26:20 UTC-3, Lawrence Emke escribió:
I understand the syntax to create a dict variable:
set dname [ dict create a b ]
Now compare these two commands:
dict append dname d e
and
dict get $dname d
in the first case the dict name does not require the de-reference $ character.
In the second command it does require the deference $ character.
This seems to be confusing. Don't force me to remember which case requires the de-reference $ character and which does not accept the $ character.
Maybe there is a hidden explanation (reason) other than the implementation of the command that does not just pop up to a new student. Please make it consistent. It will save time and effort to learn the language syntax.
A good rule of thumb is that if the command has
* "set" (set, unset, dict set, dict unset, array set, array unset, lset),
* "append" (append, lappend, dict append, dict lappend)
* "incr" (incr, dict incr)
in its name, then it takes a *variable name* as argument.
The "inconsistent" commands that break these "rules" are [array get], [dict update]
and [dict with]. Also [lpop], which is a new command in the upcoming 8.7 release.
Hope this helps
Emiliano
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 152:54:09 |
| Calls: | 12,091 |
| Calls today: | 4 |
| Files: | 15,000 |
| Messages: | 6,517,662 |