The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

nevin (2) [Avatar] Offline
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 sort.

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

Can someone give me some insight here?

(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
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)