From 76d78b5dbd6ede373fe87024fe32ae2a2ba64fc2 Mon Sep 17 00:00:00 2001 From: trizen Date: Tue, 15 Dec 2015 02:45:11 +0200 Subject: [PATCH] modified: README.md modified: lib/Sidef/Object/Object.pm new file: utils/Experiments/Lazy/Lazy.pm -- experiment --- MANIFEST | 1 + README.md | 4 +-- lib/Sidef/Object/Object.pm | 5 ++++ utils/Experiments/Lazy/Lazy.pm | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 utils/Experiments/Lazy/Lazy.pm diff --git a/MANIFEST b/MANIFEST index 19dc0ad4b..b495ddc1f 100644 --- a/MANIFEST +++ b/MANIFEST @@ -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 diff --git a/README.md b/README.md index c69b5d012..1257dda47 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/Sidef/Object/Object.pm b/lib/Sidef/Object/Object.pm index 416600720..f5ad0b3eb 100644 --- a/lib/Sidef/Object/Object.pm +++ b/lib/Sidef/Object/Object.pm @@ -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)); diff --git a/utils/Experiments/Lazy/Lazy.pm b/utils/Experiments/Lazy/Lazy.pm new file mode 100644 index 000000000..a20408319 --- /dev/null +++ b/utils/Experiments/Lazy/Lazy.pm @@ -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