Code Monkey home page Code Monkey logo

Comments (7)

ujihisa avatar ujihisa commented on August 18, 2024

ちょっと思うところがあり、vializerをいじらずにモジュールの依存関係をVim内で解決させてみました。

diff --git autoload/vital/__latest__.vim autoload/vital/__latest__.vim
index 3fe31fc..ff33218 100644
--- autoload/vital/__latest__.vim
+++ autoload/vital/__latest__.vim
@@ -3,8 +3,8 @@ let s:self_version = expand('<sfile>:t:r')

 let s:loaded = {}

-function! s:import(name, ...)
-  let module = s:_import(a:name, s:_scripts())
+function! s:import(name, ...) dict
+  let module = s:_import(self, a:name, s:_scripts())
   if a:0 && type(a:1) == type({})
     call extend(a:1, module, 'keep')
   endif
@@ -29,15 +29,15 @@ function! s:load(...) dict
     endwhile

     if !empty(target) && !has_key(dict, target[0])
-      let dict[target[0]] = s:_import(name, scripts)
+      let dict[target[0]] = s:_import(self, name, scripts)
     endif
   endfor
   return self
 endfunction

-function! s:_import(name, scripts)
+function! s:_import(V, name, scripts)
   if type(a:name) == type(0)
-    return s:_build_module(a:name)
+    return s:_build_module(a:V, a:name)
   endif
   if a:name =~# '^[^A-Z]' || a:name =~# '\W[^A-Z]'
     throw 'vital: module name must start with capital letter: ' . a:name
@@ -55,7 +55,7 @@ function! s:_import(name, scripts)
     endtry
     let sid = len(a:scripts) + 1  " We expect that the file newly read is +1.
   endif
-  return s:_build_module(sid)
+  return s:_build_module(a:V, sid)
 endfunction

 function! s:_scripts()
@@ -73,7 +73,7 @@ function! s:_unify_path(path)
   return fnamemodify(resolve(a:path), ':p:gs?\\\+?/?')
 endfunction

-function! s:_build_module(sid)
+function! s:_build_module(V, sid)
   if has_key(s:loaded, a:sid)
     return copy(s:loaded[a:sid])
   endif
@@ -85,6 +85,7 @@ function! s:_build_module(sid)
   \          'matchstr(v:val, map_pat)')

   let module = {}
+  let module.V = a:V
   for func in functions
     let module[func] = function(prefix . func)
   endfor
@@ -108,7 +109,9 @@ function! s:_redir(cmd)
 endfunction

 function! vital#{s:self_version}#new()
-  let V = s:import('')
+  let V = {}
+  let V.import = function('s:import')
+  let V = V.import('')
   call V.import('Prelude', V)
   return V
 endfunction
diff --git autoload/vital/__latest__/data/string.vim autoload/vital/__latest__/data/string.vim
index 85acc0a..6d271b6 100644
--- autoload/vital/__latest__/data/string.vim
+++ autoload/vital/__latest__/data/string.vim
@@ -4,6 +4,10 @@ let s:save_cpo = &cpo
 set cpo&vim
 let s:V = vital#{expand('<sfile>:h:h:t:r')}#new()

+function! s:unko(x) dict
+  echo self.V.system(a:x)
+endfunction
+
 " Substitute a:from => a:to by string.
 " To substitute by pattern, use substitute() instead.
 " Test: https://gist.github.com/984296

実験的にこんなのどうでしょう。他のモジュールを参照するような関数はDictionary functionにして、self経由で参照する、と。

ただし各関数がそれぞれ独自にself.importとかself.loadするとややこしいことになるので、各モジュールごとに(そのモジュール全体単位で)import時にどの他のmoduleもimportするか指定するsetupあるいはinitialize的な特殊な関数を用意しておくとよさそうです。

from vital.vim.

thinca avatar thinca commented on August 18, 2024

s:unko(x)...

from vital.vim.

thinca avatar thinca commented on August 18, 2024

辞書関数としてしか使えなくなってしまうのが若干気になりますが、妥当な案ではあると思います。
vitalizer に依存情報を渡すのはどうしましょうか。

from vital.vim.

ujihisa avatar ujihisa commented on August 18, 2024

とりあえずこの方向性で実装してみます。masterではなくcodependenceというブランチを作ってそちらでやっていきます。

この方法での問題が発覚したり、あるいはもっといい別の方法が見つかった場合は、ブランチまるごと破棄してもいいかなと思っています。

from vital.vim.

thinca avatar thinca commented on August 18, 2024

vitalizer に依存情報を渡すのはどうしましょうか。

この部分はどうする予定でしょう?

from vital.vim.

ujihisa avatar ujihisa commented on August 18, 2024

とりあえず次のステップとして、dependencies.rbというのを追加しました。これは依存関係の一覧を表示するだけのスクリプトです。

["Data.List", []]
["Data.Ordered_set", []]
["Data.String", ["Data.List"]]
["Functor", []]
["Mapping", []]
["Prelude", []]
["System.File", []]
["System.Filepath", []]

vitalizerに依存情報を渡すときに、内部で依存しているモジュールも必要なので、とりあえずこれを作った次第です。続きはCMのあと・・

from vital.vim.

thinca avatar thinca commented on August 18, 2024

最新masterでは、vitalizerをpure vim scriptで書き直し、依存関係を各モジュールの _vital_depends() から返すようにしました。
現状で最善の解決策かと思うので、とりあえずcloseします。
また何かあれば再オープンするなり新しくissueを開くなりしてください。

from vital.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.