[#78949] [Ruby trunk Feature#13095] [PATCH] io.c (rb_f_syscall): remove deprecation notice — kosaki.motohiro@...
Issue #13095 has been updated by Motohiro KOSAKI.
3 messages
2017/01/03
[#78997] [Ruby trunk Bug#13110] Byte-based operations for String — shugo@...
Issue #13110 has been updated by Shugo Maeda.
3 messages
2017/01/06
[#79228] Re: [ruby-cvs:64576] naruse:r57410 (trunk): Prevent GC by volatile [Bug #13150] — Eric Wong <normalperson@...>
naruse@ruby-lang.org wrote:
5 messages
2017/01/23
[#79511] Re: [ruby-cvs:64576] naruse:r57410 (trunk): Prevent GC by volatile [Bug #13150]
— Eric Wong <normalperson@...>
2017/02/13
Eric Wong <normalperson@yhbt.net> wrote:
[#79518] Re: [ruby-cvs:64576] naruse:r57410 (trunk): Prevent GC by volatile [Bug #13150]
— Nobuyoshi Nakada <nobu@...>
2017/02/13
On 2017/02/13 10:04, Eric Wong wrote:
[#79298] [Ruby trunk Bug#13085][Assigned] io.c io_fwrite creates garbage — nobu@...
Issue #13085 has been updated by Nobuyoshi Nakada.
3 messages
2017/01/29
[#79337] Re: [ruby-changes:45397] normal:r57469 (trunk): io.c: recycle garbage on write — SASADA Koichi <ko1@...>
Eric:
4 messages
2017/01/31
[#79352] Re: [ruby-changes:45397] normal:r57469 (trunk): io.c: recycle garbage on write
— Eric Wong <normalperson@...>
2017/01/31
SASADA Koichi <ko1@atdot.net> wrote:
[ruby-core:79260] [Ruby trunk Feature#12901] Anonymous functions without scope lookup overhead
From:
Ruby-Lang@...
Date:
2017-01-25 03:28:32 UTC
List:
ruby-core #79260
Issue #12901 has been updated by J旦rg W Mittag.
I have thought about this a number of times, but never got around to writing a feature request: we already have a way to tell Ruby that we don't want to capture certain variables from the surrounding scope: block local variables. We also have "wildcard" syntax for block parameters. So, let's just combine the two, to tell Ruby that we don't want to capture any variables:
Proc.new {|a, b:, *c; d, e, *| }
# or
-> (a, b:, *c; d, e, *) {}
This will make `d` and `e` block local variables, and make the block not close over the surrounding environment.
This is a conservative extension of existing syntax.
We can even further extend it to provide a "whitelist" of variables to capture:
Proc.new {|a, b:, *c; d, e, *; f, g| }
# or
-> (a, b:, *c; d, e, *; f, g) {}
This will make it an error if there are no local variables named `f` and `g` in the surrounding scope. The *current* behavior would then be equivalent to:
Proc.new {|a, b:, *c;; *| }
# or
-> (a, b:, *c;; *) {}
I.e.: no block local variables, capture all variables.
We will need to make a decision, though, as to whether this should include lexical binding of `self` or not. We could easily allow both explicit opt-out and explicit opt-in by allowing `self` as a legal identifier in the parameter list. E.g. a block that captures no variables, but *does* capture `self` would be declared like:
Proc.new {|a, b:, *c;* ; self| }
# or
-> (a, b:, *c; *; self) {}
A block that captures all variables but does not capture `self`:
Proc.new {|a, b:, *c;self ; *| }
# or
-> (a, b:, *c; self; *) {}
and a block that captures *nothing*:
Proc.new {|a, b:, *c;*, self| }
# or
-> (a, b:, *c; *, self) {}
An open question is: what should the default for capturing `self` be, when there is only a wildcard, i.e. these two cases:
Proc.new {|a, b:, *c;; *| }
# or
-> (a, b:, *c;; *) {}
Proc.new {|a, b:, *c; *| }
# or
-> (a, b:, *c; *) {}
I have no preference either way.
----------------------------------------
Feature #12901: Anonymous functions without scope lookup overhead
https://bugs.ruby-lang.org/issues/12901#change-62674
* Author: Richard Schneeman
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Right now if you are writing performance sensitive code you can get a performance bump by not using anonymous functions (procs, lambdas, blocks) due to the scope lookup overhead.
https://twitter.com/apotonick/status/791167782532493312?lang=en
I would like to be able to create an anonymous function and specify I don't need it to perform the lookup when called.
I am thinking that this code:
~~~
Proc.new(scope: false) {|var| puts var }
~~~
Would be the equivalent of
~~~
def anon(var)
puts var
end
~~~
If you call it while trying to access something from outside of the scope it would error
~~~
var = "hello"
Proc.new(scope: false) { puts var }.call
# => NameError: undefined local variable or method `var' for main:Object
~~~
An example of a case where this could be used is found in https://github.com/rails/sprockets/pull/417. In this case we are getting rid of anonymous functions in favor of a method created with refinements. This solution works but it was not an obvious optimization. It would be convenient to have a syntax for defining anonymous functions that do not need access to caller scope.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>