如何在REPL中打印Julia中的功能代码? [英] How to print in REPL the code of functions in Julia?

查看:143
本文介绍了如何在REPL中打印Julia中的功能代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Julia中,许多与Base和更紧密相关的功能也都是用纯Julia编写的,并且代码易于使用.可以浏览存储库或本地下载的文件,并查看该函数的编写/实现方式.但是我认为已经有一些内置的方法可以为您做到这一点,因此您可以在REPL或Jupyter Notebook中编写如下内容:

In Julia, a lot of the Base and closer related functions are also written in pure Julia, and the code is easily avaible. One can skim through the repository or the local downloaded files, and see how the function is written/implemented. But I think there is allready some built in method that does that for you, so you can write in REPL or Jupyter Notebook something like:

@code functioninquestion()

并得到类似的东西:

functioninquestion(input::Type) some calculations return end 无需通过代码分页. 我只是不记得方法或调用.我已经阅读了《手册》中的反思/内省"部分,但似乎无法在其中使用任何内容.我已经尝试过methodsmethodswithcode_loweredexpand,但似乎无法让它们给出我想要的东西-

functioninquestion(input::Type) some calculations return end without paging throug the code. I just don't remember the method or call. I have read the Reflection/Introspection section of the Manual but I cannot seem to be able to use anything there. I've tried methods, methodswith, code_lowered, expand and cannot seem to make them give what I want-

推荐答案

尽管这可能不是OP所需要的,但@less却非常方便阅读底层代码(因此我经常使用它).例如

Though this may not be what the OP is looking for, @less is very convenient to read the underlying code (so I very often use it). For example,

julia> @less 1 + 2

给予

+(x::Int, y::Int) = box(Int,add_int(unbox(Int,x),unbox(Int,y)))

对应于

julia> @which 1 + 2
+(x::Int64, y::Int64) at int.jl:8

这篇关于如何在REPL中打印Julia中的功能代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆