[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: rough first impressions
Jonathan Bachrach writes:
> > * collection stuff
> > Probably my favorite thing about Ruby is the elegance of it's iteration
> > mechanisms and corresponding syntax. This feature alone makes me twice
> > as productive in Ruby as in Python. Building this in is a smart move.
> > Goo's iteration seems to have an even more imperative flavor than
> > Ruby's, which is a bit ironic given Goo's roots.
>
> yeah i've thought about more declarative ways of specifying an
> iteration protocol, perhaps with a macro that expands into the various
> methods. i definitely wasn't ready though to add coroutine support.
I haven't programmed very much Ruby, but looking at the Ruby book it
seems like its iterators are mostly just sugar for higher-order
functions -- the "yield" keyword lets you pass a function as an
implicit argument to a method -- ie, you just write
foo(x) {|n| n + n}
rather than
foo(x, {|n| n + n })
I think jrb's new closure syntax gets you 90% of the way there without
the weird semantics. The other 10% could come from some macros for
defining collections, plus some higher-order functions for iterating
over them.
> you can pretty much do this. the only exception is local functions.
> these could be done as generic functions as well and allow users to
> have multiple methods on a given local generic.
I would love this feature! It would let you write code in a pattern
matching style, as you destructure objects and then dispatch on their
guts. It would be supremely cool if you could extend the terse closure
syntax to define generics and a set of methods, eg:
{ x|<num> y|<num> \ (+ x y)
| x|<str> y|<str> \ (cat x y) }
or
{ (x|<num> y|<num> \ (+ x y))
(x|<str> y|<str> \ (cat x y)) }
> of course, internally i need to have non generic functions to
> bootstrap the system. it's open for debate.
\begin{silly}
You could use dg/dm for methods, and define-function for non-generics.
Then you could rely on people's laziness to use dg by default. :)
\end{silly}
--
Neel Krishnaswami
neelk@alum.mit.edu