Using julia: Version 0.3.3 (2014-10-21 20:18 UTC)

This is the simplest example I could come up with to explain the issue.
In this case, the method "something" is not in scope.

module Person
  export say_something
  function say_something()
    println(something())
  end 
end


using Person


function something()
  "default something"
end


Person.say_something()


The output:

$ julia test2.jl 
ERROR: something not defined
 in say_something at /tmp/test2.jl:4
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start_3B_1720 at /usr/bin/../lib/x86_64-linux-gnu/julia/sys.so
while loading /tmp/test2.jl, in expression starting on line 14


More along the lines of my use case is this example, where my goal is to 
call to a generic method that knows to look back to a method the caller 
defines, in this case, it's "something" again:

module Person
  export say_something
  function say_something()
    println(something())
  end
end


module Boy
  using Person
  function something()
    "I'm a boy."
  end
end


module Girl
  using Person
  function something()
    "I'm a girl."
  end
end


Boy.say_something()
Girl.say_something()

Same error:

$ julia test.jl 
ERROR: something not defined
 in say_something at /tmp/test.jl:4
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start_3B_1720 at /usr/bin/../lib/x86_64-linux-gnu/julia/sys.so
while loading /tmp/test.jl, in expression starting on line 22

In ruby, this example works, albeit with classes:

module Person

  def say_something
    p something
  end
end


class Boy
  include Person
  def something
    "I'm a boy."
  end
end


class Girl
  include Person
  def something
    "I'm a girl."
  end
end


Boy.new.say_something
Girl.new.say_something


Outputting: 

$ ruby test.rb 
"I'm a boy."
"I'm a girl."

Is there anyway to accomplish this in julia?

Thank you,

- Charlie

Reply via email to