标签: lisp

LISP中的动态构建功能

我有一个关于动态构建的函数(或类似的东西)的问题.在Java中,我可以以编程方式将一些Source写入一个String,编译该字符串并像函数一样多次执行它.

想象一下,我有一些遗传算法来创建最佳代码来获取n个输入参数,根据基因组计算它们并返回m个输出参数.所以我想知道是否可能(并且我很确定它是),创建一个列表列表....包含该函数,然后使用不同的输入参数调用此函数几千次以计算错误率.

我现在需要的是一个例子,如何以编程方式创建这样的列表以及如何使用它.目前我完全陷入困境.

任何参考或例子都受到热烈欢迎.

lisp metaprogramming common-lisp

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

将列表作为函数参数传递并从函数返回列表

我有以下代码:

(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).我究竟做错了什么?

lisp list common-lisp

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

如何在Common Lisp中将字符串转换为列表

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

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

如果声明带有then子句(LISP)

所以我正在尝试自学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的新手!

lisp if-statement

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

在Lisp中获取多括号列表的第一个元素

如果我有一个如下列表:

(((X)))
Run Code Online (Sandbox Code Playgroud)

我想得到正确X而不是得到括号

在LISP中,如果我这样做CAR,我仍然会得到括号.

有什么功能可以帮我吗?

lisp list common-lisp

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

字符串列表上的lisp成员函数

我正在使用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)

lisp

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

在lisp中的第一次搜索下进行前向链接

我试图找到问题,在堆栈溢出流量问题上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)

lisp stack-overflow common-lisp

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

LISP使用负数作为指数

我一直在努力解决以下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 common-lisp

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

使用Lisp:定义一个获取列表和数字的函数,如果列表中出现数字,则返回true

我是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而不是执行功能,我对我做错了很困惑.

lisp common-lisp

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

Breadth first search in LISP

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. Traversing root node (1)
  2. Traversing depth 1 (1 2) (1 3) (2 1) (3 1) (3 1) (3 2)
  3. Traversing depth 2 (1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 …

lisp common-lisp

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