lisp

Lisp, instructions not working in defun [duplicate]

大兔子大兔子 提交于 2019-12-17 05:15:33
问题 This question already has answers here : Common lisp error: “should be lambda expression” (4 answers) Closed 2 years ago . I'm trying to make a function that changes infix input to prefix eg : (x + 1) as input outputted as (+ x 1) . So here is my code for the moment : (setq x '(Y + 1)) (if (listp x ) (list (second x) (first x) (first (last x))) x) so it returns (+ Y 1) if I input a list and the user input if it's not a list. However, the problem is that I can't get this code working in a

Common lisp error: “should be lambda expression”

狂风中的少年 提交于 2019-12-17 04:07:50
问题 I just started learning Common Lisp a few days ago, and I'm trying to build a function that inserts a number into a tree. I'm getting an error, *** - SYSTEM::%EXPAND-FORM: (CONS NIL LST) should be a lambda expression From googling around, it seems like this happens when you have too many sets of parenthesis, but after looking at this for an hour or so and changing things around, I can't figure out where I could be doing this. This is the code where it's happening: (defun insert (lst probe)

lisp-列表

*爱你&永不变心* 提交于 2019-12-14 05:40:44
cons (cons 1 nil) 列表可以当作是链表,其中的每个节点 node 包含了两个指针 car :节点的值 cdr :下一个节点 cons 的操作,可以理解为在一个链表的基础上,前插一个值。 (cons 1 nil); (1); value: 1, next: nil (cons 1 '(2 3 4)); (1 2 3 4); value: 1, next: (2 3 4) (cons '(1) '(2 3 4)); ((1) 2 3 4); value: (1), next: (2 3 4) 也就是说, cons 的第一个元素是 head 的值,然后指向后续的链表。 (consp '(1 2 3));T (consp nil); NIL 检查一个数据是否是这种链表类型,与之相反的是 (atom '(1 2 3)); NIL (atom nil); T equal (eql 'a 'a); T (eql '(a) '(a)); NIL 前面使用的 eql 有一定的局限性: 对于基本值来说,它的判断没有问题 对于基本元素的集合,它并不判断两个元素列表是否相同 也就是说,它是判断内存地址是否相等,而不是判断属性是否相等。 operation function eql addr_1 == addr_2 equal values_1 == values_2 用 java 进行区分

Undefined function error in LISP

孤街醉人 提交于 2019-12-14 04:23:57
问题 I am working on a Lisp program that contains code to read in the dimensions of boxes and then sort them from shortest to longest lengths (and set each of these new lengths as new variables). When I attempt to load my file into the interpreter, I get the following error: *** - EVAL: undefined function NEW-D1 I am confused as to why I'd be getting this error because new-d1 isn't a function, it's a variable for the length of the shortest edge of a given box. Here's the code where new-d1 is first

Convert fractions from decimal to binary

烈酒焚心 提交于 2019-12-14 04:13:11
问题 I want to convert the number 8.7 to binary. I know the commands (format nil "~b" (rationalize 8.7)) ===> 1010111/1010 or (format nil "~b" (/ 87 10))====> 1010111/1010 We observe if we do the quotient binary 1010111/1010 we obtain 1000.1011001100110011001100110011. Is possible to obtain in Lisp (8.7)_2 ~ 1000.1011001100110011001100110011? If yes, how? 回答1: "2.718..." is equal to 2 * 10^1 + 7 * 10^-1 + 1 * 10^-2 + 8 * 10^-3 ... This means that you can generate the string by the reverse process

How can I filter null values from this list?

你离开我真会死。 提交于 2019-12-14 03:23:21
问题 I have the following procedure for creating all prime-pairs in a list: (define (prime-pairs lst) (define (split lst pos) (list (drop-right lst pos) (take-right lst pos))) (define (prime-pairs-iter n acc) (cond ((= n 0) (filter (lambda (e) (not (null? e))) acc)) (else (prime-pairs-iter (- n 1) (let ((s (split lst n))) (if (and (prime? (list->number (car s))) (prime? (list->number (cadr s)))) (append s acc) acc)))))) (prime-pairs-iter (- (length lst) 1) '())) (Full code: https://gist.github.com

How to have ball collide with bricks in Breakout (racket)

◇◆丶佛笑我妖孽 提交于 2019-12-14 02:59:55
问题 I've been trying to get Breakout to work in Racket, so far the ball bounces from the paddle (paddle is controlled by mouse) and the bricks are present Here is the full on code: (require 2htdp/image) (require 2htdp/universe) (define WIDTH 400) (define HEIGHT 400) (define BALL-RADIUS 10) (define BALL-IMG (circle BALL-RADIUS "solid" "red")) (define REC-WIDTH 50) (define REC-HEIGHT 10) (define REC-IMG (rectangle REC-WIDTH REC-HEIGHT "solid" "grey")) (define BRICK-IMG0 (rectangle 60 30 "solid"

ASDF output redirection

血红的双手。 提交于 2019-12-14 02:38:53
问题 I would like to set directory where ASDF stores compiled files. I prefer to do it from a shell script. According to this page, one should define environment variable ASDF_OUTPUT_TRANSLATIONS . OK, here it is: $ export ASDF_OUTPUT_TRANSLATIONS="$HOME/.cache/common-lisp/my-dir/" But when I try to test the configuration, it does not work: $ clisp -x "(asdf:compile-system :my-system)" Output: ;; Loading file /home/mark/.clisprc.lisp ... ;; Loading file /home/mark/quicklisp/setup.lisp ... *** -

Sudoku table generator failure, lisp

别说谁变了你拦得住时间么 提交于 2019-12-14 02:18:07
问题 I have a problem with some part of my lisp code. It is a sudoku table generator. It works fine until this part: (loop for e in entries do (if (and (not (member e sub)) (not (member e col))) (progn (setq choices (nconc choices (list e))) (print choices))) (if (= (length choices) 1) (setq pick (car choices)) (if (not (= (length choices) 0)) (setq pick (nth (random (+ 0 (length choices))) choices)))) Basically, I am on a row x and a column y, and I need to insert an element. I watch the

Deep-reverse for trees in Scheme (Lisp)

五迷三道 提交于 2019-12-14 01:12:08
问题 I have a deep reverse for a basic tree data structure in Scheme (define (deep-reverse t) (cond ((null? t) '()) ((not (pair? t)) t) (else (cons (deep-reverse (cdr t)) (deep-reverse (car t)))))) (define stree (cons (list 1 2) (list 3 4))) 1 ]=> (deep-reverse stree) ;Value: (((() . 4) . 3) (() . 2) . 1) I feel like a cleaner, better result would be: (4 3 (2 1)) Can anyone provide some guidance as to where I'm going wrong in my deep-reverse function? Thank you. 回答1: It's better to split the task