Skip to content

Commit

Permalink
modified: README.md
Browse files Browse the repository at this point in the history
modified:   lib/Sidef/Object/Object.pm
new file:   utils/Experiments/Lazy/Lazy.pm	-- experiment
  • Loading branch information
trizen committed Dec 15, 2015
1 parent 8b8c966 commit 76d78b5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ utils/Examples/sidef_in_perl.pl
utils/Experiments/bigint.sm
utils/Experiments/bigrat.sm
utils/Experiments/C-inline-function-call.pl
utils/Experiments/Lazy/Lazy.pm
utils/Experiments/operator_precendece.pl
utils/Experiments/regexp_grammars_op_precedence.pl
utils/Experiments/regexp_grammars_parser.pl
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Sidef is a high-level, general-purpose programming language, inspired by Ruby, P

### WWW

* Github: https://github.com/trizen/sidef
* Gitbook: http://trizen.gitbooks.io/sidef-lang/
* Gitbook: http://trizen.gitbooks.io/sidef-lang
* Tutorial: https://github.com/trizen/sidef/wiki
* RosettaCode: http://rosettacode.org/wiki/Sidef

### LICENSE AND COPYRIGHT
Expand Down
5 changes: 5 additions & 0 deletions lib/Sidef/Object/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ package Sidef::Object::Object {
Sidef::Variable::LazyMethod->new(obj => $self, method => $method, args => \@args);
}

#~ sub lazy {
#~ my ($self) = @_;
#~ Sidef::Lazy::Lazy->new($self);
#~ }

sub object_id {
my ($self) = @_;
Sidef::Types::Number::Number->new(Scalar::Util::refaddr($self));
Expand Down
48 changes: 48 additions & 0 deletions utils/Experiments/Lazy/Lazy.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package Sidef::Lazy::Lazy {

use 5.014;

our $AUTOLOAD;

sub new {
my (undef, $self) = @_;
bless {root => $self}, __PACKAGE__;
}

sub START {
my ($self) = @_;

my $root = $self->{root};

my @result;
foreach my $item (@{$root}) {

my $obj;
foreach my $method (@{$self->{methods}}) {
my $name = $method->{name};
$obj = Sidef::Types::Array::Array->new($item)->$name(@{$method->{arg}});
@{$obj} || last;
}

push @result, @{$obj};
}

Sidef::Types::Array::Array->new(@result);
}

sub AUTOLOAD {
my ($self, @arg) = @_;

my ($method) = ($AUTOLOAD =~ /^.*[^:]::(.*)$/);

push @{$self->{methods}},
scalar {
name => $method,
arg => \@arg,
};

$self;
}
};

1

0 comments on commit 76d78b5

Please sign in to comment.