Skip to content

Commit

Permalink
- Added auto-conversion for lazy methods.
Browse files Browse the repository at this point in the history
Example:
	var x = 42.method(:add, 3);
	say x{:obj}			# prints: 42
	say x				# prints: 45 (calls the method :add on demand)

- Minor improvement in deparsing multi-arrays as Sidef code.
  • Loading branch information
trizen committed Dec 11, 2015
1 parent 287e369 commit ef52c90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/Sidef/Types/Array/MultiArray.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ package Sidef::Types::Array::MultiArray {
sub dump {
my ($self) = @_;
Sidef::Types::String::String->new(
'MultiArr(' . "\n\t" . join(
",\n\t",
'MultiArr(' . join(
",\n\t ",
map {
'[' . join(
", ",
Expand All @@ -95,7 +95,7 @@ package Sidef::Types::Array::MultiArray {
. ']'
} @{$self}
)
. "\n)"
. ")"
);
}
};
Expand Down
25 changes: 16 additions & 9 deletions lib/Sidef/Variable/LazyMethod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ package Sidef::Variable::LazyMethod {
bless \%hash, __PACKAGE__;
}

{
no strict 'refs';
foreach my $meth (qw(say print println)) {
*{__PACKAGE__ . '::' . $meth} = sub {
my $self = shift;
local $AUTOLOAD = __PACKAGE__ . '::' . $meth;
$self->AUTOLOAD(@_);
}
}
sub to_s {
my $self = shift;
local $AUTOLOAD = __PACKAGE__ . '::' . 'to_s';
$self->AUTOLOAD(@_);
}

sub to_b {
my $self = shift;
local $AUTOLOAD = __PACKAGE__ . '::' . 'to_b';
$self->AUTOLOAD(@_);
}

sub to_n {
my $self = shift;
local $AUTOLOAD = __PACKAGE__ . '::' . 'to_n';
$self->AUTOLOAD(@_);
}

sub DESTROY { }
Expand Down

0 comments on commit ef52c90

Please sign in to comment.