小编Fre*_*d_2的帖子

FORMAT函数调用中的LISP错误

我写了这段代码来写一个文件:

(defun writefile (text filename)
  (with-open-file (stream filename :direction :output :if-exists :supersede
                   :if-does-not-exist :create)
    (format stream text)))
Run Code Online (Sandbox Code Playgroud)

但如果我执行,例如:

(writefile '(a b c) "foo.txt")
Run Code Online (Sandbox Code Playgroud)

收益:

错误:在对FORMAT的调用中:(ABC)不是类型(OR STRING FUNCTION).

为什么它会告诉我这个错误?

lisp common-lisp output

3
推荐指数
1
解决办法
123
查看次数

LISP意思是#符号

在我的Lisp代码中,我有函数(nfa-regex-compile),它创建了一个cons的列表,包含初始状态,转换和最终状态(表示自动机的节点),从作为参数给出的正则表达式开始.

在这种情况下,我把一个序列作为表达式,但我不明白为什么,如果我给出两个以上的符号,函数产生(##)而不是继续生成新的状态.

CL-USER 39 : 3 > (nfa-regex-compile '(seq a))

((INITIAL 0) ((DELTA 0 A 1) (FINAL 1)))


CL-USER 40 : 3 > (nfa-regex-compile '(seq a b))

((INITIAL 0) ((DELTA 0 A 1) ((DELTA 1 B 2) (FINAL 2))))


CL-USER 41 : 3 > (nfa-regex-compile '(seq a b c)) 

((INITIAL 0) ((DELTA 0 A 1) ((DELTA 1 B 2) (# #))))


CL-USER 42 : 3 > (nfa-regex-compile '(seq a b c d e f)) …
Run Code Online (Sandbox Code Playgroud)

lisp common-lisp

2
推荐指数
1
解决办法
94
查看次数

LISP参数绑定

我必须定义一个LISP函数,为参数分配另一个函数的结果,如下所示:

(defun assign-param (x)
  (defparameter param (generic-funct x)))
Run Code Online (Sandbox Code Playgroud)

assign-param的结果是PARAM在第一次调用时.如果我再做一次调用,函数assign-param会再次返回PARAM,但这样:

Warning: (DEFVAR PARAM) defined more than once in 
C:\Users\****\Desktop\****\****.lisp.
PARAM
Run Code Online (Sandbox Code Playgroud)

我尝试使用defvar而不是defparameter使用相同的结果.

有没有办法避免这个警告信息?

有没有办法自动生成其他参数(如果已存在)?(例如:如果param已经在内存中,则分配给param1,param2 ...)

lisp parameters binding common-lisp

2
推荐指数
1
解决办法
260
查看次数

LISP迭代到递归

我使用循环函数在LISP中写下了这个迭代代码:

(defun loadfile (filename)
  (with-open-file (stream filename)
    (loop for line = (read-line stream nil 'eof)
          until (eq line 'eof)
          collect line)))
    )
  )
Run Code Online (Sandbox Code Playgroud)

有没有办法以loop递归的方式重写它?

lisp iteration recursion common-lisp

2
推荐指数
2
解决办法
212
查看次数

LISP打破了函数执行

如果获得某个值,如何在LISP中中断函数执行?

例如,我有一个这样的主要功能:

(defun recognize-a (arg input)
    (if (equal (recognize-b arg input) '())
        T
      NIL
      ))
Run Code Online (Sandbox Code Playgroud)

我希望recognize-b在输入为空列表的情况下中断函数,而不将任何值传递给main函数:

(defun recognize-b (fa input)
  (if (equal input '())
      <<<WANTED BREAK>>>
     (<Else branch>)))
Run Code Online (Sandbox Code Playgroud)

lisp common-lisp break

1
推荐指数
1
解决办法
516
查看次数

标签 统计

common-lisp ×5

lisp ×5

binding ×1

break ×1

iteration ×1

output ×1

parameters ×1

recursion ×1