WJ> Can Ruby tackle the challenge of Paul Graham's
WJ> On Lisp?
well, bro, that's not even interesting -- those are simple examples
of recursive functions and closure stuff.. i guess almost any language
that has anonymous functions (and many have them -- Python, JavaScript)
will handle them more-or-less well,
and if it has some syntatic sugar and library functionality, it could
be even simplier than Graham's code. but that doesn't show anything..
if you want to compete in denseness, try competing with Arc.
so this closure stuff is what common is between Ruby and Lisp.
and macros (and lack of thereof) is what different is. if you want
to understand the difference, go further into On Lisp in macros
section.
"Alex Mizrahi" <········@users.sourceforge.net> writes:
> well, bro, that's not even interesting
BTW: He cheats. I had only a quick look, but at least one of his
examples (IIRC group) has quite different (read: worse) performace
characteristics (IIRC O(n^2) instead of O(n)). No wonder he likes his
cute short solutions -- if Lispers were such ignorant of simple
algorithms, our code would be much shorter, too. But I think, if you
use Ruby you already did give up on performace... :)
--
Stefan.
On Nov 5, 6:06 am, William James <·········@yahoo.com> wrote:
> def find2 list, &block
> list.each{|x| val = block.call( x )
> return [ x, val ] if val }
> nil
> end
>
This looks nicer:
(defun find2 (fn list)
(loop for x in list
for val = (funcall fn x)
when val return (values x val)))
> def filter list
> acc = []
> list.each{|x|
> val = yield( x )
> acc << val if val }
> acc
> end
This looks nicer:
(defun filter (fn list)
(loop for x in list when (funcall fn x) collect it))
> def group source, n
> acc = []
> 0.step(source.size - 1, n){|i|
> acc << source[i,n] }
> acc
> end
This looks nicer:
(defun group (source n)
(loop with length = (length source)
for i from 0 below length by n
collect (subseq source i (min (+ i n) length))))
> def flatten x, acc=[]
> return acc if x.empty?
> flatten( x[1..-1], acc +
> (x.first.is_a?( Array ) ?
> flatten( x.first ) : [ x.first ] ))
> end
This looks nicer:
(defun flatten (xs)
(loop for x in xs
if (listp x) nconc (flatten x)
else collect x))
> def prune x, acc=[], &block
> return acc if x.empty?
> prune( x[1..-1], acc +
> (x.first.is_a?( Array ) ?
> [prune( x.first, [], &block )] :
> (block.call(x.first) ? [] : [x.first]) ), &block )
> end
This looks nicer:
(defun prune (test tree)
(loop for x in tree
if (consp x) collect (prune test x)
else unless (funcall test x) collect x))
Caveat emptor: I didn't really test these functions - they may be
buggy.
Paul Graham's snippets, as well as your Ruby ones, are written in a
rather
low-level style. My snippets show that Common Lisp supports a higher-
level
style. Can you show how Ruby might support such a style?
Ariel
> ...low-level style. My snippets show that Common Lisp supports a higher-
> level
> style. Can you show how Ruby might support such a style?
>
Something on Rails, ttttRrrrr...uby.... Choo Chooo!
On 2008-11-05, William James <·········@yahoo.com> wrote:
> Can Ruby tackle the challenge of Paul Graham's
> On Lisp?
Could William James feel good about himself if the answer happened to be no?