输出函数问题
我想写一个可以直接运行或者将运行代码输出成文件的代码,本地运行正常,谁知输出文件时出状况,理想目的时文件输出内容为"(abc5 )",我一口老血喷出,如果真要实现只要预设一下就可以,但是对于# 有没有好一点的方法。源码如下:
(defun abc (a< nn)
(if (a< 3 nn)
(alert "oK")
)
)
(defun test (tn / fi file ls01 path_name)
(setq ls01 (list abc < 5))
(if tn
(eval ls01) ;本地运行模式
(progn ;输出运行文件
(setq path_name "c:\\1.txt")
(if (open path_name "r")
(princ "该文件已经存在")
(progn (setq file (open path_name "w"))
(close file)
) ;_ 结束progn
)
(if (findfile path_name)
(progn
(setq fi (open path_name "w"))
(princ "(" fi)
(foreach ii ls01
(princ ii fi)
(princ " " fi)
)
(princ ")" fi)
(close fi)
)
(princ)
)
)
)
)
(defun c:tt ()
(test nil)
) vl-princ-to-string
vl-prin1-to-string
同样输出为#,想输出成 abc
vl-princ-to-string用这个剪裁一下文本也能实现
判断一下,如果是函数,用vl-symbol-name获取它的名字字符串(vl-symbol-name 'princ)
(setq ls01 (list abc < 5))
改成(setq ls01 '(abc < 5))
输出的地方 直接 (princ (VL-PRIN1-TO-STRING ls01) fi)就完事了(defun abc (a< nn)
(if (a< 3 nn)
(alert "oK")
)
)
(defun test (tn / fi file ls01 path_name)
(setq ls01 '(abc < 5))
(if tn(eval ls01);±¾μØÔËDDÄ£ê½
(progn;êä3öÔËDDÎļt
(setq file (open "c:\\1.txt" "w"))
(princ(VL-PRIN1-TO-STRING ls01)file)
(close file)))
)
(defun c:tt(/ file ls01)
(test nil)
(setq file(open "c:\\1.txt" "r"))
(setq ls01(read(read-line file)))
(close file)
(eval ls01)
)
感谢,对 ' 的认知双多了
这么偏门又不实用的技能你也会666,用 ' 坏处就是函数变固定了不能自定义
页:
[1]