我正在编写一个函数,try-weak-cues用于从大量响应中选择响应.该程序本质上是与用户的对话.
(define try-weak-cues
(lambda (sentence context)
(define helper
(lambda(list-of-pairs)
(define helper2
(lambda(list-of-pairs context)
(cond((null? list-of-pairs)
(cond((null? list-of-pairs) '())
((any-good-fragments?(cue-part(car list-of-pairs))sentence) (helper2(cdr(car list-of-pairs))context))
(else(helper(cdr list-of-pairs)))))))))
(helper *weak-cues*))))
Run Code Online (Sandbox Code Playgroud)
下面是该函数应该从中获取的响应列表:
(define *weak-cues*
'( ( ((who) (whos) (who is))
((first-base)
((thats right) (exactly) (you got it)
(right on) (now youve got it)))
((second-base third-base)
((no whos on first) (whos on first) (first base))) )
( ((what) (whats) (what is))
((first-base third-base)
((hes on second) (i told you whats on second)))
((second-base)
((right) …Run Code Online (Sandbox Code Playgroud) 我试图找出如何从另一个列表中获取最后一个(非空)列表,或者nil如果没有这样的列表(递归)则返回.这是一个家庭作业,因此我正在寻找方法的帮助,不一定是它的代码.例:
(lastele '(1 (2 3) 4 5)) ;=> (2 3)
(lastele '(1 (2 3) (4 5)) ;=> (4 5)
(lastele '(1 2 3 4 5)) ;=> NIL
Run Code Online (Sandbox Code Playgroud)
我试图浏览列表,如果我遇到一个子列表,我会检查列表的其余部分是否包含更多的非空子列表,如果是,则继续将列表设置为该列表,并重复直到我们有一个空列表.
(defun lastele2 (L)
(if (null L)
'()
(if (hasMoreLists (rest L))
(lastele2 (rest L))
(first L))))
Run Code Online (Sandbox Code Playgroud)
但是,似乎我无法hasMoreLists上班.返回t或f内部只是错误.这是解决这个问题的最好方法吗?
以下函数是尾递归的吗?如果没有,我可以做些什么来修改它?
(define (euclids-alg n1 n2)
(cond((= n1 0) n2)
((= n2 0) n1)
((= n1 n2) n1)
((> n1 n2) (euclids-alg (- n1 n2) n2))
((< n1 n2) (euclids-alg n1 (- n2 n1)))))
Run Code Online (Sandbox Code Playgroud) 这比标题所暗示的要复杂得多,但我无法将其浓缩为一句话.
我正在使用Clisp,目前有一个列表列表.外部列表是任意长的,而内部列表是4个整数长.这是我可能拥有的一个例子.
((2 1 1 0) (1 1 0 0) (1 0 0 1) (1 1 0 0) (1 0 1 0) (1 0 0 0))
Run Code Online (Sandbox Code Playgroud)
现在每个内部列表由2个部分组成,第一个项目是"乘数".最后3项只是列表中的值.因此在某种意义上,(10 1 1 0)与(5 1 1 0)(5 1 1 0)相同.
我需要一个可以压缩此列表的函数,这样就没有2个列表包含相同的最后3个项目.但是每个唯一的最后3个项目只有一个列表,第一个空格中的值是这个列表的"多少".如果这是有道理的......
所以这
((2 1 1 0) (1 1 0 0) (1 0 0 1) (1 1 0 0) (1 0 1 0) (1 0 0 0))
; ^ ^
Run Code Online (Sandbox Code Playgroud)
会成为这个
((2 1 1 0) (2 1 0 0) (1 0 0 1) (1 0 …Run Code Online (Sandbox Code Playgroud) 我必须对奇数位置上的奇数元素求和.这不起作用.谁能告诉我我的错误在哪里?谢谢
(defun sum (list)
(cond
((null list) 0)
((= (mod 2 (car list)) 0) (sum (cddr list)))
(T (+ (car list) (sum (cddr list))))))
Run Code Online (Sandbox Code Playgroud) 我正在使用一个函数d来生成随机数,我将其收集在列表中,然后对它们求平均值:
(/ (apply #'+ (list (d 6) (d 6) (d 6) (d 6) (d 6) (d 6))) 6.0)
Run Code Online (Sandbox Code Playgroud)
我想运行函数(d n) i次数,将返回的值一起添加,然后除以i.dotimes不返回值.我将如何在Common Lisp中执行此操作?
我不明白以下SPARQL查询生成的输出:
select distinct ?Concept
where {
<http://dbpedia.org/resource/Blink-182> a ?Concept
}
LIMIT 100
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下"概念"在DBPedia中的含义,以及此查询结果的含义是什么?它与rdf:type有什么联系吗?
我尝试常见的lisp hunchentoot-test.
当我上传带有非拉丁符号的utf-8文本文件时,上传文件的长度增加了.在完成文件中,插入了每个非拉丁符号的附加字节.我不明白为什么.最近的实验是刚刚在digitalocean上启动ubuntu系统.安装emacs,clisp和slime.在swank执行:
(ql:quickload"hunchentoot")
(ql:quickload"hunchentoot-test")
(hunchentoot:start(make-instance'hunchentoot:easy-acceptor:port 4242))
在127.0.0.1:4242/hunchentoot/test/upload.html上查看问题就足够了
我一直在尝试将线性列表转换为集合,但无济于事。每次运行此命令时,都会出现一些奇怪的编译错误,例如“格式错误的lambda”,它指出了我使用append的方式。这是我的代码:
(defun mem(e l)
(cond
((null l) nil)
((equal e (car l)) t)
((listp (car l)) (mem e (car l)))
(t(mem e (cdr l)))
)
)
(defun st(l k)
(cond
((null l) nil)
(( mem '(car l) 'k) (st (cdr l) k))
((listp (car l)) (st (car l) k))
( t (st (cdr l) (append((car l) k)) ))
(t(mem e (cdr l)))
)
)
Run Code Online (Sandbox Code Playgroud)
编辑:坦率地说,我只想从列表中删除重复项