What is a block expression? I'll give an example of what it might look like if it were allowed in C:
int a ;
a = {
int b ;
int c ;
b = 10 ;
c = 20 ;
return b + c ;
}
Of course, that's not legal.
A block indicates a group expressions which are executed in sequence, possibly in a new scope. The value of the last expression is returned.
Some languages allow blocks as expressions.
(define a (let ()
(define b 10)
(define c 20)
(+ b c)))
my $a = do { my $b = 10 ; my $c = 20 ; $b + $c } ;
#include <stdio.h>
int main ()
{
int a ;
a = ({ int b = 10 , c = 20 ; b + c ; }) ;
printf ( "%d\n" , a ) ;
return 0 ;
}
See the section 6.1 of the GCC manual for more details.
a = proc { b = 10 ; c = 20 ; b+c }.call()
Python
The ruby example is actually just defining a function, then evaluating it and storing the return value, which to me doesn't seem to be the same thing as a block expression, if you're allowing this then in python you could do:
def __throwaway():
b = 10
c = 20
return b+c
a = __throwaway()
However in all of these cases when you're using a block expression, you should probably be asking yourself "why isn't this just a private method?"