dictchannel.jl example

68 views
Skip to first unread message

Jon Norberg

unread,
Jun 28, 2016, 11:26:04 AM6/28/16
to julia-users
I have great use of the dictchannel.jl example. I wanted to add the method keys to it so I thought that I simply add the function:

function keys(D::DictChannel)
keys(D.d)
end

as well s add the function name in the import (I tried also without adding the "keys") :

import Base: put!, wait, isready, take!, fetch, keys

to the file, I then include("dictchannel.jl").

All functions e.g. put!() and fetch() work as should but for my new function I get:

LoadError: MethodError: `keys` has no method matching keys(::RemoteRef{DictChannel})

Not sure what I am doing wrong so any help appreciated

Jon Norberg

unread,
Jun 28, 2016, 11:30:43 AM6/28/16
to julia-users
the dictchannel is in the julia package as an example of Channels

https://github.com/JuliaLang/julia/blob/master/examples/dictchannel.jl

Kristoffer Carlsson

unread,
Jun 28, 2016, 1:50:57 PM6/28/16
to julia-users
You have defined a keys method for a DictChannel but the error message is for a RemoteRef{DictChannel} which you have no method for.

Jon Norberg

unread,
Jun 28, 2016, 2:29:06 PM6/28/16
to julia-users
Strangely makning a function

function keys(D::RemoteRef{DictChannel})
keys(D.d)
end

Gives also error:

LoadError: type RemoteRef has no field d

Also, for the function put! That does work the function looks like:

function put!(D::DictChannel, k, v)
D.d[k] = v
notify(D.cond_take)
D
end

It just makes no sense to me way keys(D.d) Should not work in the same way.

Kristoffer Carlsson

unread,
Jun 28, 2016, 2:51:37 PM6/28/16
to julia-users
I believe you need to "fetch" the value in the RemoteRef. This should return your Dict that you can then use keys on.

Jon Norberg

unread,
Jun 28, 2016, 3:34:09 PM6/28/16
to julia-users
Strangely though, if I modify the put! function as:

function put!(D::DictChannel, k, v)
D.d[k] = v
notify(D.cond_take)

Println(keys(D.d))
D
end

And run this I get

Any[2,3,1]

(I added keps in that order), i.e. This works

So it seemed the function definition of keys does not work in the same way as for put! For some reason and I can't figure out why

Reply all
Reply to author
Forward
0 new messages