Rewrite Packages from Python

I am trying to advance my Julia language skill and (some concepts). Therefore am trying to work throw the book “Deep Learning and the Game of GO” but not writing the Code in Python but in Julia.

I get some problems with writing own packages and use it:
I have a file called manvbot.jl


include("dlgo/DLGO.jl")

function main()
    boardsize = 9
    game = newgame(boardsize)
...

main()
``

with this file I wanna use a local package.

Folder: dlgo
Files: DLGO.jl, gotypes.jl, goboard_slow.jl, ...

As you can see I include the module from DLGO.jl
```julia
module DLGO

__precompile__(false)

include("gotypes.jl")

include("goboard_slow.jl")

include("utils.jl")

include("agent/base.jl")

include("agent/helpers.jl")

include("agent/naive.jl")

export newgame

end

The problem is that I cannot find, the function newgame which is included in the file goboard_slow.jl ( shorted version below)

mutable struct Move{}
    point::Point
    ispass::Bool
    isresign::Bool
end


struct GoString{}
    color::Player
    stones::Set{Point}
    liberties::Set{Point}
end


mutable struct Board{}
    numrows::UInt8
    numcols::UInt8
    grid::Set{Point}
end


mutable struct GameState
    board::Board
    nextplayer::UInt8
    previousstate::Union{GameState, Nothing}
    lastmove::Union{Move, Nothing}
end


function newgame(boardsize::UInt)
    board = Board(boardsize)

    return GameState(board, black, Nothing, Nothing)
end

I am wondering why I can’t find the file newgame function? Error: ERROR: LoadError: UndefVarError: newgame not defined

From my understanding I include the code from the file (including the function) in the modul as the full code/text, which I again do in the in manvbot.jl script. Why is the function than undefined? Do I have any misscontecptions?

You’ll want to use using .DLGO as well there, after the include(...):

Then it should work & find the exported method. The reason for this is that what matters for namespacing is the module Name .. end part, NOT the file name/directory structure, as is the case in python.

Thanks for your reply:
I added the line: using DLGO after the include statement. But I get the error:

ERROR: LoadError: ArgumentError: Package DLGO not found in current path:
- Run `import Pkg; Pkg.add("DLGO")` to install the DLGO package.

Which I think is kind of strange, because I am able to do the include statement.
the calling script is in the same path as the folder dlgo. The folder contains some files as DLGO.jl as shown before.

using .DLGO with a dot, it means the module was defined in the current scope

2 Likes

One extra, how do I solve the problem within the package.

when I define some Constructor (for example) in File A and wanna use it in B of the module.

If they’re all in the same module, it should be directly accessible as long as you include the relevant files. You don’t have to have a module per file.