Feature #15915

`@1` cannot be achieved in meta-programming

Added by znz (Kazuhiro NISHIYAMA) 10 months ago. Updated 3 months ago.

Target version:


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)


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

Updated by sawa (Tsuyoshi Sawada) 10 months ago

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

Updated by mame (Yusuke Endoh) 10 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) 8 months 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 = -> {
  @1 * @1
% 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
  @1 * @1

Updated by sawa (Tsuyoshi Sawada) 7 months 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) 7 months 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.

Updated by znz (Kazuhiro NISHIYAMA) 3 months ago

  • Status changed from Open to Closed

I think this issue resolved by changing from @1 to _1.

Also available in: Atom PDF