Skip to content

Commit

Permalink
- Declaring blocks as '{|| ... }' will prevent the declaration of a t…
Browse files Browse the repository at this point in the history
…opic variable (_).

This allows blocks to be called as 'block()' without arguments.

Example:
	var block = {|| say "hi" };
	block.run;          # perfect
	block.call;         # ok
	block();            # ok
  • Loading branch information
trizen committed Dec 10, 2015
1 parent c723701 commit 6c45643
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Sidef/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2257,15 +2257,16 @@ package Sidef::Parser {
# Parse whitespace (if any)
$self->parse_whitespace(code => $opt{code});

my $has_vars;
my $var_objs = [];
if (/\G(?=\|)/) {
$var_objs =
$self->parse_init_vars(code => $opt{code},
type => 'var');
$has_vars = 1;
$var_objs = $self->parse_init_vars(code => $opt{code},
type => 'var',);
}

# Special '_' variable
if ($opt{topic_var} and not @{$var_objs}) {
if ($opt{topic_var} and not $has_vars) {
my $var_obj = bless({name => '_', type => 'var', class => $self->{class}}, 'Sidef::Variable::Variable');

push @{$var_objs}, $var_obj;
Expand Down

0 comments on commit 6c45643

Please sign in to comment.