lispworks

Floating Point Precision Error

耗尽温柔 提交于 2020-01-03 13:15:08
问题 I am having problem with the LISP expression below. There is floating precision error while doing sum for floating point numbers. CL-USER> (+ -380 -158.27 -35.52) Actual: -573.79004 Expected: -573.79000 Please suggest me how can I achieve the expected result in LISP (I am using Lispworks). 回答1: Floats are not exact Floats represent a subset of mathematical reals with certain precision , they are not exact numbers. Round off errors are inevitable . The ANSI Common Lisp standard provides for 4(

shuffle list without duplicate number in Lisp

余生颓废 提交于 2019-12-31 05:13:48
问题 I have this function to create a list with initial element from the other question list with initial-element are start from 99 to 0 in Lisp (defun newList (&optional(n 100)) (loop for i from (- n 1) downto 0 collect i)) (defun board (newList &optional(n 10)) (cond ((null newList) nil) (t (cons (subseq newList 0 n) (board (subseq newList n) n))))) (defun show-board (board) (format T "~%") (mapcar (lambda (x) (format T " ~A ~%" x)) board) (format nil "") ) (show-board (board (newList))) (99 98

Lisp Illegal argument in functor position

泄露秘密 提交于 2019-12-12 06:51:46
问题 Hello can anyone help me out? (defun f(x) (LIST ((* 2 x) (* 3 x))) ) (f 1) I get this, Illegal argument in functor position: (* 2 X) in ((* 2 X) (* 3 X)) . 回答1: It should be: (defun f (x) (list (* 2 x) (* 3 x))) You have an extra set of parentheses around the arguments to list . When an expression is a list, the first thing is supposed to be the function to call, so ((* 2 x) (* 3 x)) is not a valid expression because (* 2 x) is not a function. 来源: https://stackoverflow.com/questions/23297834

find the position of an atom in list

天涯浪子 提交于 2019-12-11 15:51:49
问题 I have this board with atom T and I wanna get is position in list and sub-list (defun board () "position of T: i=0 e j=9" '( ;; 0 1 2 3 4 5 6 7 8 9 (96 25 54 89 21 8 36 14 41 T) ;; 0 (78 47 56 23 5 NIL 13 12 26 60) ;; 1 (0 27 17 83 34 93 74 52 45 80) ;; 2 (69 9 77 95 55 39 91 73 57 30) ;; 3 (24 15 22 86 1 11 68 79 76 72) ;; 4 (81 48 32 2 64 16 50 37 29 71) ;; 5 (99 51 6 18 53 28 7 63 10 88) ;; 6 (59 42 46 85 90 75 87 43 20 31) ;; 7 (3 61 58 44 65 82 19 4 35 62) ;; 8 (33 70 84 40 66 38 92 67

Is there a way to get the slots of a class?

我的未来我决定 提交于 2019-12-01 15:20:46
问题 I have a class like this one (defclass shape () ((color :initform :black) (thickness :initform 1) (filledp :initform nil) (window :initform nil))) Is there a function in common-lisp how to get a list of those slots if i only know instance of this class? 回答1: Many Common Lisp implementations support the CLOS Meta-object Protocol . This provides introspective operations for classes, slots and other meta objects . In LispWorks the corresponding functions are directly accessible in the package CL

How to create and write into text file in Lisp

ε祈祈猫儿з 提交于 2019-12-01 02:47:03
问题 I want to know, how to create and write text file in lisp. I just want to write simple line like: "break 1" "break 2" I am using LispWorks IDE on Window 7 回答1: (with-open-file (str "/.../filename.txt" :direction :output :if-exists :supersede :if-does-not-exist :create) (format str "write anything ~%")) You may also choose different settings for the with-open-file macro. If you use :append instead of :supersede then you can write into the text file while preserving its context instead of