Replies: 3 comments 8 replies
-
By a coincidence, I've also started work on high level bindings for JS this week. I've posted a not-working draft PR here #6048. Since you've been the main developer of js bindings, how should we proceed? |
Beta Was this translation helpful? Give feedback.
-
It might be that option 2, 3 are better, but I can't say for sure outright. |
Beta Was this translation helpful? Give feedback.
-
@bakkot I'm trying to understand some design decisions and trade-off that were made.
|
Beta Was this translation helpful? Give feedback.
-
As a followup to #5762, I've started work on high-level JS bindings, which you can see on this branch. There's an example of how they're used here, and some important notes about the implementation here. It is very far from being complete, having basically only enough to make a sudoku or n-queens solver, but it has all of the foundational work - GC, correct TypeScript types, etc. I'm not entirely happy with the structure yet, but it's functional.
I didn't PR this because I got stuck on a design question, and then forgot about it. The design question is:
How should contexts work? There's a few possible designs I see.
context
parameter which defaults to a shared global context. So, e.g.,A hybrid approach: have a global context and global versions of all the API functions like
Int
which implicitly use the global context, but also have acontext
function which gives you new versions of all the API functions which are bound to the new context.Only ever have one, global context.
There's some tradeoffs in the usability of option 1 vs 2. In option 1, if you only ever have one context, then you never have to think about it: you just import the global
Int
class and use it and everything works. On the other hand, if you do have multiple contexts, you now have to remember to pass it to everything.I can't really evaluate these tradeoffs because I don't know how often you actually want to work with contexts explicitly, rather than just having everything use a shared global context.
Currently it's implemented as option 1, because I was just copying python. I think option 2 is theoretically cleaner, but maybe a little more annoying to use since you can't just import things you need. Option 3 might be a best-of-both-worlds approach.
With any of these approaches I might be able to make the type system help out some, by preventing you from mixing values from different contexts, but I would have to think about how to do that more.
Beta Was this translation helpful? Give feedback.
All reactions