SBCL 從REPL 中提取lisp代碼

1, 在emacs C-x C-W 文件另存爲保存全部REPL過程bash

因爲 (load "foo.lisp")時只有定義語句能夠正確執行, 執行語句不可正確被 (load "foo.lisp")解析執行函數

因此腳本寫成了這個樣子, 腳本名 parse_lisp_code.shcode

#!/bin/bash
if [ -n "$1" ]; then
   sed 's/CL-USER>//' $1 | expand -t 8 | egrep '^ *\(def|^ {8,}' >> "code_${1}"
else
   echo "please input lisp file name"
fi

orm

運行腳本 sh parse_lisp_code.sh cd.lispinput

命令解釋:emacs

使用sed 刪除提示符 CL-USERform

lisp定義語句以(def 開頭 或是 製表符開頭, 以下sed

CL-USER> (defun dump-db ()$
^I   (dolist (cd *db*)$
^I     (format t "~{~a: ~10t~a~%~}~%" cd)))$file

 因此使用grep 過濾出每行開始n個空格後加(def或製表符的行, grep

可是發現grep 不能匹配製表符,

因此使用 expand -t 8 foo > bar 把製表符轉化成8個空格

 

 

P.S. 定義出錯的函數也會被提取出來

相關文章
相關標籤/搜索