lisp

code throws me an error: Space is an illegal character after a colon.

谁都会走 提交于 2019-12-11 20:34:38
问题 sort code, which is basically a translation i made from this one: insertion(A) for i from 2 to n j=i-1 while (j>=1) AND (A[j]>A[j+1])do t=A[j+1] A[j+1]=A[j] A[j]=t j=j-1 and my translation to lisp is (defun insertion (unsorted-vector) (let ((vector (copy-seq unsorted-vector)) (n (length unsorted-vector))) (loop :for i : from 2: below (n) :do ((j (- i 1)) (loop :do (AND (>= (j 1)) (> (aref vector j) (aref vector (+ j 1)))) (rotatef (aref vector j) (aref vector (+ j 1))) (j (- j 1)))) vector)))

Solving Infix Arithmatic in LISP

南楼画角 提交于 2019-12-11 20:00:55
问题 (defun solve (L) (cond ((null L) nil) (t(eval (list (car (cdr L)) (car L) (car (cdr (cdr L)))))))) The code I have is a simple evaluate program that works fine as long as the input is something like '(5 + 4). However I want to be able to solve other inputs such as '(5 +( 3 - 1)) and '(6 + 5) - (4 /2 ) . My problem obviously being how to handle the parentheses. I tried comparing the literal value of '( as in ((equal (car L) '( ) (solve(cdr L))) but that only throws all of my close parentheses

Should be a lamba expression-LISP

天大地大妈咪最大 提交于 2019-12-11 19:50:06
问题 Just one function of my code: (defun equalprev (x y) (cond ((or (atom x) (atom y)) (if (not (null isLoop)) t ((setq list1 (append list1 (list x))) (setq list2 (append list2 (list y))) (eql x y)))) ((equalprev (car x) (car y)) (equalprev (cdr x) (cdr y))))) *** - SYSTEM::%EXPAND-FORM: (SETQ LIST1 (APPEND LIST1 (LIST X))) should be a lambda expression The following restarts are available: ABORT :R1 Abort main loop Any help is appreciated 回答1: The alternate expression for the 'if' expression is

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

When I run this, it states that the list constraints is unbound. Why is that?

与世无争的帅哥 提交于 2019-12-11 13:56:44
问题 (defun combinations (&rest lists) (if (car lists) (mapcan (lambda (inner-val)(mapcar (lambda (outer-val) (cons outer-val inner-val)) (car lists))) (apply #'combinations (cdr lists))) (list nil))) The combinations function creates all combinations of the names, charms and position for each baseball player. (defun main() (setq m-list (combinations '(Blacket Bluet Browning Greenfield Whitehall)'(four-lear-clover penny rabbit-foot ribbon silver-dollar) '(center- field first-base right-field short

How to inject elements into character content with Closure XML?

狂风中的少年 提交于 2019-12-11 13:36:28
问题 I need to transform all characters | to tags in all texts blocks of a big XML file. That is, whenever I found <test att="one|two">content | something more | and done</test> I need to transform to <test att="one|two">content <bar/> something more <bar/> and done</test> Note that | can also occur in attributes values and, in that case, they must be keeped unchanged. After reading the Transforming slide of the SAX Overview part of the CXML focumentation, I wrote (defclass preproc (cxml:sax-proxy

Navigating a webpage using html5-parser and xmls Common Lisp

≡放荡痞女 提交于 2019-12-11 12:17:14
问题 I am trying to get the first row under the column with the title "Name" so for example for https://en.wikipedia.org/wiki/List_of_the_heaviest_people I want to return the name "Jon Brower Minnoch". My code so far is as follows, but I think there must be a more general way of getting the name: (defun find-tag (tag doc) (when (listp doc) (when (string= (xmls:node-name doc) tag) (return-from find-tag doc)) (loop for child in (xmls:node-children doc) for find = (find-tag tag child) when find do

How is sharp quote (#') different from symbol-function?

↘锁芯ラ 提交于 2019-12-11 10:59:25
问题 To me these operators seem to do the same thing. Both take a symbol and return the function associated with it. Is there any difference? elisp evaluation returns the following: (defun foo (x) (+ 1 x)) foo (foo 3) 4 #'foo Which I don't understand either. Furthermore is there a difference between common lisp and elisp? I'm learning from resources on either. 回答1: Common Lisp : SYMBOL-FUNCTION can't retrieve functions from lexically bound functions. FUNCTION references the lexically bound

Largest sublist in Common Lisp

拟墨画扇 提交于 2019-12-11 10:47:37
问题 I'm trying to get the largest sublist from a list using Common Lisp. (defun maxlist (list) (setq maxlen (loop for x in list maximize (list-length x))) (loop for x in list (when (equalp maxlen (list-length x)) (return-from maxlist x))) ) The idea is to iterate through the list twice: the first loop gets the size of the largest sublist and the second one retrieves the required list. But for some reason I keep getting an error in the return-from line. What am I missing? 回答1: Main problem with

Remove subsequence function (deep recursion) in scheme

大憨熊 提交于 2019-12-11 10:45:01
问题 Im trying to write a function called removesub* which accepts two arguments (l1 and l2) . The function needs to return the second list with the first occurence of the subsequence removed. So, if the first list is '(a b c) , the first a if the second list is removed, the first b that appears after the removed a is removed, and the first c that appears after the removed b is removed - no matter how deep the atoms are nested. Working Example Input: (removesub* '(a b) '(w (x b) ((a) ((y z))) b a)