2

What is the mzscheme equivalent of the following codes?

  • python:

    python import sys, vim
    python sys.path.append(vim.eval("var"))
    <...>
    python sys.path.remove(vim.eval("var"))
    
  • perl:

    perl push @INC, [VIM::Eval("var")]->[1];
    <...>
    perl @INC=(grep {$_ ne VIM::Eval("var")} @INC);
    
  • lua:

    let str=';'.var.'/?.lua;'.var.'/?/init.lua'
    lua package.path=package.path..vim.eval("str")
    <...>
    let ppath=[]
    lua vim.eval("add(ppath,"..string.format("%q", package.path)..")")
    let importidx=stridx(ppath[0], str)
    let importendidx=importidx+len(str)
    let ppath[0]=((importidx>0)?(ppath[0][:(importidx-1)]):("")).
                \ppath[0][(importendidx+1):]
    lua package.path=vim.eval("ppath[0]")
    
  • ruby:

    ruby $LOAD_PATH << VIM::evaluate("var")
    <...>
    ruby $LOAD_PATH.delete(VIM::evaluate("var"))
    
  • tcl:

    silent tcl lappend auto_path [::vim::expr "dir"]
    <...>
    silent tcl set auto_path
                \ [lreplace $auto_path
                \ {*}[lrepeat 2
                \ [lsearch -exact $auto_path
                \ [::vim::expr "a:fdict.imported"]]]]
    
Asumu Takikawa
  • 8,447
  • 1
  • 28
  • 43
ZyX
  • 52,536
  • 7
  • 114
  • 135

1 Answers1

2

That depends on what you want to do with your script. Racket (it hasn't been called "mzscheme" for a long time now) works with modules, so you rarely use the "add a path to a dynamic load path" kind of workflow. Instead, modules are imported using the require form from either the core collection of libraries or from packages you've installed.

If you really need to load things dynamically, one option is to set the current-directory parameter and then use dynamic-require.

(require (prefix-in vim- vimext))
(parameterize ([current-directory (vim-eval "var")])
  (define add (dynamic-require "add.rkt" 'add)))

The dynamic-require will pull out the add function from the add.rkt file in the supplied directory. Note: I haven't tested this code since I can't find a version of vim that has Racket support compiled in.

You can find the documentation for the vim interface in Racket here. General documentation for Racket here.

Asumu Takikawa
  • 8,447
  • 1
  • 28
  • 43
  • Packages you have installed how? What I need is to make frawor users able to add directory to theirs plugins that will be taken as module import path without requiring them to add this path by themselves. I’ve never seen lua, tcl or racket/mzscheme requiring plugins, thus code for them is only for completeness. Could you say what a typical racket user will do when he wants to have his racket source code utilizing vim interface to be contained in a separate file with only a few functions called from the mappings/commands? – ZyX Jul 25 '12 at 04:21
  • If you need to require functions from another file (that's in the same directory), you can just refer to it by name. Like `(require "foo.rkt")`. This works for any relative path. If you're not guaranteed to have a fixed relative path to the file, then you might need to use `dynamic-require`. – Asumu Takikawa Jul 25 '12 at 14:07
  • Thanks, that means I do not need to do anything in frawor. – ZyX Jul 25 '12 at 14:51