comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: bug? or how to distinguish between a Hash and an array of Hashes ?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83389] Mon, 04 March 2013 08:37 Go to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
thanks. Even for someone familiar with IDL, this seems somewhat
backwards. For the rest of the IDL data types we can distinguish
between array and scalar objects using SIZE(x, /N_Dimensions)... no?
Now for lists and hashes we have to check the typename() for HASH vs
OBJREF ? that can't be how it was intended..?

-Mark
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83390 is a reply to message #83389] Mon, 04 March 2013 08:28 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
The documentation for TYPENAME() explains that it is not exactly the same as SIZE(/TNAME)

"If Variable is a scalar object or a one-element object array, Result will be the object class name. If Variable is an object array with two or more elements, Result will be the IDL basic type name “OBJECT” [because each element of the object array could have a different class name]."

So with a scalar hash, TYPENAME() can return "HASH" but for an array it will return OBJREF (not "OBJECT" as the documentation wrongly says). --Wayne

On Monday, March 4, 2013 11:24:49 AM UTC-5, David Fanning wrote:
> David Fanning writes:
>
>
>
>>
>
>> wlandsman writes:
>
>>
>
>>> You could use the TYPENAME function to distinguish the two variables
>
>>>
>
>>> IDL> print,typename(a)
>
>>> HASH
>
>>> IDL> print,typename(c)
>
>>> OBJREF
>
>>>
>
>>> although I'm not sure why SIZE(/TNAME) doesn't give the same results.
>
>>
>
>> Oh, dear! Really!?
>
>
>
> I guess this is right, though, since there are no "type" codes for hash
>
> or list. They are objects, I guess, not real data types.
>
>
>
> Still, awfully confusing to explain to a new user not familiar with the
>
> "IDL Way". ;-)
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83391 is a reply to message #83390] Mon, 04 March 2013 08:24 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

>
> wlandsman writes:
>
>> You could use the TYPENAME function to distinguish the two variables
>>
>> IDL> print,typename(a)
>> HASH
>> IDL> print,typename(c)
>> OBJREF
>>
>> although I'm not sure why SIZE(/TNAME) doesn't give the same results.
>
> Oh, dear! Really!?

I guess this is right, though, since there are no "type" codes for hash
or list. They are objects, I guess, not real data types.

Still, awfully confusing to explain to a new user not familiar with the
"IDL Way". ;-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83392 is a reply to message #83391] Mon, 04 March 2013 08:16 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
wlandsman writes:

> You could use the TYPENAME function to distinguish the two variables
>
> IDL> print,typename(a)
> HASH
> IDL> print,typename(c)
> OBJREF
>
> although I'm not sure why SIZE(/TNAME) doesn't give the same results.

Oh, dear! Really!?

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83393 is a reply to message #83392] Mon, 04 March 2013 08:11 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
You could use the TYPENAME function to distinguish the two variables

IDL> print,typename(a)
HASH
IDL> print,typename(c)
OBJREF

although I'm not sure why SIZE(/TNAME) doesn't give the same results. --Wayne

On Monday, March 4, 2013 11:05:03 AM UTC-5, superchromix wrote:
> surprisingly, the ISA function doesn't help here either...
>
>
>
>
>
> pro test
>
>
>
> a = hash('first', 1, 'second', 2)
>
> b = hash('third', 3, 'fourth', 4, 'fifth', 5)
>
>
>
> print, 'Output of SIZE() for a HASH varible:'
>
> print, size(a, /STRUCTURE)
>
>
>
> c = [a,b]
>
> print, 'Output of SIZE() for an array of HASHes:'
>
> print, size(c, /STRUCTURE)
>
>
>
> print, 'Output of ISA(/ARRAY) for scalar hash:'
>
> print, isa(a, /array)
>
>
>
> print, 'Output of ISA(/ARRAY) for array of hashes:'
>
> print, isa(c, /array)
>
>
>
> help, a, output=ahelp
>
> help, c, output=chelp
>
>
>
> print, 'Help for scalar hash:'
>
> print, ahelp
>
>
>
> print, 'Help for array of hashes:'
>
> print, chelp
>
>
>
> end
>
>
>
> Output of SIZE() for a HASH varible:
>
> { OBJREF 11 0 0 2
>
> 1 2 0 0 0
>
> 0 0 0 0
>
> }
>
> Output of SIZE() for an array of HASHes:
>
> { OBJREF 11 0 0 2
>
> 1 2 0 0 0
>
> 0 0 0 0
>
> }
>
> Output of ISA(/ARRAY) for scalar hash:
>
> 1
>
> Output of ISA(/ARRAY) for array of hashes:
>
> 1
>
> Help for scalar hash:
>
> A HASH <ID=154 NELEMENTS=2>
>
> Help for array of hashes:
>
> C OBJREF = Array[2]
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83394 is a reply to message #83393] Mon, 04 March 2013 08:05 Go to previous messageGo to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
surprisingly, the ISA function doesn't help here either...


pro test

a = hash('first', 1, 'second', 2)
b = hash('third', 3, 'fourth', 4, 'fifth', 5)

print, 'Output of SIZE() for a HASH varible:'
print, size(a, /STRUCTURE)

c = [a,b]
print, 'Output of SIZE() for an array of HASHes:'
print, size(c, /STRUCTURE)

print, 'Output of ISA(/ARRAY) for scalar hash:'
print, isa(a, /array)

print, 'Output of ISA(/ARRAY) for array of hashes:'
print, isa(c, /array)

help, a, output=ahelp
help, c, output=chelp

print, 'Help for scalar hash:'
print, ahelp

print, 'Help for array of hashes:'
print, chelp

end

Output of SIZE() for a HASH varible:
{ OBJREF 11 0 0 2
1 2 0 0 0
0 0 0 0
}
Output of SIZE() for an array of HASHes:
{ OBJREF 11 0 0 2
1 2 0 0 0
0 0 0 0
}
Output of ISA(/ARRAY) for scalar hash:
1
Output of ISA(/ARRAY) for array of hashes:
1
Help for scalar hash:
A HASH <ID=154 NELEMENTS=2>
Help for array of hashes:
C OBJREF = Array[2]
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83395 is a reply to message #83394] Mon, 04 March 2013 06:39 Go to previous messageGo to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
I've updated this a bit. It seems that the HELP command can
distinguish between the two cases, but SIZE(), even with the /
STRUCTURE keyword specified, cannot.

pro test

a = hash('first', 1, 'second', 2)
b = hash('third', 3, 'fourth', 4, 'fifth', 5)

print, 'Output of SIZE() for a HASH varible:'
print, size(a, /STRUCTURE)

c = [a,b]
print, 'Output of SIZE() for an array of HASHes:'
print, size(c, /STRUCTURE)

help, a, output=ahelp
help, c, output=chelp

print, ahelp
print, chelp

end

IDL> test

Output of SIZE() for a HASH varible:

{ OBJREF 11 0 0 2
1 2 0 0 0
0 0 0 0
}

Output of SIZE() for an array of HASHes:

{ OBJREF 11 0 0 2
1 2 0 0 0
0 0 0 0
}

A HASH <ID=18 NELEMENTS=2>
C OBJREF = Array[2]

so I could solve this by parsing the output of HELP, but this is
strongly discouraged in the documentation for the IDL Help command
itself, as the text formatting of the output from this command my
change...
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83396 is a reply to message #83395] Mon, 04 March 2013 06:19 Go to previous messageGo to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
ps. my system is running IDL Version 8.0.1, Microsoft Windows (Win32
x86_64 m64)
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83469 is a reply to message #83396] Mon, 04 March 2013 09:00 Go to previous message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
> Except structures. There is no scalar structure, s={i:0} and a=replicate(s,2) are both arrays.
>
> regards,
> Lajos

good point. At least if you index a scalar structure as s[0], this
doesn't throw an error, unlike the case with the hash.
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83470 is a reply to message #83389] Mon, 04 March 2013 08:55 Go to previous message
Lajos Foldy is currently offline  Lajos Foldy
Messages: 176
Registered: December 2011
Senior Member
On Monday, March 4, 2013 5:37:26 PM UTC+1, superchromix wrote:
> thanks. Even for someone familiar with IDL, this seems somewhat
>
> backwards. For the rest of the IDL data types we can distinguish
>
> between array and scalar objects using SIZE(x, /N_Dimensions)... no?
>
> Now for lists and hashes we have to check the typename() for HASH vs
>
> OBJREF ? that can't be how it was intended..?
>
>
>
> -Mark

Except structures. There is no scalar structure, s={i:0} and a=replicate(s,2) are both arrays.

regards,
Lajos
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83471 is a reply to message #83389] Mon, 04 March 2013 08:47 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
I agree. I hope someone from Exelis will eventually chime in as to the best way to distinguish between scalar and array hashes or lists. --Wayne

On Monday, March 4, 2013 11:37:26 AM UTC-5, superchromix wrote:
> thanks. Even for someone familiar with IDL, this seems somewhat
>
> backwards. For the rest of the IDL data types we can distinguish
>
> between array and scalar objects using SIZE(x, /N_Dimensions)... no?
>
> Now for lists and hashes we have to check the typename() for HASH vs
>
> OBJREF ? that can't be how it was intended..?
>
>
>
> -Mark
Re: bug? or how to distinguish between a Hash and an array of Hashes ? [message #83472 is a reply to message #83389] Mon, 04 March 2013 08:44 Go to previous message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
oops I meant "array and scalar variables" above...

to make one other point, the ISA(/ARRAY) function is unambiguous in
its meaning.. it should return true for arrays and false for scalars,
regardless of whether the scalar is an object reference.

unless.. of course, the object refererence refers to an array-like
object I suppose... but in the case of hash objects if you try to do
this:

a=hash('first',1)

and then try to index it with a[0], this throws an error.

confusion! :)
Mark
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: bug? or how to distinguish between a Hash and an array of Hashes ?
Next Topic: Nan represented by a gray area

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:47:51 PDT 2025

Total time taken to generate the page: 0.01357 seconds