我有一个关于动态构建的函数(或类似的东西)的问题.在Java中,我可以以编程方式将一些Source写入一个String,编译该字符串并像函数一样多次执行它.
想象一下,我有一些遗传算法来创建最佳代码来获取n个输入参数,根据基因组计算它们并返回m个输出参数.所以我想知道是否可能(并且我很确定它是),创建一个列表列表....包含该函数,然后使用不同的输入参数调用此函数几千次以计算错误率.
我现在需要的是一个例子,如何以编程方式创建这样的列表以及如何使用它.目前我完全陷入困境.
任何参考或例子都受到热烈欢迎.
我有以下代码:
(defun read_coords (in)
(setq x (read-line))
(if (equalp x "0")
in
(progn
(append in (cons x nil))
(read_coords in)
)
)
)
(setq coords (read_coords (cons nil nil)))
Run Code Online (Sandbox Code Playgroud)
目标是读取输入行并将它们存储在列表中.问题是列表coords
保持不变(因此仅包含NIL
).我究竟做错了什么?
Just like
Run Code Online (Sandbox Code Playgroud)
字符串是
> "((1 0)(0 1))"
required
>((1 0)(0 1))
Run Code Online (Sandbox Code Playgroud)
我也在使用实习函数,但它以((1 \ 0)(0 \ 1))的形式返回
所以我正在尝试自学lisp,我目前正在使用这个网站作为参考:https://www.tutorialspoint.com/lisp/lisp_if_construct.htm
我不太明白为什么执行then子句,尽管if子句是假的?
(setq a 10)
(if (> a 20)
then (format t "~% a is less than 20"))
(format t "~% value of a is ~d " a)
Run Code Online (Sandbox Code Playgroud)
输出是:
a is less than 20
value of a is 10
Run Code Online (Sandbox Code Playgroud)
即使if语句为false,then子句是否总是执行?(在这种情况下是).
任何帮助将不胜感激,也很抱歉,如果我的术语完全不正确我仍然是Lisp的新手!
如果我有一个如下列表:
(((X)))
Run Code Online (Sandbox Code Playgroud)
我想得到正确X
而不是得到括号
在LISP中,如果我这样做CAR
,我仍然会得到括号.
有什么功能可以帮我吗?
我正在使用LISP,并想知道如何访问字符串列表中的成员.我已经尝试了成员函数,但一直都是NIL.谢谢
(setq phrase-list '( "What color is the sky?" "It is Blue.")) ;list of strings
(write phrase-list)
(terpri)
(setq x(read-line)) ; I try to input What color is the sky?
(write(member x phrase-list)) ; I keep getting NIL
Run Code Online (Sandbox Code Playgroud) 我试图找到问题,在堆栈溢出流量问题上alogrithm是明确的但它和递归调用是在一个if satetment所以我无法弄清楚为什么它会变坏
(defparameter BF '(B C) )
(defparameter BR '((R1(B D E) F )(R2( D G) A )(R3(C F) A )(R4(C) D)
(R5(D ) E )(R6(A) H ) (R7(B ) X) (R8(X C) A ) ))
(defun chain_av (BF BR F)
(loop
(unless (member F BF)
(dolist (R BR)
(when (actionable R BF)
(remove R BR)
(append BF (conclusion-part R)))
(if (member F BF) (return "yes")
(or(chain_av BF BR F) (return nil)))))))
(defun conclusion-part( r)
(caddr r)
)
(write (chain_av …
Run Code Online (Sandbox Code Playgroud) 我一直在努力解决以下Common Lisp问题:
到目前为止我有这个:
(defun activation (type sum)
"(type sum)
Returns the activation value of a connectionist unit
given a sum of products of input activations x
corresponding connection weights."
(cond ((equal type 'sigmoid) (- (/ 1 (+ 1 (exp (- 0 sum)))) 0.5))
((equal type 'asigmoid) ((/ 1 (+ 1 (exp (- 0 sum))))))
(t 'unknown-type)))
Run Code Online (Sandbox Code Playgroud)
但我一直在exp函数附近得到错误"type-error"...有人可以帮我弄清楚出了什么问题吗?
我是lisp的新手,我有一个问题,我正在尝试在列表中找到该号码,但它无效.我还没有发表回复声明
(defun num (x 'y)
(if (member x '(y)) 't nil))
(write (num 10 '(5 10 15 20)))
Run Code Online (Sandbox Code Playgroud)
我的输出只输出nil
而不是执行功能,我对我做错了很困惑.
I have a representation of a tree using lists. For example:
(1 ((2 (3)) (3 (2)))) (2 ((1 (3)) (3 (1)))) (3 ((1 (2)) (2 (1)))))`
Run Code Online (Sandbox Code Playgroud)
Now I need to traverse it level by level while maintaining the hierarchy tree. For instance:
(1)
(1 2) (1 3) (2 1) (3 1) (3 1) (3 2)
(1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 …