6 ms·
The same thing could be done in Python (with requests) and Ruby (with whatever-it-is) with more clarity, less confusion, and much less consumption of resources.
by dschiptsov 14y ago
The same thing could be done in Python (with requests) and Ruby (with whatever-it-is) with more clarity, less confusion, and much less consumption of resources.)
(:headers resp)
This construction is confusing - it breaks environmental model (scoping) and general evaluation rule of Lisps - is :headers a global symbol? a part of foo namespace? Is it macros?
(resp :headers)
On the other hand, this form is perfectly consistent - I'm sending to some closure which is bound in a global or other environment a constant message.
The assumption that the reader function implicitly transforms first form to second is of no good, because it is not obvious and breaks intuition about environments and violates principle of less astonishment.
That thing (:headers resp) returned - what language is it?)
- wtetzner 14y ago>This construction is confusing - it breaks environmental model (scoping) and general evaluation rule - is :headers a global symbol? a part of foo namespace? Is it macros? It follows Clojure's evaluation rules just fine: it's an object that implements the IFn interface. > On the other hand, this form is perfectly consistent - I'm sending to some closure which is bound in a global or other environment a constant message. resp isn't a closure, it's a map, which is also an object that implements IFn.
- dschiptsov 14y agoHow could you tell this from the code?)
- wtetzner 14y agoYou can tell by knowing Clojure. Things that start with : are keywords, and keywords implement IFn.
- prospero 14y agoBecause keywords are functions which are implemented such that: (:keyword m) calls in turn (get m :keyword) That's just a basic feature of the language. No macros involved.
- dschiptsov 14y agoSo, reader knows about keywords and does this implicit syntactic transformation? It seems to me that a function must be defined somewhere before one could call it.)
- bloat 14y agoNo, there is no syntactic transformation. The keyword is a function i.e. (in Java terms) it implements the IFn interface. The effect of that function is the same as calling the get function on a map using the keyword as the argument.
- dschiptsov 14y agoIn Lisp terms, however, a keyword is a self-evaluating symbol, a constant. If it is a function, where it is defined and when? That's why I'm arguing that this form is confusing, and that transformation is more correct notion, at least if people are insisting to call it Lisp.)
- bloat 14y agoIt does evaluate to itself and it is constant. It is also a function though, and can be used in the function position of a function application just like any other function. Keywords and all their functionality are defined as a primitive in Clojure, i.e. in the Java source code for the language. It's typically one of the first things people learn when they pick up Clojure, and is used as an idiomatic way to access maps whose keys are keywords. I would argue that is is not confusing and that it is totally consistent - all you were missing is one fact: keywords are functions.
- dschiptsov 14y agoFrom the Lips's perspective it is a contradiction. Something is either a function or a constant. The logic is that this object could be called as a function and at the same time always evaluated to itself? That means whenever you call it you always getting it back - this is behavior of a constant. But if you could call it with an argument, you will get back some value, different from whatever it is? As long as maps are immutable, it will behave as a function - return the same value for the same argument. OK, but, please, don't tell me that this isn't confusing.)
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]