JLD.jl icon indicating copy to clipboard operation
JLD.jl copied to clipboard

should has(jld,name) work?

Open ggggggggg opened this issue 10 years ago • 5 comments
trafficstars

Consider

jld = jldopen("test.jld","w")
jld["a"]=1
has(jld,"a") # ERROR: MethodError: `has` has no method ...
has(jld.plain,"a")

Is there a reason this doesn't work?

ggggggggg avatar Sep 18 '15 17:09 ggggggggg

You're looking for haskey, not has. But yes, it would be nice if this worked, so that jld behaved like an associative structure.

jiahao avatar Sep 18 '15 18:09 jiahao

Is there a reason this doesn't work?

No good reason.

timholy avatar Sep 18 '15 18:09 timholy

I first looked for haskey. But I posted about has because that works for the plain HDF5File. I'm happy to try to add this.

It seems like JLDFile (and HDF5File) should are kind of emulating an associative like Dict, but with many deviations. . What would you think about doing the following for both JLDFile and HDF5File (in HDF5.jl of course):

  • Add haskey
  • Add keys methods that do the same thing as names(jld)

ggggggggg avatar Sep 18 '15 18:09 ggggggggg

It's worth thinking a bit more about how exactly JLDFile is similar to a Dict and how it isn't.

jiahao avatar Sep 18 '15 18:09 jiahao

Probably a lot of the deviations are due to the fact that these packages date from the julia 0.2 days.

In general I'd say it would be best if it emulated the Dict interface wherever it makes sense. At the moment, I'm failing to think of a way in which it shouldn't act like a Dict.

timholy avatar Sep 18 '15 18:09 timholy