Giter Site home page Giter Site logo

ht.el's Introduction

Table of Contents generated with autotoc

ht.el

The missing hash table library for Emacs.

Build Status

Functions

Return a hash table

  • ht-create (test?)
  • ht-merge (&rest tables)
  • ht-copy (table)
  • ht-select (function table)
  • ht-reject (function table)

Accessing the hash table

  • ht-get (table key default?)
  • ht-keys (table)
  • ht-values (table)
  • ht-items (table)
  • ht-find (function table)
  • ht-size (table)

Mutating the hash table

  • ht-set! (table key value)
  • ht-update! (table table)
  • ht-remove! (table key)
  • ht-clear! (table)
  • ht-reject! (function table)

Iterating over the hash table

  • ht-map (function table)
  • ht-each (function table)

Predicates

  • ht? (table-or-object)
  • ht-contains? (table key)
  • ht-empty? (table)

Converting from a hash table

  • ht->alist (table)
  • ht->plist (table)

Converting to a hash table

  • ht<-alist (alist)
  • ht<-plist (plist)

Macros

Returning a hash table

  • ht (&rest pairs)

Iterating over the hash table (anaphoric)

  • ht-amap (form table)
  • ht-aeach (form table)

Examples

Creating a hash table and accessing it:

(require 'ht)

(defun say-hello (name)
  (let ((greetings (ht ("Bob" "Hey bob!")
                       ("Chris" "Hi Chris!"))))
    (ht-get greetings name "Hello stranger!")))

This could be alternatively written as:

(require 'ht)

(defun say-hello (name)
  (let ((greetings (ht-create)))
    (ht-set! greetings "Bob" "Hey Bob!")
    (ht-set! greetings "Chris" "Hi Chris!")
    (ht-get greetings name "Hello stranger!")))

Why?

Libraries like s.el (strings) and dash.el (lists) have shown how much nicer Emacs lisp programming can be with good libraries. ht.el aims to similarly simplify working with hash tables.

Common operations with hash tables (e.g. enumerate the keys) are too difficult in Emacs lisp.

ht.el offers:

  • A consistent naming scheme (contrast make-hash-table with puthash)
  • A more natural argument ordering
  • Mutation functions always return nil
  • A more comprehensive range of hash table operations, including a conventional map (ht-map returns a list, elisp's maphash returns nil).

Similar libraries

Installation

ht.el is availabe on MELPA and Marmalade.

Add a package archive to your .emacs.d/init.el:

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)

then run M-x package-install <RET> ht <RET>

Changelog

ht.el uses semantic versioning, so an incompatible API change will result in the major version increasing. See CHANGELOG.md for a history of all changes.

Running tests

M-x ht-run-tests

What's an alist/plist?

An alist is an association list, which is a list of pairs. It looks like this:

((key1 . value1)
 (key2 . value2)
 (key3 . value3))

An alist can also look like this:

((key1 . value1)
 (key2 . value2)
 (key1 . oldvalue))

A plist is a property list, which is a flat list with an even number of items. It looks like this:

(key1 value1
 key2 value2
 key3 value3)

Both of these are slow. ht.el provides ht<-alist and ht<-plist to help you convert to hash tables. If you need to work with an alist or plist, use the functions ht->alist and ht->plist to convert an hash table to those formats.

ht.el's People

Contributors

wilfred avatar rejeep avatar rolpereira avatar sillykelvin avatar

Watchers

Johnny avatar

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.