-
-
Notifications
You must be signed in to change notification settings - Fork 121
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
Instance defined with VmModules is not a new instance #315
Comments
Looks like a bug to me. Another example:
Output:
Expected output:
|
So for Line 277 in adf6aee
I know this can be fixed by creatinga copy of the env, but not sure if that is the correct approach or where that code should go. Any thoughts @mattn ? |
I don't look code yet but it seems correct behavior. |
I think there would be a difference between |
Is there a work around that would allow for instantiating a new module? Module "types" don't work with |
Most of users not use module. So we can change specification of module, I think. |
I am going to look into this more, see if there is something not too hard to make this work. |
Even if we could figure out how to hook the new() function to allow for copying that environment, that would be cool too. I don't want to advocate for changing the language spec if at all possible. |
The new spec is looking for a type, so would like to look at other options. So having a module named a, like:
Please let me know if you have any other ideas and your thoughts about the above. |
The var keyword being used to declare a new variable seems to mesh with the
way normal types work. So thats my vote (if I get one). :)
…On Tue, Dec 3, 2019, 5:12 PM MichaelS11 ***@***.***> wrote:
The new spec is looking for a type, so would like to look at other options.
So having a module named a, like:
module a { b = 1 }
Here are some thoughts for a copy of a to c:
1. module c = a
2. var c = a
3. c := a
Please let me know if you have any other ideas and your thoughts about the
above.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#315?email_source=notifications&email_token=AAKD2ODFIO537PB57CA5R5TQW3YYVA5CNFSM4IFXFXW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF3IL3A#issuecomment-561415660>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKD2OGEZ4PRGE77VCYXXATQW3YYVANCNFSM4IFXFXWQ>
.
|
@mattn What you think? |
On my first design, module meant namespace not class. So I did not expect that module can be instance with new keyword. But most of users does not use module and they seems to expect classes. We may have to add classes. |
So rename module to class? Have some details on what you would like? |
Let's add new code for class and make "module" deprecated. Go's reflect does not have APIs to make struct dynamically. So adding class on anko will be useful. Class has methods and self-keyword, and definition of variables. |
Yes it does. https://golang.org/pkg/reflect/#StructOf Sounds like we just need to support struct better and that should work instead of classes. |
Yes, few years ago, I worked in progress for struct. But some APIs did not exists in that time. |
Ok, so deprecate modules and add better support for structs. |
@traetox Please test |
Will do. Thank you!
…On Wed, Dec 4, 2019, 7:05 PM MichaelS11 ***@***.***> wrote:
@traetox <https://github.com/traetox> Please test
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#315?email_source=notifications&email_token=AAKD2OFGNN7HB2PSARSFZ6DQXBOVFA5CNFSM4IFXFXW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF7GT6Q#issuecomment-561932794>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKD2OC6TDJI2XQQ3U67AW3QXBOVFANCNFSM4IFXFXWQ>
.
|
@traetox All good? |
doesn't look like the PR fixed it. Here is a test script:
Using anko version 0.15 i got the following output
Expected output:
|
So t1 and t2 are new instances of Foo however the functions still point to the orginal variable x. I will think about it some more but I don't think there are any easy fixes for modules. Will probably need to work on better struct support so can do Go struct methods. In partiluar, need to add struct creation. Note that struct methods are supported to some extent, can look at Sort for an example: So for now if you define the struct using env define, it might do what you are looking for. |
ok, that seems entirely fair. I would say you could close this as "working as intended" Thank you for your time! We will poke a bit as we can on the code base and see if we can get some PRs that make sense. Thank you! |
Anko code
Expected output
Actual output
The text was updated successfully, but these errors were encountered: