I've been following this language and community from a distance, with wide open loving eyes. It had nice abstraction underneath, far less mutation than vintage~ Lisps, some ~syntactic niceties (words like first, rest instead of acronyms).
But coding in it felt had too much. I guess that's what Rich Hickey said, it's on the pragmatic side of things. All it brings has value on day to day problem solving. And I'm still fresh out college scheme/ml courses. But that's the thing, if I had to iterate on the lisp idea, I'd bring it closer to ML, not closer to ruby/perl (that's how I felt for the last few days). Using sml I felt my mind was constrained just enough to find abstract recursive solutions. In clojure I'm floating in a river of gems in brownian motion.
It's shallow criticism, not even criticism, just firsthand expression. I'm probably not smart enough to dive in it in 3 days and understand its idioms. This dialect different enough from lisp/schemes that my brain needs more time (says more about my brain than clojure vs others) . When finished with other things (SICP, 4clojure) I'll do a medium-- sized project in it (something I've never done on my own actually). Hoping the function based, mutation free idioms will lift me above my current limitations, whereas other languages feels comfortable doing one liners, I can never write systems in them. Maybe clojure shines at helping your mind scale above non-trivial exercises.
(lambda (k) ...)
Affichage des articles dont le libellé est functional programming. Afficher tous les articles
Affichage des articles dont le libellé est functional programming. Afficher tous les articles
mercredi 21 août 2013
mardi 20 août 2013
The loop/recur constructs in clojure are really nasty, and not in a good way. Let's say it will force your brain to re-evaluate its knowledge on recursive processes.
(fn [n]
(loop [i 0
a [1 1]]
(cond (< n 3) a
(= i (- n 2)) a
:else (recur (inc i)
(conj a (apply + (drop i a))))))
Blame it on Sun's JVM.
ps: this is probably the ugliest guess-fested fibonacci function I've ever seen (and written). So far.
(fn [n]
(loop [i 0
a [1 1]]
(cond (< n 3) a
(= i (- n 2)) a
:else (recur (inc i)
(conj a (apply + (drop i a))))))
Blame it on Sun's JVM.
ps: this is probably the ugliest guess-fested fibonacci function I've ever seen (and written). So far.
lundi 22 juillet 2013
Y U NO Y
After finally watching the 1986 SICP HP sessions, and many other videos building languages from nothing but lambdas, I can say I'm almost there for the Y-combinator. This choregraphy of bouncing `objects` (functions or whatever) is a thing of beauty. Wikipedia page on the matter includes some lazy functional example in Haskell :
dummy@x60s_GPT ~ [master *]
± % ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> let fix f = f (fix f)
Prelude> (fix (\f n -> if n == 0 then 1 else (f (n - 1)) * n)) 5
120
Prelude> -- amazed
dummy@x60s_GPT ~ [master *]
± % ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> let fix f = f (fix f)
Prelude> (fix (\f n -> if n == 0 then 1 else (f (n - 1)) * n)) 5
120
Prelude> -- amazed
samedi 12 janvier 2013
template as [higher-order] functions
Many templating systems are implicit substitution semantic functions, I feel templates should be normal functions with strict and optional parameters, instead of a generic call with (template name, environment map) couple.
That's all. Emacs org-capture style nano post.
ps: the higher-order part, is that we need a way to express the formatted output as context-sensitive by embedding its surrounding as another set of parameters (which would be templating functions)
Inscription à :
Articles (Atom)