4 ms·
ListAndHash
- cpitman 11y agoI wonder if the .Net/Java approach of "Iterables And Objects" with generic sequence operators either is ListAndHash or is the equivalent in more strongly typed languages. You essentially replace String->Object Hashes with Objects and Lambda lookup functions.
- andrioni 11y ago>Despite the fact that list 'n' hashes are very common, there are times I wish I was using a thoughtful tree representation. Such a model can provide richer navigation operations. Specter[1] provides something like this for Clojure, allowing rich navigation and transformation abilities to deeply nested structures. [1]: http://nathanmarz.com/blog/functional-navigational-programming-in-clojurescript-with-sp.html http://nathanmarz.com/blog/functional-navigational-programmi...
- gfodor 11y agoGoing into it I assumed this article was about data structures like the PHP "array", which are basically ordered hashtables that allow the programmer to treat them like either lists or hashes depending on context and still get reasonable performance. (I haven't seen this pattern used much elsewhere, has anyone?)
- Rusky 11y agoLua tables are similar- they're nominally hash tables but are often used as arrays (including a length operator), and a few versions ago they added an optimization where small integer keys are stored in an actual linear array.
- Franciscouzo 11y agoThe optimization is actually for contiguous integer keys, starting from 1.
- arikrak 11y agoAren't any hashes that keep track of order like that? (I.e. how's that different than objects in javascript, hashes in ruby, OrderedDicts in python and LinkedHashmaps in java?)
- olalonde 11y agoIn Javascript, object properties are not ordered: http://stackoverflow.com/a/5525820/96855 http://stackoverflow.com/a/5525820/96855. The Map object would be closer: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- deleted 11y ago[deleted]
- frou_dh 11y agoFinding out about "alists" and their lispy incarnation made me so happy. It was just so neat that something in some regards more capable than a typical hash table (key shadowing, references needn't be to the entire structure, ...) could spring to life, expressed in terms of barely anything atop the humble cons cell.
- izzle49 11y agotldr you can have list or hashes to represent your data model, trivial observation
- xenomachina 11y agoYeah, but now that trivial observation has a name that he coined. And incidentally, what a terrible name. A "hash" (really hash table) is a specific implementation of a map/dictionary. You shouldn't use "hash" to refer to a map based on search trees.
- stplsd 11y agoIt is interesting that hash is sometimes (incorrectly) used as a synonym or generic name for map/dictionaty/associative array, but Red-Black-Tree, AVL tree, etc. is not.
- foxhop 11y agoI've thought about this topic a lot recently. Many times I find myself working with API endpoints which return deeply nested JSON or XML "documents" which I have no real desire to learn their schema. (AWS and ElastiSearch) I ended up creating a Python Library to perform key lookups on these deeply nested documents. For Example: >>> from nested_lookup import nested_lookup >>> document = [ { 'taco' : 42 } , { 'salsa' : [ { 'burrito' : { 'taco' : 69 } } ] } ] >>> print(nested_lookup('taco', document)) [42, 69] Check it out here: * https://pypi.python.org/pypi/nested-lookup https://pypi.python.org/pypi/nested-lookup * https://github.com/russellballestrini/nested-lookup https://github.com/russellballestrini/nested-lookup
- _ZeD_ 11y agohave you heard of xpath? :)
- dunham 11y agoYou might be interested in "jq", a python program that provides an expression language for extracting and transforming json data: https://stedolan.github.io/jq/
- Nyetan 11y agoI've always wanted to write something like regular expressions for lists of objects. So, for example the example of writing a parser, one could use a regex to match chars to tokens, then write another that gathers tokens into blocks and etc. Essentially, bottom-up parsing without resorting to parser generators that take over everything. A similar tool would be interesting for querying trees directly.
- lumpypua 11y agoOMeta is an interesting place to start, there's implementations for a ton of languages. Here's a good description of the motivation for OMeta and the .Net implementation: http://www.moserware.com/2008/06/ometa-who-what-when-where-why.html http://www.moserware.com/2008/06/ometa-who-what-when-where-w...
- Nyetan 11y agoThat is definitely very interesting! Writing a parser/compiler for 'x' language tends to be a component of many interesting projects, and that's definitely a good start -- thanks :)
- taeric 11y agoI'm not sure I understand why "S-expression" doesn't fit as a name for this data structure.