Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

[discussion/question] construct dict with native object? #570

Open
jstoebel opened this issue Jun 12, 2017 · 3 comments
Open

[discussion/question] construct dict with native object? #570

jstoebel opened this issue Jun 12, 2017 · 3 comments
Labels
documentation-gaps This issue points to a gap in documentation

Comments

@jstoebel
Copy link
Contributor

I can create a List by passing in a native javascript array:

l = new types.List([1,2,3])
console.log(l);
List { '0': 1, '1': 2, '2': 3, length: 3 }

But to make a Dict its not as straightforward as far as I can tell:

pair1 = new Tuple(['s', 'spam'])
pair2 = new Tuple(['e','eggs'])
d = new types.Dict(new types.Tuple([pair1, pair2]))
console.log(d.__getitem__("s")); // -> 'spam'

Has there been any thought to making a Dict constructable by passing a native JavaScript object? Or is this a pandoras box we're better off not opening? What if, for example a nested object is passed in?

If we don't want to change the implementation, would it be useful to update the docs to make it clear how to make a dict? Ditto for all other types.

@abonie
Copy link
Contributor

abonie commented Jun 12, 2017

I have not used it yet, but there is a function in batavia/types.js called js2py that may do what you need judging by its name and code. Let me know if you decide to try it and it works well.

@martica martica added the documentation-gaps This issue points to a gap in documentation label May 21, 2019
@martica
Copy link
Contributor

martica commented May 21, 2019

Looks like there should be a section in the docs about implementing functions and how to return values. The topic is covered partly here, but it doesn't cover returning values.

@alexjdw
Copy link
Contributor

alexjdw commented Jun 13, 2019

Working on updating the How-Tos. The new version of the above link will cover return values.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation-gaps This issue points to a gap in documentation
Projects
None yet
Development

No branches or pull requests

4 participants