- 积分
- 6483
- 明经币
- 个
- 注册时间
- 2002-4-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2002-9-14 15:25:00
|
显示全部楼层
这回比较完善了: QF-list->string
测试:
_$ (qf-list->string '(1 a b (2 4 5) 'e "teststring" (3 4 (5))k))
"(1 A B (2 4 5 )(QUOTE E )\"teststring\" (3 4 (5 ))K )"
_$ (read (qf-list->string '(1 a b (2 4 5) 'e "teststring" (3 4 (5))k)))
(1 A B (2 4 5) (QUOTE E) "teststring" (3 4 (5)) K)
程序:
(defun QF-list->string (lst / atom->string)
(defun atom->string (a)
(cond ((= (type a) 'Str) (strcat "\"" a "\""))
((= (type a) 'Int) (itoa a))
((= (type a) 'real) (rtos a))
((= a 'QUOTE) "QUOTE")
((= (type a) 'sym) (SymToStr a))
(T "")
)
)
(strcat "("
(apply 'strcat
(mapcar '(lambda (x)
(if (= (type x) 'list)
(QF-list->string x)
(strcat (atom->string x) " ")
)
)
lst
)
)
")"
)
)
(defun SymToStr (SymbolName)
;; If the argument is a symbol ...
(if (= (type SymbolName) 'SYM)
(progn ;; Execute the function we are going to create ...
(;; Create a function on the fly
(list ;; The argument and local variable list. Note
;; that SymbolName will be evaluated, so the
;; symbol name that we're trying to convert
;; will be a local variable.
(list '/ SymbolName)
;; Set the local variable to 0 to make sure it
;; appears in the atoms-family (variables that
;; are "bound to NIL", explicitly or implicitly,
;; do not appear in the atoms-family)
(list set (quote SymbolName) 0)
;; In "native "AutoLISP", the symbol would
;; now be the first one in the atoms-family
;; list. Not so in Visual LISP. So we have
;; to look up the symbol [as a symbol] using
;; (member ...), compute its position in the
;; list, and then extract it from the string
;; version of the atoms-family list. This
;; also sets up the return value.
(list nth
(list -
(list length (list atoms-family 0))
(list length
(list member
(list (quote quote) SymbolName)
(list atoms-family 0)
) ;_ end list
) ;_ end list
) ;_ end list
(list atoms-family 1)
) ;_ end list
;; End of the dynamic function
) ;_ end list
)
) ;_ end progn
;; If the argument is not a symbol, return NIL
nil
) ;_ end if
) ;_ end defun |
|