code blocks and C-like lambda expressions

Oct 07, 2006 23:50

A while back, I started using Ruby for some personal software projects. I was immediately impressed with its "code block" syntax. It's a fairly natural Algol-like syntax for lambda expressions, and is used to great effect in the language. ( I'd like to advocate wider adoption of this kind of syntax, and suggest some improvements. )

nerdiness, ruby, programming languages

Leave a comment

Comments 5

ch October 8 2006, 08:49:14 UTC
you might wish to check out Forsythe (ref: CMU CS Tech Report cmu-cs-88-159). dylan too. there has been lots of work on have higher order functions in algol-derived languages. the smalltalk approach is not the only way. (i personally prefer full closures over blocks.)

Reply

confuseme October 8 2006, 09:11:33 UTC
Thanks for pointing out Forsythe, I hadn't paid any attention to it before!

I think Ruby's blocks are full closures, although I'm not super clear on the meaning of that phrase. But, for example:

irb(main):001:0> i = 1
=> 1
irb(main):002:0> p = Proc.new { i += 1 }
=> #

irb(main):003:0> p.call()
=> 2
irb(main):004:0> i
=> 2

Reply

ch October 9 2006, 06:18:04 UTC
I'm not a Ruby expert, but I understood the Proc object as the closure and a block is just a block.

It seems roughly equivalent to the difference between lamba and progn.

Reply

snej October 9 2006, 18:48:43 UTC
But you can convert a block to a Proc object with a single method call, so there isn't really much distinction between them. It's primarily syntactic sugar plus some optimization. (Smalltalk-80 implementations also tried to be lazy about converting block parameters into full-fledged objects, generally doing so only if the block got assigned to a non-local variable.)

Reply


nescafe October 8 2006, 13:10:08 UTC
You might also want to check out http://www.iolanguage.com/about/

Reply


Leave a comment

Up