Search found 62 matches

by Konfusius
Tue Jun 19, 2012 4:32 pm
Forum: Common Lisp
Topic: Lisp newbie trying to optimize recursive algorithm, help?
Replies: 16
Views: 34811

Re: Lisp newbie trying to optimize recursive algorithm, help

The funcall to predicate is a huge timesink. I tested your program with Clozure CL v1.6 under Windows and without the funcall to predicate it took 0.205 seconds for a list of 10.000 elements. I also rewrote your program in C with Visual C++ 6 using a static array and it took 0.175 seconds. I doubt J...
by Konfusius
Thu Jun 07, 2012 3:50 pm
Forum: Common Lisp
Topic: Getting the directory of executable (like GetModuleFileName)
Replies: 10
Views: 17945

Re: Getting the directory of executable (like GetModuleFileN

You may use *load-truename*. While loading this variable is bound to the name and full path of the lisp-file that is currently loading. Since it is only bound while loading you cannot use it directly in your program. You have to assign it to a global variable and then use that instead: (defparameter...
by Konfusius
Thu May 03, 2012 12:19 pm
Forum: Common Lisp
Topic: Efficient relation composition
Replies: 6
Views: 9081

Re: Efficient relation composition

Sorry for the typos. I corrected them. The second code example is tested and working, though. I dont' get what you mean with "composition of relations" (I'm assuming you mean equivalence relations). The idea of composition you gave in your second post cannot be generalized for relations co...
by Konfusius
Thu May 03, 2012 7:45 am
Forum: Common Lisp
Topic: Efficient relation composition
Replies: 6
Views: 9081

Re: Efficient relation composition

Your code is wrong. A working and much simpler approach would be the following: (defun related-p (a b rel) ; return true if a and b are related according to rel ) (defun combine-relations (rel-1 rel-2) (if (endp rel-1) rel-2 (let ((elm (car rel-1))) (combine-relations (cdr rel-1) (if (related-p (car...
by Konfusius
Mon Dec 19, 2011 4:23 pm
Forum: Common Lisp
Topic: Newbie in Lisp
Replies: 12
Views: 15254

Re: Newbie in Lisp

Clozure CL has integrated a full Win32-API right out of the box. But its poorly documented and you already need to know how to program the Win32-API in C to use it successfully.
by Konfusius
Mon Dec 19, 2011 4:17 pm
Forum: Common Lisp
Topic: tree in-order
Replies: 1
Views: 3346

Re: tree in-order

Just reorder the arguments to append.
by Konfusius
Mon Dec 19, 2011 4:10 pm
Forum: Common Lisp
Topic: Member using MAP
Replies: 4
Views: 8212

Re: Member using MAP

Since you made efford to solve the problem yourself (no sane lisp programmer would write the code like you did) i give you a solution. (defun deep-member (elm list) (or (equal elm list) (deep-member elm (car list)) (deep-member elm (cdr list))) But you have to rewrite the code yourself (using cond e...
by Konfusius
Mon Dec 19, 2011 3:53 pm
Forum: Common Lisp
Topic: accessing children in CLOS?
Replies: 2
Views: 4412

Re: accessing children in CLOS?

CLOS doesn't manage a list of all instances automatically because this would be inefficient and unneccessary for most applications. But you can easily maintain such a list yourself with a global variable. (defclass my-class (...) (...)) (defvar *my-class-instances* nil) (defmethod initialize-instanc...
by Konfusius
Sat Dec 10, 2011 6:40 pm
Forum: Common Lisp
Topic: Implementing "last" with do*
Replies: 19
Views: 24562

Re: Implementing "last" with do*

Code: Select all

<== when there is just one element left ==> stop
by Konfusius
Sat Dec 10, 2011 1:55 pm
Forum: Common Lisp
Topic: Implementing "last" with do*
Replies: 19
Views: 24562

Re: Implementing "last" with do*

Code: Select all

(defun last-it (lista)
  (do* ()
       ((equal (list-length lista) 1) ;; <== when there is just one element left ==> stop
        lista) ; return lista
    (setf lista (cdr lista)))) ; ** ;; <== like "cdr recursion"