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

WIP: Add a Context object #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

kskyten
Copy link

@kskyten kskyten commented Nov 22, 2020

I tried to add a Context object as per #20, but ran into some issues. For some reason the context object seems to get inserted into the generated code. This is what I get:

julia> using Py2Jl.ASTGen: Context, to_ast

julia> using Py2Jl.Process: process

julia> xp = process("""
       def foo(x):
           x + 1
       """)
Dict{Symbol,Any} with 2 entries:
  :class => "Module"
  :body  => Dict{Symbol,Any}[Dict(:name=>"foo",:args=>Dict{Symbol,Any}(:kwarg=>nothing,:args=>Dict{Symbol,Any}[Dict(:

julia> to_ast(Context(nothing, nothing), xp)
:(module filename
  Py2Jl.ASTGen.var"##λ#253#9"{Nothing}(nothing)
  begin
      function foo(x)
          begin
              Py2Jl.ASTGen.var"##λ#253#9"{Nothing}(nothing)
              begin
                  (+)(x, 1)
                  nothing
              end
          end
      end
      nothing
  end
  end)

I don't fully understand what gather, tag_loc and trans_block are doing. Also I didn't find what the definition for the <| operator inside the _apply pattern function is. I see how you are using the Record pattern to do a kind of a destructuring bind on the keys of a dictionary, but I don't understand how the definition works from the MLStyle docs.

@thautwarm
Copy link
Member

You are correct, and now I don't think the functions confusing you are good to keep. Instead of making this PR, I prefer to talk with you about how to evaluate generated julia code in given module. This is the approach I'd prefer.

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

Successfully merging this pull request may close these issues.

2 participants