70 points · by thepanister · 17y ago · 17 comments
For example, it is natural in Scheme to declare a lot of local information, including local function definitions. These have the great advantage of knowing about variables within the local environment. So rather than declaring an external function with heaps of parameters to pass in local state, you just declare a local function which automatically gets access to the variables in the surrounding scope.
The same idiom works neatly in Python too, but didn't occur to me previously.
* * *
Also after learning Python and Scheme, Ruby felt a bit like a cross between the two, and quite comfortable.
e.g.:
> (let fac ([n 10])
(if (zero? n)
1
(* n (fac (sub1 n)))))
3628800Or if you're only doing it once use a lambda (with the same advantages).
A lot of time it just kills me that "if" statements don't default to returning the true branch or false branch. You need the ternary conditional operator in Java and other C-derivatives, and in Python you need to resort to some hack with and/or precedence.
I'm also wondering if I should declare all variables final in Java, and only change that default if I really, really have to.
The non-working python if statement/assignment example from the article works perfectly fine in Ruby. (No python/ruby flamewar please, that's really not the point)
In all seriousness though, I've recently moved to Clojure from Ruby. I'm not looking back. Clojure is significantly cleaner, faster, and has better libraries than Ruby.
(x if cond else y) which is essentially (cond ? x : y)
a = ("False", "True")[condition]
It's a little fugly -- but if you know the basic semantics of Python, it's quite readable. It is nice that we have a proper ternary now, though.