Comments (5)
Hi @llogiq, glad to hear that you're trying out Koto!
I'm sorry that the docs are missing here, I started a documentation effort on the help
branch but I haven't touched the topic of integrating with Rust yet and I've had a busy few weeks, I'm looking forward to picking this up again.
I agree that making custom types is a bit cumbersome at the moment, especially without a guide.. My thinking is that I'd like to make sure the fundamentals are correct and the implementation straight-forward, and then some more ergonomic helpers can be added to make usage a bit friendlier.
I'll try to clarify the current approach:
- An
ExternalValue
is just a placeholder for some arbitrary Rust value. The intention is that scripts don't interact with them directly, but instead to make them useful they get placed in aValueMap
as a hidden value usingExternalDataId
. - An interface is then built up around the external value in the
ValueMap
. Functions and any other value type can be added to the map, like with any other map in Koto. - There are a couple of other examples in the core library that can be looked at. The
File
example is more extensive. You can see that I added afile_fn
helper for reducing boilerplate when adding functions.
If I understand you correctly you'd rather expect that the ExternalValue
itself would be the value that the user interacts with (instead of a ValueMap
), with behaviour on the value exposed via a KeyValue -> Function
mapper?
If I've got that right I think I would rather extend the type via an embedded ValueMap
(just to enable all value types, not just functions). The difference in approaches would then be that you would have an ExternalValue
with an embedded ValueMap
, rather than a ValueMap
with an embedded ExternalValue
...
Does that make sense? I can see some value in inverting the approach here, it might make the expected usage more explicit (although maybe utilities and docs will help there).
from koto.
Adding a ValueMap
field in the ExternalValue
variant makes a lot of sense; those are Arc
and can easily be generated as a lazy static to be cloned for further use.
from koto.
Yes I can see an advantage there, it'd be cheaper to clone the interface map than having to rebuild it for each new value.
from koto.
I have started a WIP PR #64. Do you think this is the right direction?
from koto.
Yes I think this is roughly how I would expect it to look, I appreciate you diving in!
I'm still unsure if I want to proceed in this direction though. The main concern I have is that this will introduce a new object-like-thing to Koto, and I’d like to avoid that if possible.
I'm thinking about an alternative solution which would be to extend ValueMap
so that it includes an optional ExternalValue
, plus an optional ‘immutable data’ map, which would act as fallback when values aren't found in the main data, and which would allow for the fast cloning of a shared function table that you're looking for.
ValueMap
would then look something like:
/// The Map value type used in Koto
#[derive(Clone, Debug, Default)]
pub struct ValueMap {
data: Arc<RwLock<ValueMapContents>>,
immutable_data: Option<Arc<RwLock<ValueHashMap>>>,
external_data: Option<Arc<RwLock<dyn ExternalValue>>>,
};
…and ExternalValue
and ExternalDataId
could be removed as Value
variants.
Something I like about this is that modules like could expose their features as immutable. It’s never really felt right that there’s nothing to stop a user from saying number.pi = -1
(but users could still extend core modules with their own functionality if they like).
…and I haven’t figured out a few details of the expected behaviour of map operations over a mix of mutable and immutable entries (like how map operations should apply), but I’d need to start playing with some examples to get a feel for the right direction.
from koto.
Related Issues (20)
- Reverse iterators HOT 1
- `@as_bool` meta key HOT 1
- Optimize tail calls HOT 1
- Add `iterator.cycle` HOT 2
- Single-threaded runtime
- Add REPL support for the Delete key
- Add `iterator.flatten`
- Arrow key movement broken in the REPL on Windows
- Run wasm tests on CI
- `num2`/`num4` improvements
- Add load/run functions to allow for running Koto code inside a script
- Function objects, `@||` meta key HOT 1
- Noob question. How do i print something without a newline? HOT 2
- KotoFile::id() should return a ValueString
- Add language support to Helix text editor HOT 2
- Remove packed numbers (Num2 / Num4)
- Add geometry and color libs HOT 1
- Remove Value's implementation of fmt::Display
- Stack overflow when displaying recursive objects
- `+=` and other assignment operations broken in the REPL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koto.