Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something to allow you to change $_ to a real variable in blocks #36

Closed
schwern opened this issue Jun 19, 2009 · 8 comments
Closed

Something to allow you to change $_ to a real variable in blocks #36

schwern opened this issue Jun 19, 2009 · 8 comments

Comments

@schwern
Copy link
Contributor

schwern commented Jun 19, 2009

Like in Ruby.

@foo = map { |$var| $var++ } @bar;

to be equivalent to

@foo = map { $_++ } @bar;

Perhaps using Data::Bind?

@schwern
Copy link
Contributor Author

schwern commented Jan 25, 2010

Integrating this with autoboxing and subroutine signatures, it would be...

my $foo = @bar->map(sub ($var) { $var++ });

@exodist
Copy link
Contributor

exodist commented May 9, 2010

Using Devel::Declare I can make
nmap my $var { "xxx" . $var } @list
and
ngrep my $var { $var eq .... } @list

But I cannot override actual grep and map.

the following all would work:

{
    my $var;
    nmap $var { ... }
}
nmap my $var { ... } @list
nmap local $var { ... } @list
nmap our $var { ... } @list

Would this be sufficient? or should we wait to override the actual map and grep builtins?

@exodist
Copy link
Contributor

exodist commented May 9, 2010

Scratch the local, but otherwise this is done:

http://github.com/exodist/Block-NamedVar - also uploaded to cpan, but may take a while to propogate

I will try to put this into my branch of perl5i tonight

@exodist
Copy link
Contributor

exodist commented May 9, 2010

nmap and ngrep are added in http://github.com/exodist/perl5i - master

@schwern
Copy link
Contributor Author

schwern commented May 9, 2010

Good work, but I have to rain on it.

Currently, perl5i cannot depend on Devel::Declare because it breaks one liners. That is open for debate as it blocks a lot of useful features. One possibility is for the perl5i binary to intercept -e and turn it into a real program.

@exodist
Copy link
Contributor

exodist commented May 10, 2010

"One possibility is for the perl5i binary to intercept -e and turn it into a real program."

Whats preventing us from doing this? is it a decision that has been made? If I were to do this would it be accepted (depending on implementation and quality of course)

@exodist
Copy link
Contributor

exodist commented May 10, 2010

My master has -e capturing added, DD works with my cli tests.

@schwern
Copy link
Contributor Author

schwern commented Jul 12, 2010

Its in 2.3.0_01. I suspect this feature will go away in v3 and be replaced with something using subroutine signatures. Example:

@new_array = @array->map( func($item) { ... } );

Especially if we can get rid of parens around methods.

@new = @array->map def($item) { ... };

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants