Coder Social home page Coder Social logo

Comments (5)

irh avatar irh commented on June 27, 2024

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 a ValueMap as a hidden value using ExternalDataId.
  • 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 a file_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.

llogiq avatar llogiq commented on June 27, 2024

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.

irh avatar irh commented on June 27, 2024

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.

llogiq avatar llogiq commented on June 27, 2024

I have started a WIP PR #64. Do you think this is the right direction?

from koto.

irh avatar irh commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.