Skip to content
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

recursive maps (use case: to emulate packages) #10

Open
glycerine opened this issue Dec 24, 2018 · 1 comment
Open

recursive maps (use case: to emulate packages) #10

glycerine opened this issue Dec 24, 2018 · 1 comment

Comments

@glycerine
Copy link

glycerine commented Dec 24, 2018

Wondering how I could create a working math.Pow(2,3) and math.Log(2).

I tried:

    lib := make(map[string]interface{})
    lib["Pow"] = math.Pow
    sdict, err := convert.MakeStringDict(lib) // also doesn't work if we omit this
    panicOn(err)
    env.Starlark.GoGlobal["math"] = sdict
    dict, err = convert.MakeStringDict(env.Starlark.GoGlobal)
    panicOn(err)
    // use dict as the globals in a call

but I get

Error: starlight_map<map[string]interface {}> has no .Pow field or method

or

Error: starlight_map<starlark.StringDict> has no .Pow field or method

ah. conv.go:48 has a TODO that indicates recursive maps aren't implemented.

update: also I've been doing too much Lua where this actually works and maps (tables) can act as packages (which makes sense since they are both just hash tables). Python doesn't like this syntax

Python 3.7.1 (default, Nov  6 2018, 18:45:35)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a={"b":2}
>>> a
{'b': 2}
>>> a.b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'b'
>>>

so some other way to represent packages is needed if python "use this package after import" is to be realized.

@glycerine
Copy link
Author

glycerine commented Dec 24, 2018

added the necessary functionality in https://github.com/glycerine/starlark-go/tree/attr and proffered it in google/starlark-go#79

#11 fixes this, once the pull request is merged.

chasehensel pushed a commit to chasehensel/starlight that referenced this issue Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant