make eval() module local #1651

Closed
rephorm opened this Issue Dec 2, 2012 · 6 comments

Comments

Projects
None yet
6 participants
@rephorm

rephorm commented Dec 2, 2012

If I have a file named test.jl containing

module TestMod
    using Base

    load("strpack")

    type(Point)
        x::Int8
        y::Int8
    end

    function test_unpack()
        s = "\x01\x02"
        unpack(s, Point)
    end
end

and then from the repl run

load("test")
TestMod.test_unpack()

I get the following error:

in anonymous: DataAlign not defined
 in anonymous at no file
 in test at /home/bmattern/code/julia/test/test.jl:13

Does strpack need to be modularized in order to be used from a module?

@JeffBezanson

This comment has been minimized.

Show comment Hide comment
@JeffBezanson

JeffBezanson Dec 2, 2012

Owner

No, I believe this has to do with strpack's use of eval. I think we need some more work to decide how eval should work in modules. What I might do is bind an eval in each module that has the behavior of evaluating within that module.

Owner

JeffBezanson commented Dec 2, 2012

No, I believe this has to do with strpack's use of eval. I think we need some more work to decide how eval should work in modules. What I might do is bind an eval in each module that has the behavior of evaluating within that module.

@toivoh

This comment has been minimized.

Show comment Hide comment
@toivoh

toivoh Dec 2, 2012

Member

+1

Member

toivoh commented Dec 2, 2012

+1

@staticfloat

This comment has been minimized.

Show comment Hide comment
@staticfloat

staticfloat Dec 2, 2012

Owner

What I might do is bind an eval in each module that has the behavior of evaluating within that module.

This seems pretty intuitive, and what most people would expect when writing eval code.

EDIT: That's my way of saying "+1", I guess. :P

Owner

staticfloat commented Dec 2, 2012

What I might do is bind an eval in each module that has the behavior of evaluating within that module.

This seems pretty intuitive, and what most people would expect when writing eval code.

EDIT: That's my way of saying "+1", I guess. :P

@timholy

This comment has been minimized.

Show comment Hide comment
@timholy

timholy Dec 2, 2012

Owner

The workaround is to run Struct(Point) when still inside the module's scope, e.g.,

    type(Point)
        x::Int8
        y::Int8
    end
    Struct(Point)

    function test_unpack()
        ...

See #1378

@JeffBezanson, I like your suggestion of a module-specific eval.

Owner

timholy commented Dec 2, 2012

The workaround is to run Struct(Point) when still inside the module's scope, e.g.,

    type(Point)
        x::Int8
        y::Int8
    end
    Struct(Point)

    function test_unpack()
        ...

See #1378

@JeffBezanson, I like your suggestion of a module-specific eval.

@rephorm

This comment has been minimized.

Show comment Hide comment
@rephorm

rephorm Dec 2, 2012

@timholy, thanks for the workaround and the pull-request link.
@JeffBezanson, module-specific eval sounds good.

For my own understanding, is the issue that strpack is only being loaded in my TestMod module, while the eval is currently being run in the context of the main module?

rephorm commented Dec 2, 2012

@timholy, thanks for the workaround and the pull-request link.
@JeffBezanson, module-specific eval sounds good.

For my own understanding, is the issue that strpack is only being loaded in my TestMod module, while the eval is currently being run in the context of the main module?

@pao

This comment has been minimized.

Show comment Hide comment
@pao

pao Dec 2, 2012

Member

That sounds like it. eval runs in Main, which doesn't know about the symbols from strpack which were created in TestMod. I don't think modular strpack would fix that (though it would make TestMod's namespace cleaner).

Member

pao commented Dec 2, 2012

That sounds like it. eval runs in Main, which doesn't know about the symbols from strpack which were created in TestMod. I don't think modular strpack would fix that (though it would make TestMod's namespace cleaner).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment