Hacker News new | past | comments | ask | show | jobs | submit login

> but I found it difficult to work with the lack of first-class functions and iterators/generators, as well as the general iteration protocol.

Ruby has iterators/generators. It doesn't have first-class functions because it doesn't have functions at all, but blocks/procs serve the same purposes.




I don't know Ruby, but it kinda sounds like Ruby just calls first-class functions blocks.


No, blocks are not first class (procs are, and procs are the closest thing Ruby has to functions, and a method definition can bind convert the block passed to the function to a proc if a first-class value is needed.)

Blocks are a syntactically special single argument to a method that can either be yielded to (a Ruby construct similar to a function call but which only applies to the block passed to the current method) or converted to a proc (but the latter only as part of the method definition, since they aren't first class and thus cannot be manipulated or referred to directly.)


No, blocks are lambdas.


No, in Ruby lambdas are lambdas (and are a special type of proc); the longhand way to create a lambda is to call Kernel#lambda and pass it a block (though modern Ruby has a special shorthand syntax for lambdas, as well.)

Blocks are sort of like anonymous function literals that are not first class, one (but no more than one) of which may be attached to a function call.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: