• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Roger-luo/FromFile.jl: Julia enhancement proposal (Julep) for implicit per file ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

Roger-luo/FromFile.jl

开源软件地址:

https://github.com/Roger-luo/FromFile.jl

开源编程语言:

Julia 100.0%

开源软件介绍:

FromFile.jl

This package exports a macro @from, which can be used to import objects from files.

The hope is that you will never have to write include again.

Installation

FromFile is a   Julia Language   package. To install FromFile, please open Julia's interactive session (known as REPL) and press ] key in the REPL to use the package mode, then type the following command

pkg> add FromFile

Usage

Objects in other files may be imported in the following way:

# file1.jl
import FromFile: @from
@from "file2.jl" import foo

bar() = foo()

#file2.jl
foo() = println("hi")

File systems may be navigated: @from "../folder/file.jl" import foo

The usual import syntax is supported; the only difference is that the objects are looked up in the file requested: @from "file.jl" using MyModule; @from "file.jl" import MyModule: foo; @from "file.jl" import foo, bar.

Using @from to access a file multiple times (for example calling @from "file.jl" import foo in multiple files) will access the same objects each time; i.e. without the duplication issues that include("file.jl") would introduce.

Specification

FromFile.jl is a draft implementation of this specification, for improving import systems as discussed in Issue 4600.

Tips

FromFile will (besides its programmatic benefits like the removal of spooky action at a distance) help you keep track of what objects are defined in what file. When converting over to FromFile that may mean untangling your existing project, and figuring out exactly what you defined where. To print out which file defines which object, you can execute the following bash snippet at the root of your project:

for f in $(find . -name '*.jl'); do echo $f && cat $f | vim - -nes -c '%s/#.*//ge' -c '%s/"""\_.\{-}"""//ge' -c '%v/^\S\+/d_' -c '%g/^\(end\|@from\|using\|export\|import\|include\|begin\|let\)\>/d_' -c '%g/.*/exe "norm >>"' -c ':%p' -c ':q!' | tail -n +2; done | less

This should (hopefully) print out each file, and the objects defined in that file. It's not perfect, but it'll help you get 90% of the way there.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap