-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module at top level scope #21009
Comments
You can do this by returning an expression with head |
I managed to get this working like this:
Which works for my purposes, but I think its worth including something like this in base |
I think this is mostly a duplicate of #2586. It's tricky, since it's not generally correct to just replace |
Actually, the solution above has a slight issue. Even though it correctly defines the module, it returns |
I thought that |
This is not scope. And |
Maybe the error could be more specific on what "top level" it is? |
Also related to #10472. If |
A seemingly easy fix would just be to pass through code post macro-parsing pre-lowering and (repeatedly) remove any begin end bookends at top-level. |
Any updates? I'm using 7.0 alpha and am having similar problems.
But I'm getting the error
I've read through the linked issues here but cant find a good solution. I don't need the types to exist in a local scope but I want to define them within one. This seems like it would be a pretty common pattern in a mathematically oriented language. I know it will be key if I want to write constructors for derivative algebraic structures that use the dispatch system. |
You could just use abstract type Zmod <: Integer end
function constructZmodn(n)
name = parse("Z$n", raise = true)
eval(:(primitive type $name <: Zmod 8 end))
#eval reinterpret behavior
#eval ops
end
constructZmodn(3) |
I figured that I wouldn't be able to define methods on types that didn't exist at parse time. Is this false?
But the weird thing is if I define more methods in a for loop within the same
However, If I take for loop out of the escape block and escape inside the loop everything works as expected:
|
Actually it doesn't work in the last example. The constructor Z6 is not in the global namespace. It only appeared to be because I didn't restart the REPL. |
Theoretically this should work, because module A is indeed in global scope? Would be helpful to get working for macros which operate on large blocks of global code
The text was updated successfully, but these errors were encountered: