5 ms·
> maps can easily represent lists but not vice versa Obviously false, as demonstrated by Lisp, with which the author must be familiar. The problem with maps a
by aasasd 7y ago
> maps can easily represent lists but not vice versa
Obviously false, as demonstrated by Lisp, with which the author must be familiar.
The problem with maps as a basis for a programming language is that you need expressions to have one entry point which says what expression this is. In a sequence, an obvious choice is the first element, or sometimes the last. This is why YAML-programming expressions in Ansible in fact work exactly like regular function calls, with their “- function: argument argument” syntax (which Ansible authors seem to not notice). ‘Misc’, of course, also has to choose ‘0’ to represent the expression entry point.
I think this syntax is translatable one-to-one to old Lisp syntax, probably with keyword arguments.
- e12e 7y agoWouldn't it be fair to say a proper map can (more) directly represent a list, while a list can only be used as the underlying implementation of a map? Specifically for lisp, a list is a sequence of cons cells, and you would have to do a linear search to look up a value by key - thus, it can function as a map from an Api point of view, but not in terms of performance? That's why the common lisp "map" is a hash table, not a list? http://gigamonkeys.com/book/collections.html http://gigamonkeys.com/book/collections.html
- aasasd 7y ago> while a list can only be used as the underlying implementation of a map? I certainly wouldn't advise that. We're talking about language syntax here. Lists serve alright for maps in the syntax (personally I like Clojure's curly-brace literals), but I sure hope that the implementation uses hash maps or something like that. I also have no idea why lists have to be linked-lists and made of cons cells. Lisps working on top of pre-existing environments, like Clojure, don't seem to bother with that requirement, so it looks like it's just an idea from the stone age of computing.
- e12e 7y agoBy your definition of lists, misc uses lists to represent maps?
- aasasd 7y agoI guess it can do so. I don't really understand why one would want to ‘base’ the language on maps to promptly go back to lists for putting these integer-keyed maps in. Where's the ‘based on maps’ part then? It would be really map-based, in my book, if it used named arguments for every function—though that would be incredibly cumbersome (ahem ObjC cough). As it is, it's just regular Lisp but with map keys having colons on the right instead of the left.
- e12e 7y agoA map with integer keys is closer to an array than a list. I'm not sure I follow your arguments - you seem to be talking of "lists" as some sort of string syntax, possibly as some form of abstract syntax - but either way separate from the abstract data structure? That's not how I read the comment from the misc page - they seem to be talking about the ADT - much like clojure chose to not use lists made from cons pairs?
- aasasd 7y agoNow your distinctions seem foreign to me. Let's look at this structure in Python: ["qwe", 1.1, True, None, [], var1] Is this an array, a linked list or what? Can an integer-indexed map be mapped onto this structure? To me it looks perfectly cromulent for making a Lisp.
- e12e 7y agoSince there isn't any traversal when looking up an element n, I guess the best "short hand" would be to call it an array - it's an array of pointers to objects on the heap. https://www.laurentluce.com/posts/python-list-implementation/ https://www.laurentluce.com/posts/python-list-implementation... As for collections within collections, python allows for that in "lists" (arrays) and "dictionaries" (maps).