by bitops · 13y ago · 0 comments
However, whenever people post "Lisp in Ruby" stories, I always hope that it'll be a "Clojure in Ruby" implementation. I am surprised no-one has done it yet.
They have: http://rouge.io/ https://github.com/rouge-lang/rouge
Clojure is immutable by default, which is a pretty big difference AIUI. It also has a pretty strong emphasis on concurrency, including a bunch of primitives for such. It uses STM.
A bunch of data structures are first class, like vectors, maps, and sets. There are literals for each of them, and you can use maps and sets as functions. You can also use keywords as functions against maps to e.g. retrieve the :name value from a list of maps:
user=> (map :name [{:name "foo"} {:name "bar"}])
("foo" "bar")
Lambda literals are nice: user=> (map #(* 2 (inc %)) [1 2 3])
(4 6 8)
They can take multiple args (e.g. %1 %2) instead of just %.Threading macros are somewhat closer to Haskell's syntactically straightforward function composition:
user=> (->> [1 2 3] ;; this'll be the last arg passed to each fn below
#_=> (map #(* 2 %))
#_=> (map inc))
(3 5 7)
I'm sure there's more. Maybe a more experienced Lisper can chime in.Personally I dislike Clojure's syntax - Scheme's feels more pure, cleaner. It's a bit like PERL vs. Python, a matter of taste largely.
I would call it more like Ruby vs. Python — c'mon, perl? that's just mean — but yes, we're quibbling. :)
Which data-structures are not first class "objects" in Scheme?
It may have been misleading to say that Clojure was immutable by default. It is immutable; it does not have set! or the moral equivalent. You can use concurrency primitives to update in place (sort of? AFAICT you're mutating the var itself, not the data it contains) but each primitive comes with its own semantics.
As far as first-class is concerned: in Clojure, maps, sets, and vectors are functions. They're functions of their data as well as being data, and there are literal representations for each.
Examples:
user=> ({:foo 1} :foo) ;; maps are functions
1
user=> (:foo {:foo 1}) ;; keywords are functions, too
1
user=> (filter :name [{:name "foo"} {:surname "baz"}]) ;; filter by key
({:name "foo"})
user=> ([\a \b \c] 2) ;; access vector by index
\c
user=> (#{1 2 3} 4) ;; test set membership
nil
user=> user=> (filter #{2 4 6} (range 1 10)) ;; filter by set membership
(2 4 6)
To what extent is any of that true of Scheme? I am reasonably certain that these data types can't operate as functions in Scheme. Glancing at such as the Racket docs, my impression is that generally you use a specific set of functions to interact with each type (e.g. hash-map-get, hash-has-key?, set-member?).Optional static typing (a la Qi) is being implemented, too.
Taking 100 MB to startup may be a problem. But not exactly for a webserver.
Or, I run a few hundred servers at work, also on VMs. I want to create a process that needs to run on all of them in addition to what the server is actually used for. Maybe for monitoring, maybe for server management, etc. and I want it to have a REST API. Suddenly using 100MB matters to me.