Error calling some functions in DataStructures

72 views
Skip to first unread message

Richard Thanki

unread,
Feb 20, 2014, 6:54:00 AM2/20/14
to julia...@googlegroups.com
Hi!

I'm new to Julia and I hope to use it for an agent-based model that I'm building.

I've downloaded and installed the DataStructures package, and am trying to use the mutable_binary_minheap structure. I can instantiate a minheap, push to it and pop from it, but two very important functions claim that they're not defined: update! and top. Both return an "ERROR: x not defined".

But when i look at the source code they both seem correctly defined (the code on my machine matches that online). This error is there with 0.21 as well as 0.3 pre-release.

Ivar Nesje

unread,
Feb 20, 2014, 8:01:27 AM2/20/14
to julia...@googlegroups.com
How does your code for using mutable_binary_minheap look? Can you post it (or at best a minimal failing example) to gist.github.com, or another place where I can find it online?

There is no variable named x in the linked code, so the error is probably in your code.

Ivar

Richard Thanki

unread,
Feb 20, 2014, 8:10:22 AM2/20/14
to julia...@googlegroups.com
here you go

https://gist.github.com/lePereT/9113170

ps the x was my unwise insertion in a code block :) 

Ivar Nesje

unread,
Feb 20, 2014, 8:18:30 AM2/20/14
to julia...@googlegroups.com
That was better.

The problem is that you `import DataStructures` instead of `using DataStructures`. If you use `import` you will need to use the fully qualified name.

The push! and pop! functions exist in Base. DataStructures extends them with new methods to work with binary heap.

update! and top does not exist in Base, so DataStructures defines its own function witch you can access with 

    import DataStructures
    DataStructures.update!()

or
    using DataStructures
    update!()

Ivar

Richard Thanki

unread,
Feb 20, 2014, 8:27:36 AM2/20/14
to julia...@googlegroups.com
Tusen Takk Ivar!

A newbie misstep :) Is either of these two methods preferred?

Ivar Nesje

unread,
Feb 20, 2014, 8:50:29 AM2/20/14
to julia...@googlegroups.com
Most Julia programs use `using`, but we have both `using` and `import` because there are good reasons for both.

Import is does not clutter your namespace, and naming collisions for `using` is currently problematic (see: #4345). A problem with `import` is that when packages extends functions from Base with new method definitions, the result is confusing (as you apparently found out).

Ivar
Reply all
Reply to author
Forward
0 new messages