Coder Social home page Coder Social logo

Protocols about squint HOT 8 CLOSED

lilactown avatar lilactown commented on July 1, 2024
Protocols

from squint.

Comments (8)

borkdude avatar borkdude commented on July 1, 2024 2

This idea excites me: https://twitter.com/borkdude/status/1560711024336150528
Bringing your own immutable collections and add support via protocols for assoc etc.
This would still get you the features from CLJS but in an "unbundled" way.

from squint.

lilactown avatar lilactown commented on July 1, 2024

To clarify: the above idea could accomplish the following goals:

  1. Emit far less code than we do today
  2. Allow JS code to easily import and extend ClavaScript protocols
  3. Allow ClavaScript code to use JS protocols like the transducer example

from squint.

borkdude avatar borkdude commented on July 1, 2024

@lilactown Sounds like good goals, but need to learn a bit more:

  1. What is the benefit of using a symbol over a string here? When you create Symbol/for + a same string you will have an identical symbol and thus a conflict, similar when you would just use the string?
  2. Is it really that much different from what clava generates now (based on code borrowed from CLJS)?
  3. Which transducer example?

from squint.

lilactown avatar lilactown commented on July 1, 2024
  1. Symbol.for is an explicit lookup in the global symbol table. It is different than someone randomly calling the object.bar method, which may have a conflict. The other thing that symbols ensure is that the properties don't show up in things like Object.keys and JSON.stringify, which is an improvement over using a long obscure string.
  2. It's fairly similar in semantics, but right now Clava generates a lot more code than I wrote above. The code I wrote out also moves all handling of arity into the method implementation, rather than the protocol wrapper, which is more JS-like.
  3. It's linked in the OP: cognitect-labs/transducers-js#20

from squint.

lilactown avatar lilactown commented on July 1, 2024

Other examples of built-in "protocols" that could guide us towards a more JS-like design: https://dmitripavlutin.com/detailed-overview-of-well-known-symbols/

from squint.

borkdude avatar borkdude commented on July 1, 2024

@lilactown I've read the articles and this seems the way to go forward, agreed!

from squint.

lilactown avatar lilactown commented on July 1, 2024

An amendment to the initial design: by using Symbol("Foo") instead of Symbol.for("Foo"), we no longer have to worry about collisions, since symbols constructed the former way have unique identities each time.

from squint.

lilactown avatar lilactown commented on July 1, 2024

Closing this as the general approach seems to work.

Additional issues will be opened for gaps & bugs.

from squint.

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.