3 ms·
...At that point, what was the advantage of Sinatra? You were basically running a Rails application. Framework simplicity is good if your application is meant
by pron 13y ago
...At that point, what was the advantage of Sinatra? You were basically running a Rails application.
Framework simplicity is good if your application is meant to be simple. But you should be cautious when choosing simplicity if your application is ambitious and you care about supporting it for a long time.
This is what I like about Clojure. It is so composable, that simplicity doesn't come at the expense of features. The language makes composing disparate libraries so easy, that it's quite trivial to mix and match different libraries and have them all work in tandem. You don't only use what you need, but for every aspect of your application you can choose the best tool for your particular needs.
- danneu 13y agoClojure's namespace declaration: (ns my-app.my-namespace (:require [some-library.some-namespace :as foo]) is pretty liberating for me after working with Ruby for so long. Composition is tedious to reason about in Ruby when your only clue is a menagerie of `require`s at the top of the file. Or, more commonly, when your only clue is a Gemfile because all the gems are auto-required and omnipresent.
- prollyignored 13y agoAn offtopic clojure question. Today I was seeing this -- https://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm https://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm How can I begin to implement it in clojure ? Specifically, how do I _ingeneral_ deal with assignments and while loops. In common-lisp, for example I would use the `loop` macro and defvar-sefq combo, (beginning lisper). In ruby, = and while itself.
- danneu 13y agoClojure has most of the semantics you're used to in other languages. http://clojuredocs.org/clojure_core/clojure.core/let http://clojuredocs.org/clojure_core/clojure.core/let (let [username "prollyignored" karma 7] (println username "has" karma "karma points.")) ; prollyignored has 7 karma points. http://clojuredocs.org/clojure_core/1.2.0/clojure.core/loop http://clojuredocs.org/clojure_core/1.2.0/clojure.core/loop (loop [n 0] (when (< n 10) (print n) (recur (inc n)))) ;=> 0123456789 http://clojuredocs.org/clojure_core/clojure.core/for http://clojuredocs.org/clojure_core/clojure.core/for (for [x [0 1 2 3 4 5] :let [y (* x 3)] :when (even? y)] y) ;=> (0 6 12) Or just: (filter even? (map #(* % 3) [0 1 2 3 4 5])) ;=> (0 6 12) Browse the Clojure cheatsheet: http://clojure.org/cheatsheet http://clojure.org/cheatsheet
- prollyignored 13y agoAha ! Now in, while m+i is less than the length of S, do: if W[i] = S[m + i], if i equals the (length of W)-1, return m let i ← i + 1 .... How would I implement the `return m` part ?
- dizzystar 13y agoThere is no explicit return value because the functions aren't functions: they are values, thus the result of the algorithm is bound to the value that is bound to the function. When you write: (defn square [x] (* x x)) You are really writing: (def square (fn [x] (* x x))) and x * x is bound to the value of square. There would be no logical reason to have an explicit return value here.
- danneu 13y agoIt's pretty much the same as this: (loop [n 0] (if (= n 10) n ; true case: return n (recur (inc n)))) ; false case: loop with n++ ;=> 10