0 Replies - 363 Views - Last Post: 10 July 2009 - 02:34 AM

#1 Raynes   User is offline

  • D.I.C Lover
  • member icon

Reputation: 615
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

[Lisp] Function to find the max value in a sequence in Clojure

Posted 10 July 2009 - 02:34 AM

Description: This is just a simple Clojure function, it can be ran at the REPL for testing.This function will find the largest number in a Clojure sequence. Note that there is a standard library function max that does close to the same thing. It can be used to do the same thing as this by doing (apply max coll).
(defn maxi [lst]
  (loop [l lst cur 0]
    (let [ele (if (= (first l) nil) 0 (first l))]
	(empty? l) cur
	(> ele cur) (recur (rest l) ele)))))

Is This A Good Question/Topic? 0
  • +

Page 1 of 1