ラベル OpenLisp の投稿を表示しています。 すべての投稿を表示
ラベル OpenLisp の投稿を表示しています。 すべての投稿を表示

2008年10月14日火曜日

OpenLispでlet変数がstack-overflowする件

OpenLispでletで作った変数がstack-overflowしちゃいます。

↓stack-overflowする例


(defun testmem (a b)
(let ((aa a) (bb b))
(setq aa (+ aa 1))
(if (= aa 100)
(progn
(setq aa 0)
(setq bb (+ bb 1))))
(if (< bb 100)
(progn
(format (standard-output) " *** aa= ~S bb= ~S ~%" aa bb)
(testmem aa bb)))
))

(testmem 0 0)



↓stack-overflowしない例



(defun testmem (a b)
(setq a (+ a 1))
(if (= a 100)
(progn
(setq a 0)
(setq b (+ b 1))))
(if (< b 100)
(progn
(format (standard-output) " *** a= ~S b= ~S ~%" a b)
(testmem a b)))
)

(testmem 0 0)


違いは(let ((aa a) (bb b))があるかどうか、のみ。
前者は手元の環境(ver.8.8.0-win32-x86)では

前略
・
・
・
*** aa= 5 bb= 19
** eval : stack-overflow : nil
と終わります。


無駄なlet変数は使わないように > 自分

2008年7月14日月曜日

Open Lisp 超初心者用 コード集 01

;;Open Lisp です

;;ファイルへの書き出し(ファイルは上書きされる)
(with-open-output-file
    (outstream-test
    "T:/Lisp/test_code/test-output-file.txt")
    (format outstream-test "Hello file!~%")
    (format outstream-test "Hello line!~%")
    (format outstream-test "Hello strings!~%")
)

;;ちょっと調べたところでは、Lispでよく出てくる「with-open-file」は、存在しない模様…


;;ファイルを読む(ただし、この例だと初めの1行のみ読む)
(with-open-input-file
    (inputstream-test
    "T:/Lisp/test_code/test-input-file.txt")
    (read-line inputstream-test))


;;listの連結
;;(append list*) → <list> function
    ;;連結するlistはいくつでもいい
(defglobal aa nil)
(setf aa (append '(a b c) '(d e f)))
;;⇒ (a b c d e f)


;;文字列の連結
;;(string-append string*) → <string> function
    ;;連結する文字列はいくつでもいい
(string-append "abc" "def")
;;⇒ "abcdef"