in Education by
In his talk "Maybe not" Rich Hickey states: maps are (mathematical) functions! in Clojure, we can directly write, and invoke ({:a 1 :b 2} :b) => 2 However I have the feeling that they are not in fact first class Clojure functions, or are they? I can call the map with a keyword, or the other way around: user=> (:b {:a 1 :b 2 :c 3}) 2 user=> ({:a 1 :b 2 :c 3} :b) 2 But I can't use apply either way it seems: user=> (apply #(:b %) {:a 1 :b 2 :c 3}) ArityException Wrong number of args (3) passed to: user/eval1762/fn--1763 clojure.lang.AFn.throwArity (AFn.java:429) user=> (apply #({:a 1 :b 2 :c 3} %) :b) IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Keyword clojure.lang.RT.seqFrom (RT.java:542) And neither can I apply the keyword directly to the map: user=> (apply {:a 1 :b 2 :c 3} :b) IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Keyword clojure.lang.RT.seqFrom (RT.java:542) So are they functions only in the mathematical sense, or is there more to them in the sense of applying a keyword similar to a "normal" clojure function? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Maps are functions of keys, as in your first two examples. Maps implement IFn interface just like "regular" Clojure functions. The reason apply doesn't work in your examples is due to the "sequence" arguments being passed in the second position. (apply #(:b %) {:a 1 :b 2 :c 3}) In that example, the map argument is being turned into a sequence of key/value vectors/tuples, so they can be applied to #(:b %) (which wouldn't work anyway because that anonymous function only takes one argument). This is how the map would look as it's being turned into a sequence and applied as arguments to the function: user=> (seq {:a 1 :b 2 :c 3}) ([:a 1] [:b 2] [:c 3]) This second example doesn't work because :b is not a sequence — it's a single keyword. This works though: user=> (apply {:a 1 :b 2 :c 3} [:b]) 2 Note that calling a map-as-function with apply and a sequence of keywords doesn't really make practical sense though.

Related questions

0 votes
    In his talk "Maybe not" Rich Hickey states: maps are (mathematical) functions! in Clojure, we can ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 18, 2022 in Education by JackTerrance
0 votes
    In feature maps, when weights are updated for winning unit and its neighbour, which type learning it is known as? (a ... (d) none of the mentioned Please answer the above question....
asked Aug 27, 2022 in Education by JackTerrance
0 votes
    I have s Student class where each student record has a list of Results. I need to export there ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    State whether the following statements are true or false. Correct the false statements: 1. Prediction ... proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    Given a stream of text, Named Entity Recognition determines which pronoun maps to which noun. (a) False ( ... Acting of Artificial Intelligence Please answer the above question....
asked Oct 9, 2022 in Education by JackTerrance
0 votes
    Given a stream of text, Named Entity Recognition determines which pronoun maps to which noun. (a) False ( ... Acting of Artificial Intelligence Please answer the above question....
asked Oct 2, 2022 in Education by JackTerrance
0 votes
    What is the objective of feature maps? (a) to capture the features in space of input patterns (b) to capture ... (d) to capture output patterns Please answer the above question....
asked Aug 27, 2022 in Education by JackTerrance
0 votes
    1. Complete the following Chart/Concept Maps: 2. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    Complete the concept maps as given below : Please answer the above question....
asked Aug 3, 2022 in Education by JackTerrance
0 votes
    Complete the concept maps. Please answer the above question....
asked Aug 3, 2022 in Education by JackTerrance
...