News for hackers. Stuff that matters.
Re:Why Clojure? by 6thaccount2 on Saturday August 24, 2019 @11:35AM (#20787725)
I'm with you. Reading a text file (line by line) is the thing I do most and what I look for first. If you can't do that in a simple way, I move on. I also look at returning datasets from SQL databases, how you can make a GUI, and a host of other practical things. I think fibonnaci is a sort of one step up from "Hello World", so in a sense it gives a little taste of the language and syntax.
Re:Why Clojure? by LandR on Saturday August 24, 2019 @03:26PM (#20789160)
I think if all you are doing is reading files line by line, reading a database dataset etc, then your choice of language is probably irrelevant. Choose whatever you prefer typing.

But here's CLojres read a file line by line and print it out:

    C:\\foo.txt
    "THis is line 1
     This is line 2
     This is line 3"

     (with-open [rdr (io/reader "C:\\foo.txt")]
        (doall (map println (line-seq rdr))))
      =>THis is line 1
        This is line 2
        This is line 3
A simple function to read a specified file line by line

   (defn read-file-line-by-line [file-path]
      (with-open [rdr (io/reader file-path)]
         (doall (line-seq rdr))))

   (read-file-line-by-line "C:\\foo.txt")
   => ("THis is line 1" "This is line 2" "This is line 3")
To read the line by line and convert them to upper case

     (map clojure.string/upper-case (read-file-line-by-line "C:\\foo.txt"))
     => ("THIS IS LINE 1" "THIS IS LINE 2" "THIS IS LINE 3")
Re:Why Clojure? by 6thaccount2 on Saturday August 24, 2019 @04:50PM (#20789626)
I don't think this is remotely true. Compare doing file parsing in Python, Perl, C#, Java, Common Lisp, OCaml, Ada, Fortran, C++...etc.

Doing it in Python is easy...it is a bigger pain in several of the other ones. Even your Clojure examples are definitely more work than in Python. You even defined a helper function (something I've never needed to do in Python) as the default is so easy. Mind you, the Clojure isn't too bad and definitely better than some of the others I've mentioned.

To your average developer...this is indeed probably irrelevant as IO might be a small part of your codebase. I do a lot of process automation though and do a lot of IO.