How to start REPL for slimv with MIT-Scheme
Asked Answered
A

1

20

My operating system is Debian Squeeze. Here's the vim version:

VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 12 2010 02:29:33)

I read a tutorial on http://kovisoft.bitbucket.org/tutorial.html and tried to start REPL for MIT-Scheme. Unfortunately, I failed to start.

When I pressed ",c", it started a terminal window loading mit-scheme. Nothing showed in the REPL buffer of vim. Some errors showed in the terminal:

Listening on port: 4005
;netcat: "4005: inverse host lookup failed: Unknown host"
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

2 error> 

I read the source code and fixed some bugs (about the parameters of netcat and something else), here's the diff file:

*** /home/gaussfrank/slimv/slime/contrib/swank-mit-scheme.scm   2012-02-02 16:41:58.357463955 +0800
--- swank-mit-scheme.scm    2012-02-06 22:30:42.929212874 +0800
***************
*** 113,126 ****

  (define (netcat port)
    (let* ((sh (os/shell-file-name))
!    (cmd (format #f "exec netcat -v -q 0 -l ~a 2>&1" port))
     (netcat (start-pipe-subprocess sh 
                    (vector sh "-c" cmd)
                    scheme-subprocess-environment)))
      (list netcat port)))

  (define (netcat-accept nc)
!   (let* ((rx "^Connection from .+ port .+ accepted$")
     (line (read-line (subprocess-input-port nc)))
     (match (re-string-match rx line)))
      (cond ((not match) (error "netcat:" line))
--- 113,126 ----

  (define (netcat port)
    (let* ((sh (os/shell-file-name))
!    (cmd (format #f "exec netcat -v -q 0 -l -p ~a 2>&1" port))
     (netcat (start-pipe-subprocess sh 
                    (vector sh "-c" cmd)
                    scheme-subprocess-environment)))
      (list netcat port)))

  (define (netcat-accept nc)
!   (let* ((rx "^listening on.*")
     (line (read-line (subprocess-input-port nc)))
     (match (re-string-match rx line)))
      (cond ((not match) (error "netcat:" line))

I retried, but some new problems happened.

;The object #f, passed as the second argument to integer-add, is not the correct type.
;To continue, call RESTART with an option number:
; (RESTART 4) => Specify an argument to use in its place.
; (RESTART 3) => Return to SLIME top-level.
; (RESTART 2) => Close connection.
; (RESTART 1) => Return to read-eval-print level 1.

Here's the log file (swank.log)

[---Sent---] 0.21
(:emacs-rex (swank:connection-info) nil t 1)

[---Sent---] 16.11
(:emacs-rex (swank:swank-require 'swank-fuzzy) nil t 2)

Here's the packet:

8   0.739991    127.0.0.1   127.0.0.1   TCP 50732 > pxc-pin [PSH, ACK] Seq=1 Ack=1 Win=32792 Len=51 TSV=1451459 TSER=1451459
0000   00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00  ..............E.
0010   00 67 91 53 40 00 40 06 ab 3b 7f 00 00 01 7f 00  .g.S@.@..;......
0020   00 01 c6 2c 0f a5 f9 57 b4 93 fc 40 7f 85 80 18  ...,...W...@....
0030   10 03 fe 5b 00 00 01 01 08 0a 00 16 25 c3 00 16  ...[........%...
0040   25 c3 30 30 30 30 32 64 28 3a 65 6d 61 63 73 2d  %.00002d(:emacs-
0050   72 65 78 20 28 73 77 61 6e 6b 3a 63 6f 6e 6e 65  rex (swank:conne
0060   63 74 69 6f 6e 2d 69 6e 66 6f 29 20 6e 69 6c 20  ction-info) nil 
0070   74 20 31 29 0a                                   t 1).

9   0.740009    127.0.0.1   127.0.0.1   TCP pxc-pin > 50732 [ACK] Seq=1 Ack=52 Win=32768 Len=0 TSV=1451459 TSER=1451459
0000   00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00  ..............E.
0010   00 34 5a 46 40 00 40 06 e2 7b 7f 00 00 01 7f 00  .4ZF@.@..{......
0020   00 01 0f a5 c6 2c fc 40 7f 85 f9 57 b4 c6 80 10  .....,[email protected]....
0030   10 00 fe 28 00 00 01 01 08 0a 00 16 25 c3 00 16  ...(........%...
0040   25 c3                                            %.
Arroyo answered 5/2, 2012 at 4:30 Comment(10)
Slimv can also connect to a running swank server, so I suggest you try to start the scheme swank server manually. This way you can check whether the problem is on swank side or slimv side. If you are able to run the swank server, then slimv should connect to it upon pressing ,c. As I see "2 error" is printed, but do you know what exactly the errors are?Dong
;netcat: "listening on [any] 4005 ..." is an error. I read the source code and found that.Arroyo
@Tamas Kovacs: I found it was a bug on swank-mit-scheme.scm. Here's the buggy code: (cond ((not match) (error "netcat:" line)) (else (subprocess-input-port nc))) It uses the out-of-date output of netcat in Debian. Commenting it, writing a new code made it better. But when I pressed ",c", there were also bugs happening in the line (sum 0 (+ (* sum 16) (char->hex-digit (read-char in))))) which made (integer-add 192 #f).Arroyo
both procedure (netcat-accept nc) and (read-length in) are buggyArroyo
Try to add this in your .vimrc: let g:swank_log=1. This makes slimv create a log file of the communication between slimv and the swank server. Please send the log file to me (I'm the author of slimv) for analysis. The bug you described (in function read-length) shows that there's a problem in decoding the message length. You know, swank messages contain the message length in 6 hex digits, then comes the message itself.Dong
@TamasKovacs I'll edit my post.Arroyo
From swank.log: after connecting the socket slimv sends the swank:connection-info message (00002d(:emacs-rex (swank:connection-info) nil t 1)) but the swank server does not respond. It would be nice to have a TCP trace, whether the swank server received the message or not and whether it sent a response or not.Dong
I think one of the best tools for tracing TCP/IP traffic is wireshark, but you can use tcpdump as well.Dong
@TamasKovacs I'll edit my post again.Arroyo
For me the TCP packet slimv sent to the swank server looks OK: the first 6 bytes are 00002d which is the message length. However, when the swank server tries to decode the message length (in function read-length) it gets #f returned by char->hex-digit, so one of the 6 bytes are not identified as a hex digit. Sorry, but I can't explain why, this is out of my competence. My last tip is to add some kind of debug logging to char->hex-digit to see what characters are actually read: maybe it's nothing just the EOF and no chars are actually passed to the swank server at all by netcat(?).Dong
D
4

This is a known problem. I have a patched version of Slimv in my git repo which fixes this issue and quite a few others.

Note that it's quite a while ago that I used Slimv, so I can't recall from the top of my head what the exact changes are I made. I only tested this on OS X, so YMMV.

Dieppe answered 16/2, 2013 at 13:16 Comment(4)
I left away from Lisp long ago. I remember I've solved that problem. Rigorously, it's a compatibility issue, since the different versions of netcat have different behaviors. It's supposed that netcat is bsd version.Arroyo
@SunQingyao I recently updated my vimrc and removed a ton of old plugins which I didn't use anymore. I don't think I still have a copy of my patched slimv lying around, sorry. Is this still an issue with the latest version of slimv? github.com/kovisoft/slimvDieppe
@SunQingyao I found an old copy of the code on my Windows partition. Uploaded it to a new repo and updated the link.Dieppe
@Dieppe I was having some problems when installing slimv on my macbook air, and now it turns to be my fault, not slimv's. Thank you anyway for the updated link :)Pugnacious

© 2022 - 2024 — McMap. All rights reserved.