
ListAndHash - ingve
http://martinfowler.com/bliki/ListAndHash.html
======
andrioni
>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-
programmi...](http://nathanmarz.com/blog/functional-navigational-programming-
in-clojurescript-with-sp.html)

------
foxhop
I'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_
have you heard of xpath? :)

~~~
foxhop
does xpath require knowing the path? nested-lookup doesn't.

~~~
taeric
You do know you can just stick a double slash at the beginning of the path to
say that you don't care where in the document it is, right?

~~~
foxhop
No, I didn't know that. Thanks.

------
Nyetan
I'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
OMeta 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-w...](http://www.moserware.com/2008/06/ometa-who-what-when-where-
why.html)

~~~
Nyetan
That 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 :)

------
gfodor
Going 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
Lua 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
The optimization is actually for contiguous integer keys, starting from 1.

------
taeric
I'm not sure I understand why "S-expression" doesn't fit as a name for this
data structure.

------
cpitman
I 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.

------
frou_dh
Finding 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
tldr you can have list or hashes to represent your data model, trivial
observation

~~~
xenomachina
Yeah, 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
It 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.

