Git Product home page Git Product logo

Comments (4)

bakpakin avatar bakpakin commented on May 23, 2024

Probably not as a core data structure, although it would be possible to add one as an abstract type. Abstract types cannot emulate all of the features of built in types right now, such as length, hash, equality, call, and print methods, but I would consider adding some of these features to the abstract type interface.

All that said, I think there is benefit to using a few core data structures - enough for many use cases, but few enough that making generic functions is easy.

You could of course also do something like:

(defn make-set 
  [& els]
  (let [tab @{}]
    (each el els (put tab el true))
    (table/to-struct tab)))

(make-set :a :b :c)
# -> {:c true :a true :b true}

from janet.

quan-nh avatar quan-nh commented on May 23, 2024

oops, I don't know about abstract types, what do we already have for now?

from janet.

bakpakin avatar bakpakin commented on May 23, 2024

Abstract types are native C types, you would have to write your own in C. The current abstract types in the core are files and typed arrays, and there are some others in external packages.

I would recommend using tables for sets, though.

from janet.

mdwhatcott avatar mdwhatcott commented on May 23, 2024

The package index references janet-set, an implementation of set types in Janet.

Janet-set uses janet-abstract (https://github/mikebeller/janet-abstract.git) in order to create a new abstract type directly in Janet. This allows us to "hook" into get/put/tostring/next so that our sets will support length calls, normal Janet iteration, and print out in a sensible way.

from janet.

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.