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

Potential conflict with Pluto? #39

Closed
max-sixty opened this issue Dec 6, 2021 · 6 comments
Closed

Potential conflict with Pluto? #39

max-sixty opened this issue Dec 6, 2021 · 6 comments

Comments

@max-sixty
Copy link

I'm new to Julia and so I might be making a naive mistake.

In Pluto, running something like this prints the docs! This may be because in pluto, the docs are offered in a pop-up on the bottom right.

@chain begin "3,4,3,1,2"
	strip
end

image

and running

@chain begin "3,4,3,1,2"
	strip
	split(",") 
end

returns an error

MethodError: no method matching split(::Base.Docs.Binding, ::String)

Closest candidates are:

split(!Matched::T, ::Any; limit, keepempty) where T<:AbstractString at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/strings/util.jl:417

    top-level scope@Local: 3[inlined]

It's not purely a Pluto issue though — @_ from Underscores.jl doesn't have this problem, maybe because it doesn't use multiple lines?

Thank you!

@max-sixty
Copy link
Author

FWIW surrounding the block with another begin ... end makes it work, so possibly this is more of a Pluto issue?

@jkrumbiegel
Copy link
Owner

Hah I remember seeing this error once and not understanding it, but now I do. The problem is that the string "3,4,3,1,2" above strip is parsed into a docstring for the strip function. This happens at parse time and I can't do anything about it in my macro. You can see this if you look at the output of Meta.@dump:

julia> Meta.@dump @chain begin
               "3,4,3,1,2"
               strip
               split(",") 
       end
Expr
  head: Symbol macrocall
  args: Array{Any}((3,))
    1: Symbol @chain
    2: LineNumberNode
      line: Int64 1
      file: Symbol REPL[5]
    3: Expr
      head: Symbol block
      args: Array{Any}((4,))
        1: LineNumberNode
          line: Int64 2
          file: Symbol REPL[5]
        2: Expr
          head: Symbol macrocall
          args: Array{Any}((4,))
            1: GlobalRef
              mod: Module Core
              name: Symbol @doc
            2: LineNumberNode
              line: Int64 2
              file: Symbol REPL[5]
            3: String "3,4,3,1,2"
            4: Symbol strip
        3: LineNumberNode
          line: Int64 4
          file: Symbol REPL[5]
        4: Expr
          head: Symbol call
          args: Array{Any}((2,))
            1: Symbol split
            2: String ","

Of course, now that I think about it, I could specifically intercept this situation and re-expand the doc macro call into a string and a function..

@jkrumbiegel
Copy link
Owner

The workaround is to put the string before the begin block to avoid the doc parsing

@max-sixty
Copy link
Author

Thanks @jkrumbiegel! I'm less familiar with how this works — should I put an issue in Pluto? Or is this unavoidable on their side too?

@jkrumbiegel
Copy link
Owner

No they're just expanding the macro and finding the docstring, I could try to fix that, remove the doc string in the first line if there's one

@jkrumbiegel
Copy link
Owner

Fixed in #41

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

2 participants