Gauche:REPL

Gauche:REPL

Gaucheの対話環境について。

Replの改善

Gauche:Replの改善

yamasushi(2013/04/25 10:16:11 UTC) 本体のreplはそのままにして、xreplを改造してみました。

; xreplのrepl.scm
; 括弧を補完する
(define (paren-less)
  (let1 line (string-trim-both (read-line))
    ($ read-from-string $ format #f "(~a)" line)
  ) )

; 特別なヘルプ関数infojを呼ぶ
(define (invoke-info)
  (let1 line (string-trim-both (read-line))
    ($ read-from-string $ format #f "(infoj ~s)" line )
  ) )

; 変数・関数を定義する
(define (define-var)
  (let1 line (string-trim-both (read-line))
    ($ read-from-string $ format #f "(define ~a)" line )
  ) )
(define (reader)
  (case (peek-non-ws-char)
    [(#\,) (read-char) (read-toplevel-command) ]
    [(#\:) (read-char) (paren-less) ]
    [(#\?) (read-char) (invoke-info) ]
    [(#\=) (read-char) (define-var) ]
    [else => (^c (if (eof-object? c) c (read)))]))
gosh> = hoge 123
hoge
gosh> hoge
123
gosh> = (foo x y) (cons x y)
foo
gosh> :foo 123 456
(123 . 456)
gosh> 

初期状態にもどる機能について

rlwrap

その他

Tag: REPL

More ...