Skip to content

Is the meta programming allowed in REPL? #5551

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

Closed
plokhotnyuk opened this issue Dec 1, 2018 · 1 comment
Closed

Is the meta programming allowed in REPL? #5551

plokhotnyuk opened this issue Dec 1, 2018 · 1 comment

Comments

@plokhotnyuk
Copy link

plokhotnyuk commented Dec 1, 2018

I have tried to run an example from the Principled Meta Programming doc page.

  1. It seems that some import is missing to compile with the showExpr call.
  2. Even after successful compilation without that call I cannot use the assert macro:
andriy@notebook:~/Downloads/dotty-0.10.0/bin$ ./dotr
Starting dotty REPL...
scala> import scala.quoted._                                                                                                                                                                                       
     | 
     | inline def assert(expr: => Boolean): Unit =
     |   ~ assertImpl('(expr))
     | 
     | def assertImpl(expr: Expr[Boolean]) =
     |   '{ if !(~expr) then throw new AssertionError("failed assertion")}
def assert(expr: => Boolean): Unit
def assertImpl(expr: quoted.Expr[Boolean]): quoted.Expr[Unit]

scala> assert(0 == 0)
1 |assert(0 == 0)
  |^^^^^^^^^^^^^^
  |Could not find macro class rs$line$1$ in classpath. The most common reason for that is that you apply macros in the compilation run that defines them
@nicolasstucki
Copy link
Contributor

nicolasstucki commented Dec 1, 2018

  1. showExpr is actually defined below in the document. Though its definition is also wrong (outdated) (improves with Improve showExpr example #5562).
  2. As far as I can see it should be possible to define macros in the REPL. Most likely the macro classloader gets confused by the special classloader that the REPL uses.

odersky added a commit that referenced this issue Jan 12, 2019
Fix #5551: Handle repl line modules in splicer
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

3 participants