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

Dispatch weirdness in REPL #3323

Closed
p6rt opened this issue Jan 30, 2014 · 5 comments
Closed

Dispatch weirdness in REPL #3323

p6rt opened this issue Jan 30, 2014 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Jan 30, 2014

Migrated from rt.perl.org#121117 (status was 'rejected')

Searchable as RT121117$

@p6rt
Copy link
Author

p6rt commented Jan 30, 2014

From mark@kli.org

 

 
 
 
 
  Consider​:

 

  multi sub f1(Any $x) { "Any $x" }

  multi sub f2(Any $x) { f1($x) }

  multi sub f1(Rat $x) { "Rat $x" }

 

  say f2("a");

  say f2(1.9);

  say f1(1.9);

 

  This should produce

 

  Any a

  Rat 1.9

  Rat 1.9

 

  And so it does, when run from a file.  But when typed in the REPL,
  we get

 

  Any a

  Any 1.9

  Rat 1.9

 

  i.e. the f2 call doesn't pick up the more specific f1.  If you
  reverse the order of the second and third sub definitions and thus
  define both f1's before the f2, we get the correct results even in
  the REPL.

 

@p6rt
Copy link
Author

p6rt commented Jan 30, 2014

From @pmichaud

On Wed, Jan 29, 2014 at 06​:14​:38PM -0800, Mark E. Shoulson wrote​:

Consider​:

multi sub f1(Any $x) { "Any $x" }
multi sub f2(Any $x) { f1($x) }
multi sub f1(Rat $x) { "Rat $x" }

say f2("a");
say f2(1.9);
say f1(1.9);

The way the REPL works is that each line of entered input
ends up in its own (nested) lexical scope. We've yet to
find a good solution around this -- in order to complete
compilation and execution of a line, we kinda have to make
the current lexical scope concrete. This is at least
implied in several sections of the synopses, where the lexical
symbol table is considered static after compilation completes
("CHECK" time, I believe).

Thus when the lines above are entered one at a time,
the REPL treats it as​:

  {
  multi sub f1(Any $x) { "Any $x" }

  {
  multi sub f2(Any $x) { f1($x) }

  {
  multi sub f1(Rat $x) { "Rat $x" }

  {
  say f2("a");

  {
  say f2(1.9);

  {
  say f1(1.9);
  }
  }
  }
  }
  }
  }

So, when f2() is executed, the f1(Rat) multi isn't in scope and
never gets called.

To think of it another way -- each line of input to the REPL
is treated like a nested EVAL, thus resulting in its own lexical
scope.

At the moment I'm inclined to reject this ticket as "not a bug",
since Perl 6.0 design seems to constrain anything REPL-like to
work this way. But perhaps someone sees a way to have lexical
scopes that can be more dynamic/interactive, so I'll give time
for other opinions before closing this.

Pm

@p6rt
Copy link
Author

p6rt commented Jan 30, 2014

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 27, 2016

From @coke

On Thu Jan 30 07​:15​:52 2014, pmichaud wrote​:

On Wed, Jan 29, 2014 at 06​:14​:38PM -0800, Mark E. Shoulson wrote​:

Consider​:

multi sub f1(Any $x) { "Any $x" }
multi sub f2(Any $x) { f1($x) }
multi sub f1(Rat $x) { "Rat $x" }

say f2("a");
say f2(1.9);
say f1(1.9);

The way the REPL works is that each line of entered input
ends up in its own (nested) lexical scope. We've yet to
find a good solution around this -- in order to complete
compilation and execution of a line, we kinda have to make
the current lexical scope concrete. This is at least
implied in several sections of the synopses, where the lexical
symbol table is considered static after compilation completes
("CHECK" time, I believe).

Thus when the lines above are entered one at a time,
the REPL treats it as​:

{
multi sub f1(Any $x) { "Any $x" }

 \{ 
   multi sub f2\(Any $x\) \{ f1\($x\) \}

   \{ 
     multi sub f1\(Rat $x\) \{ "Rat $x" \}

     \{ 
       say f2\("a"\);

       \{ 
         say f2\(1\.9\);

         \{ 
           say f1\(1\.9\);
         \}
       \}
     \}
   \}
 \}

}

So, when f2() is executed, the f1(Rat) multi isn't in scope and
never gets called.

To think of it another way -- each line of input to the REPL
is treated like a nested EVAL, thus resulting in its own lexical
scope.

At the moment I'm inclined to reject this ticket as "not a bug",
since Perl 6.0 design seems to constrain anything REPL-like to
work this way. But perhaps someone sees a way to have lexical
scopes that can be more dynamic/interactive, so I'll give time
for other opinions before closing this.

Pm

Rejecting ticket.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Jul 27, 2016

@coke - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Jul 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant