clisp

Common Lisp: Why does my tail-recursive function cause a stack overflow?

♀尐吖头ヾ 提交于 2020-08-04 04:06:34
问题 I have a problem in understanding the performance of a Common Lisp function (I am still a novice). I have two versions of this function, which simply computes the sum of all integers up to a given n . Non-tail-recursive version: (defun addup3 (n) (if (= n 0) 0 (+ n (addup (- n 1))))) Tail-recursive version: (defun addup2 (n) (labels ((f (acc k) (if (= k 0) acc (f (+ acc k) (- k 1))))) (f 0 n))) I am trying to run these functions in CLISP with input n = 1000000 . Here is the result [2]>

MAC OSX 10.7 Lion 下简单编译 CLISP 的过程--使用了 macport

五迷三道 提交于 2020-04-11 18:51:02
MAC OSX 10.7 Lion 下简单编译 CLISP 的过程 最简单的办法就是用 macport(需要你的系统上先安装好 macport), 命令行如下: sudo port install clisp 然后就边喝茶边看 CPU 温度飙升到 90多度,风扇以 6000 转的速度狂转.... 整个过程就是先查找 Clisp 有依赖关系的库, 先把这些库下载编译好, 最后编译 Clisp , 编译最后的输入信息如下: .......... ---> Computing dependencies for clisp ---> Fetching archive for clisp ---> Attempting to fetch clisp-2.49_2.darwin_11.i386.tbz2 from http://jog.id.packages.macports.org/macports/packages/clisp ---> Attempting to fetch clisp-2.49_2.darwin_11.i386.tbz2 from http://packages.macports.org/clisp ---> Attempting to fetch clisp-2.49_2.darwin_11.i386.tbz2 from http://mse.uk.packages

How do I use the “cl-position” function accurately in clisp?

只谈情不闲聊 提交于 2020-03-23 07:59:13
问题 I am trying to use cl-position in clisp, however, whenever I try to run the code, I get the following error: Prinayas-MacBook-Pro:~ pchoubey$ clisp project1.lisp *** - SYSTEM::%EXPAND-FORM: (PRINT (CL-POSITION "bar" '("foo" "bar" "baz") :TEST 'EQUAL)) should be a lambda expression Why is this happening and how can I get this code to run properly? For reference, here is my code: (defun answer-ynq() (setq ROBOT '(IS_A_ROBOT ROBBIE)) (loop for x in ROBOT do( (print (cl-position "bar" '("foo"

Trying to print a triangle recursively in lisp

ε祈祈猫儿з 提交于 2020-01-25 08:57:07
问题 Trying to print a triangle recursively in lisp. I get an overflow but I don't know from where. Mind you I am new to Lisp programming. (defun triangle (n) (if (not (oddp n))(progn (print "This is not an odd integer") (return-from triangle n))) (if (< n 1) '()) (setf lst (cons (car(list n)) (triangle (- n 2)))) (print lst)) (triangle 7) 回答1: Let's review some parts of your code. (if (not (oddp n)) (progn (print ...) (return-from ...))) When you have an if with only one branch, think about using

common lisp function/macro aliases

家住魔仙堡 提交于 2020-01-05 04:06:10
问题 I would like to set aliases in common lisp(clisp to be exact) for commands that are used a lot, such as "defun" and "lambda" etc, is it possible to do this? This is actually kind of a duplicate of this question, but I can not comment and the solution does not work for defun or lambda in both sbcl and clisp 回答1: Macros: CL-USER 5 > (setf (macro-function 'dm) (macro-function 'defmethod)) #<Function DEFMETHOD 410009A014> CL-USER 6 > (dm m1+ ((v vector)) (map 'vector #'1+ v)) #<STANDARD-METHOD M1

Compiling clisp-2.49 on OSX : LIBFFI not found

限于喜欢 提交于 2020-01-03 09:08:14
问题 TL;DR : Even if libffi seems installed, the configure script doesn't find it even if I give it the (correct?) prefix. /!\ The last part (*) of this post is where I'm stuck. /!\ I only put the other information to explain how I get there. I apologize for the big post, if something seems irrelevant to you, feel free to tell me, I'll consider making my post shorter. Why I want to compile CLISP by myself : I have a lisp programm I would like to run but when running it with CLISP installed with

Functional programming in LISP

走远了吗. 提交于 2019-12-26 03:09:44
问题 i just have started to learn function programming and it is a bit confusing for me, i have a task now: remove all duplicates from the row with lists, so: input row: (SETQ X (LIST 2 -3 (LIST 4 3 0 2) (LIST 4 -4) (LIST 2 (LIST 2 0 2))-3)) I want output be like this : (2 -3 (4 3 0)(-4)()) I want to make it with recursion. I have some conceptual questions: how can i remove an element from list or i should make a new one for output? In other programming languages every step of recursion has it own

Using packages installed from quicklisp with clisp

和自甴很熟 提交于 2019-12-25 17:00:30
问题 I installed cl-yacc from quick lisp: (ql:quickload "yacc") I checked it is available. [12]> (ql:system-apropos "yacc") #<SYSTEM lispbuilder-yacc / lispbuilder-20130312-svn / quicklisp 2013-08-13> #<SYSTEM yacc / cl-yacc-20101006-darcs / quicklisp 2013-08-13> I tried to use the package, but I got errors. [18]> (use-package '#:yacc) *** - USE-PACKAGE: There is no package with name "YACC" The following restarts are available: USE-VALUE :R1 Input a value to be used instead. ABORT :R2 Abort main

Lisp Function that Returns a Sum

半世苍凉 提交于 2019-12-24 02:41:02
问题 I am trying to write a weird function, so bear with me here. This function should take a list L as a parameter and have a sum variable. If L is not a list, it should return nil . Otherwise, it should iterate through each element of the list and do the following: If the element is a number and less than zero, it should subtract 1 from the sum. If the element is a number and greater than zero, it should add 1 to the sum. if the element is 0 or not a number, then it should add 0 to the sum. Here

LISP: Why doesn't mapcan accept my list give as parameters?

回眸只為那壹抹淺笑 提交于 2019-12-23 20:49:12
问题 To simplify my question: why this works (mapcan #'(lambda (l) (list '1 '2) ) '(a b)) and this doesn't (mapcan #'(lambda (l) '(1 2) ) '(a b)) ? I have to write a function that substitutes an element through all elements of list D at all levels of a given list L, using Map Functions. I tried using mapcan for this: (defun subAll (l k d) (cond ((and (atom l) (eq l k)) d) ((and (atom l) (not (eq l k))) (cons l '())) (t (cons (mapcan #'(lambda (l) (subAll l k d)) l) '())))) but I get following