nevin (2) [Avatar] Offline
#1
Hi, I've hit an understanding roadblock with listing 3.3 in Higher Order Functions.
The listing is below my question.

I understand that the sorter-using function returns a function and that's assigned to the appropriate variables poorest-first and alphabetically.
What I don't understand is how you would actually call this group of functions to actually get it to do something..ie sort.

Calling poorest-first for example just returns the definition of the function object.

Can someone give me some insight here?
thanks
Nev


(def users [
{:username "kyle"
:balance 175.00
:member-since "2009-04-16"}

{:username "zak"
:balance 12.95
:member-since "2009-02-01"}
{:username "rob"
:balance 98.50
:member-since "2009-03-30"}
])

(defn username [user]
(user :username))

(defn balance [user]
(user :balance))

(defn sorter-using [ordering-fn]
(fn [users]
(sort-by ordering-fn users)))

(def poorest-first (sorter-using balance))

(def alphabetically (sorter-using username))
nevin (2) [Avatar] Offline
#2
Re: Listing 3.3 understanding.
Ok, sleep allowed me to realise how stupid this question was.

For anyone else as sleep deprived as I was reading this, the answer is that poorest-first and alphabetical are the returned anonymous function. So, of course you have pass in what that function is expecting as a parameter:

(poorest-first users)