Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to determine if dict value is dict?

75 views
Skip to first unread message

anj patnaik

unread,
Jul 23, 2015, 4:19:34 PM7/23/15
to
Is there a way in tcl 8.4 to determine if the value is a dict itself?

Thanks

anj patnaik

unread,
Jul 23, 2015, 4:22:38 PM7/23/15
to
On Thursday, July 23, 2015 at 4:19:34 PM UTC-4, anj patnaik wrote:
> Is there a way in tcl 8.4 to determine if the value is a dict itself?
>
> Thanks

Are there any examples of nested dict traversals in 8.4?

Andreas Leitgeb

unread,
Jul 23, 2015, 6:06:57 PM7/23/15
to
anj patnaik <pat...@gmail.com> wrote:
> On Thursday, July 23, 2015 at 4:19:34 PM UTC-4, anj patnaik wrote:
>> Is there a way in tcl 8.4 to determine if the value is a dict itself?
> Are there any examples of nested dict traversals in 8.4?

tcl 8.4 is like stone age, and back then, dict wasn't yet part of tcl.

There existed an extension though to 'backport' the dict to 8.4.

Most likely, that extension would contain everything needed for nested
dict traversal, but I never used the dict extension, myself.

pal...@yahoo.com

unread,
Jul 24, 2015, 12:05:40 AM7/24/15
to
On Friday, July 24, 2015 at 1:49:34 AM UTC+5:30, anj patnaik wrote:
> Is there a way in tcl 8.4 to determine if the value is a dict itself?
>
> Thanks

The short answer is no (irrespective of the Tcl version). For example, the value may be "x y". There is no way to tell if that represents a dict with key x. Knowledge of a dict structure has to be embedded in application code. So you cannot (for example) write *generic* code that will traverse nested dictionaries where the depth is arbitrary for each key.


/Ashok

tombert

unread,
Jul 24, 2015, 7:49:42 AM7/24/15
to
On Thursday, 23 July 2015 22:19:34 UTC+2, anj patnaik wrote:
> Is there a way in tcl 8.4 to determine if the value is a dict itself?
>
> Thanks

I would say everything is/canbe a dict if it is a multiple of 2 elements:

{x 1} # two list elements
{x {1 2 3}} # still two list elements
{x {1 2 3} y 1} # four list elements
{x {1 2 3 4} y 1} # the second element {1 2 3 4} can be seen as dictionary as well

So there is only a way to tell if dict can read the list, but not if it makes sense.

Rich

unread,
Jul 24, 2015, 8:41:39 AM7/24/15
to
Actually "x y" can be:

1) the three character string "x y"
2) a two element list, with elements x and y
3) a one element dict, with key x and value y

0 new messages