Project

General

Profile

Feature #15915

`@1` cannot be achieved in meta-programming

Added by znz (Kazuhiro NISHIYAMA) 2 months ago. Updated 1 day ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:93064]

Description

I cannot think of any way to get @1 in meta-programming, so it is hard to inspect it in a debugger.

% ruby -e 'proc{@1;binding.local_variable_get("@1")}.call(1)'
Traceback (most recent call last):
    2: from -e:1:in `<main>'
    1: from -e:1:in `block in <main>'
-e:1:in `local_variable_get': wrong local variable name `@1' for #<Binding:0x00007f952401e490> (NameError)

Files

local_variable_get-for-numparam.patch (3.61 KB) local_variable_get-for-numparam.patch mame (Yusuke Endoh), 08/23/2019 04:40 AM

History

Updated by sawa (Tsuyoshi Sawada) 2 months ago

What is the use case? And how do you want it to be made possible?

Updated by mame (Yusuke Endoh) 2 months ago

What is the use case?

OP says a debugger. The motivation looks reasonable to me.

And how do you want it to be made possible?

I think it would be technically possible.

If this ticket is accepted, Binding#local_variables should include numbered parameters. It might be good to allow a symbol like :@1.

(I'm negative against numbered parameters themselves, though.)

Updated by hanachin (Seiei Miyagi) 11 days ago

When I debug a proc which use the numbered parameters, I can not inspect the numbered parameters.
Because irb use Binding to evaluate input but the numbered parameters can not get from binding.

square = -> {
  binding.irb
  @1 * @1
}
square[rand(100)]
% ruby foo.rb

From: foo.rb @ line 2 :

    1: square = -> {
 => 2:   binding.irb
    3:   @1 * @1
    4: }
    5: square[rand(100)]

irb(main):001:0> @1
Traceback (most recent call last):
        3: from foo.rb:5:in `<main>'
        2: from foo.rb:2:in `block in <main>'
        1: from <internal:prelude>:206:in `irb'
SyntaxError ((irb):1: numbered parameter outside block)

I need to give a name to the numbered parameters to inspect value.
It doesn't make sense.

square = -> {
  v = @1
  binding.irb
  @1 * @1
}
square[rand(100)]
#5

Updated by sawa (Tsuyoshi Sawada) 2 days ago

  • Description updated (diff)
  • Subject changed from `@1` cannot get from meta-programming to `@1` cannot be achieved in meta-programming

Updated by nobu (Nobuyoshi Nakada) 1 day ago

I'm negative to add ID_NUMPARAM.
As rb_is_numparam_id is not used, and rb_is_numparam_name can be implemented without rb_symname_type.

Also available in: Atom PDF