Skip to main content
Notice removed Draw attention by CommunityBot
Bounty Ended with rreillo's answer chosen by CommunityBot
deleted 26 characters in body; edited title
Source Link
palacsint
  • 30.4k
  • 9
  • 82
  • 157

Is this program idiomatic clojure? Unix sort in Clojure

I am implementing Unix sort in clojureClojure. ThisThis is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions. II tried my best to follow the coding standards, but went with camelCase instead of hyphen-case for variable and function names.

Thank you very much!

Is this program idiomatic clojure?

I am implementing Unix sort in clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions. I tried my best to follow the coding standards, but went with camelCase instead of hyphen-case for variable and function names.

Thank you very much!

Unix sort in Clojure

I am implementing Unix sort in Clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions. I tried my best to follow the coding standards, but went with camelCase instead of hyphen-case for variable and function names.

I am implementing Unix sort in clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions. I tried my best to follow the coding standards, but went with CamelCasecamelCase instead of '-' delimitedhyphen-case for variable and function names.

sort.core is my mainMain class.

sort.core: sort.core

and my library, sort.libLibrary: sort.lib

I am implementing Unix sort in clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions. I tried my best to follow the coding standards, but went with CamelCase instead of '-' delimited variable and function names.

sort.core is my main class.

sort.core

and my library, sort.lib

I am implementing Unix sort in clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions. I tried my best to follow the coding standards, but went with camelCase instead of hyphen-case for variable and function names.

Main class: sort.core

Library: sort.lib

Notice added Draw attention by wespiserA
Bounty Started worth 50 reputation by wespiserA
Tweeted twitter.com/#!/StackCodeReview/status/160413446867927040
Source Link

Is this program idiomatic clojure?

I am implementing Unix sort in clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions. I tried my best to follow the coding standards, but went with CamelCase instead of '-' delimited variable and function names.

sort.core is my main class.

sort.core

(ns sort.core
  (:gen-class)
  (:use clojure.contrib.core)
  (:use clojure.tools.cli)
  (:require [sort.lib :as lib]))


(defn -main [& args]
  (let [[options args banner] (cli args    
                                   ["-h" "--help" "Show help" :default false :flag true]
                                   ["-i" "--input" "The input file" :default nil]
                                   ["-d" "--delim"  "The delimitter" :default ","]
                                   ["-f" "--field" "The column to parse(1 indexed)" :parse-fn #(Integer. %)])
        {:keys [delim field input]} options]
    
    
    (lib/help options args banner)
    
    (when (= (lib/fileKind input) "file")
        (lib/printOutVector delim
                            (lib/sortVector field
                                            (lib/splitFile input delim ))))
    
    (System/exit 0)))

and my library, sort.lib

(ns sort.lib
  (:require [clojure.string :as str])
  (:import java.io.File))


(defn splitFile 
  "splits a file into a 2d array" 
  [s delim] 
  (pmap #(str/split % (re-pattern delim)) 
        (str/split(slurp s) #"\n")))


(defn printOutVector
  "prints out the 2dVector formatted by the delim arg"
  [delim coll] 
  (println 
    (apply str 
           (interpose "\n" (map #(apply str (interpose delim %)) coll)))))


(defn sortVector 
  "sorts a 2d vector by the given index"
  [index coll]
  (sort-by #(nth % index) coll))


(defn help 
  "custom help message for sort.core"
  [opts args banner] 
  (when (:help opts)
    (println (str "input: " (:input opts)))
    (println (str "field: " (:field opts)))
    (println (str "delim: " (:delim opts)))
    (println banner)
    (System/exit 0)))

(defn fileKind [filename]
  (let [f (File. filename)]
    (cond
      (.isFile f)      "file"
      (.isDirectory f) "directory"
      (.exists f)      "other" 
      :else            "(non-existent)" )))

Thank you very much!