Re:How Ruby Borrowed a Decades Old Idea From Lisp
by davidw on Tuesday September 18, 2012 @10:57AM
(#4538395)
Tcl uses blocks for pretty much everything, and they're not that bad looking:
The first one is actually an expression, but the do this and do something else are simply blocks of code passed to the 'if' command.
[ Parent
| on HN ]
Re:How Ruby Borrowed a Decades Old Idea From Lisp
by draegtun on Wednesday September 19, 2012 @05:32AM
(#4542832)
Its beauty (and power) comes with the consistency of the syntax ala Smalltalk / Lisp.
PS. Here's an example of creating something similar with Perl:
sub IF (&@) {
my ($block, $flow) = @_;
[ map { $flow->{$_} || sub {} } qw/else then/ ]->[ $block->() ]->();
}
sub THEN (&@) {
my $block = shift;
my $flow = shift || {};
$flow->{then} = $block;
$flow;
}
sub ELSE (&) {
my $block = shift;
+{ else => $block };
}
IF { 1 == 0 } THEN { say "True" } ELSE { say "False" };
And with these being functions and not statements we can also do: my $result = IF { 1 == 1 } THEN { "True" } ELSE { "False" };
Re:How Ruby Borrowed a Decades Old Idea From Lisp
by arthurschreiber on Tuesday September 18, 2012 @02:10PM
(#4539598)
Well, but Tcl blocks are nothing more than strings that you pass as arguments that then get eval'ed using uplevel. Ruby blocks are "real" language constructs, and are real closures, in difference to Tcl blocks.
Re:How Ruby Borrowed a Decades Old Idea From Lisp
by davidw on Tuesday September 18, 2012 @03:37PM
(#4540072)
I can assure you that Tcl blocks are quite "real" in that they are code that gets executed. Initially, yes, they are treated as a string, but then they get byte compiled, and remain 'code' internally.