Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if then do in clojure

Tags:

clojure

I have created 3 functions. Each connects to a database, runs a query and displays the result. Run indivually they all work fine. However I want the user to decide which report of 3+ to run, to do so they will select a parameter and hit an execute button. How do I write a nested if then do in Clojure to decide which functions to execute?

If param = "reporta" do execute functiona else if param = "reportb" do execute functionb else etc etc etc

I have searched online but can't really find a good example of what I am trying to do... Any advise much appreciated.

like image 409
user983597 Avatar asked Dec 09 '22 04:12

user983597


1 Answers

Use cond or condp:

(condp = param
  "reporta"    (functiona)
  "reportb"    (functionb)
  (function-else))   

Alternatively, you could use a map of functions and just index by param.

like image 157
Dave Ray Avatar answered Jan 18 '23 17:01

Dave Ray