2

In order to debug MIT-Scheme scripts with Vim, I want to be able to run the script file currently being edited as conveniently as possible. Here is what I'm doing:

sicp.scm

(set! load-noisily? #t)

(define
    (abs x)
    (cond
        ((> x 0) x)
        ((= x 0) 0)
        ((< x 0) (- x))
    )
)

(abs 42)
(abs -24)

(exit)

After executing :!mit-scheme --eval "(load \"sicp\")" when editing sicp.scm in Vim, I get:

Image saved on Saturday May 17, 2014 at 2:39:25 AM
  Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118
  Edwin 3.116
;Loading "sicp.scm"...

Kill Scheme (y or n)? 

There are two main issues:

  1. The results of both (abs 42) and (abs -24) are not printed, despite the fact that I've already set load-noisily? to #t.
  2. I don't want to enter y manually to kill scheme each time the script is run. It should exit automatically, since there is an (exit) line in the end.

Here is the expected output:

Image saved on Saturday May 17, 2014 at 2:39:25 AM
  Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118
  Edwin 3.116
;Loading "sicp.scm"... done
;Value: 42
;Value: 24

Moriturus te saluto.

How can I do this?

nalzok
  • 14,965
  • 21
  • 72
  • 139

2 Answers2

2

I'm not sure that this one qualifies as a full answer, but this is how to do it in vim+slimv:

  1. Keep only your (define ...) in sicp.scm, remove everything else from the file.
  2. Open sicp.scm in vim and press ,c to start/connect the swank server. This also opens a REPL window.
  3. Place the cursor somewhere into the (define ...) form and press ,d to define your function in the REPL.
  4. Go to the REPL window and type your test expression (e.g. (abs 42)) in insert mode then press ENTER, this will evaluate the test expression and display the result in the REPL window.
  5. You can also evaluate s-expressions from your source window via ,d. Please note that when evaluating multiple s-expressions in one single step (e.g. evaluating a visual selection via ,r) then only the result of the last s-expression is displayed in the REPL window.
  6. In case an error happens then slimv opens the debugger window, displays the backtrace and the possible restarts.
Tamas Kovacs
  • 1,495
  • 7
  • 9
  • Where can I find a full list of the usages and key bindings for all Slimv menu items? Your [tutorial](http://kovisoft.bitbucket.org/tutorial.html#startup) recommends gvim users to `set guioptions+=m`, but I'm not using gvim... – nalzok Nov 16 '16 at 14:00
  • 1
    Check the keyboard mappings in the documentation. If you compiled the help file (`:helptags ~/.vim/doc`) then you can invoke it from within vim: `:help slimv-keyboard`. You can find additional information about the swank functions (like using the SLDB debugger) here: `:help slimv-swank`. And the help on using the REPL is here: `:help slimv-repl`. Don't worry about the `guioptions`, if you use the character mode vim then you can bring up the slimv menu by pressing `,,`. – Tamas Kovacs Nov 16 '16 at 14:14
1

OK - I've never used Vim, and haven't used Scheme since 1992 - so I'm guessing here.

Setting load-noisily? inside the file being loaded is probably too late (because load has already decided not to be noisy before it even opens the file). You probably need to set it before calling load. Try removing it from the file and using :!mit-scheme --eval "(begin (set! load-noisily? #t) (load \"sicp\"))"

As far as (exit) is concerned, I have no idea, but...

I've also never used slimv (or here), but it is apparently the Vim equivalent of Slime, which I have used. Slime turns emacs into a wonderful Lisp IDE, and will hopefully do the same for Scheme and Vim.

Allison Lock
  • 2,375
  • 15
  • 17
  • The correct command should be `:!mit-scheme --eval "(begin (set\! load-noisily? \#t) (load \"sicp\"))"`(escaping `!` and `#`). However, unfortunately, it doesn't work :( – nalzok Nov 09 '16 at 16:07
  • @Sun, that's unfortunate. Looks like you'll need to explicitly `display` the expressions then. You might consider defining a macro so that e.g. `(dump (abs -42))` will display `(abs -42) => 42` instead of just `42`. (You could extend that so that `(dump (abs 42) (abs -42) ...)` would display multiple lines of output. – Allison Lock Nov 11 '16 at 08:04
  • 1
    However, I still recommend checking out slimv as a far more convenient way of doing this. Having a working REPL in your editor makes a world of difference. – Allison Lock Nov 11 '16 at 08:05