Discussion about LISP

lisp programing




Install guide for CLISP, Emacs, and SLIME on Windows XP

In the spirit of good documentation, I just wrote up my transition
from Lispbox to a regular CLISP/Emacs/SLIME on Windows XP.  I pulled
together info from a bunch of different places and wrote up a complete
set of instructions to get that system running easily.  I ran through
it on another computer and it took about 20 minutes (that’s for you
Peter H! http://groups.google.com/group/comp.lang.lisp/msg/d4e5a1c07a2a1a8c).
The next thing I’m going to work on is a guide for setting up lots of
documentation accessible within Emacs (HyperSpec, SICP, etc).

I appreciate any feedback – let me know what else it could use!

Thanks,
Peter

http://www.pchristensen.com/blog/articles/installing-clisp-emacs-and-…

No Comments

WWW.NIKES4WHOLESALE.COM Nike Air Max trainers

Nike Air Max trainers
Air Max 87 shoes WWW.NIKES4WHOLESALE.COM
Air Max 90 shoes WWW.NIKES4WHOLESALE.COM
Air Max 91 shoes WWW.NIKES4WHOLESALE.COM
Air Max 95 shoes WWW.NIKES4WHOLESALE.COM
Air Max 97 shoes WWW.NIKES4WHOLESALE.COM
Air Max 2003 shoes WWW.NIKES4WHOLESALE.COM
Air Max 360 shoes WWW.NIKES4WHOLESALE.COM
Air Max 180 shoes WWW.NIKES4WHOLESALE.COM
Air Max TN shoes WWW.NIKES4WHOLESALE.COM
Air Max TN2 shoes WWW.NIKES4WHOLESALE.COM
Air Max TN3 shoes WWW.NIKES4WHOLESALE.COM
Air Max TN6 shoes WWW.NIKES4WHOLESALE.COM
Air Max TN8 shoes WWW.NIKES4WHOLESALE.COM
Air Max LTD shoes WWW.NIKES4WHOLESALE.COM
Air Max 1 id shoes WWW.NIKES4WHOLESALE.COM

No Comments

Search path program

I was just wondering if anyone had any idea on how to address this
problem. I would like to write code for a function in LISP that will
help a car go from point A to point J passing all points with no
backtracking using a depth-first search. Any ideas?

Comments (15)

Trouble populating an array of structures with items from list of data

; Suppose I have the following list with data:
;
(defparameter *db*
‘(("01" "Agatha Christie" "Murder on the Orient Express" "po")("02"
"Oscar Wilde" "Portrait of Dorian Gray" "ro")))

; I then create structures for the items
;
(defstruct (bk (:type list)) cod aut tit gen)

; Now, I create an empty array to receive those structures
;
(defvar vc (map-into (make-array 2) #’make-bk))
;
; CL-USER> vc
; => #((NIL NIL NIL NIL) (NIL NIL NIL NIL))

; But when I try to populate the array with the books, like this:
;
(dolist (bk *db*)
             (map-into (make-array 2) #’make-bk)
                     (loop for i from 0 to 1 do ;;
                  (setf (aref vc i) bk)))
;
; I find, strangely, this:
;
;CL-USER> vc
;#(("02" "Oscar Wilde" "Portrait of Dorian Gray" "ro")
;  ("02" "Oscar Wilde" "Portrait of Dorian Gray" "ro"))
;
; Probably I problem related to dolist, I’m guessing.
; Any clues?
; Thanks.
; JT.

Comments (12)

bored

the string

"I can eat glass⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍Я могу есть

стекло, оно мне не вредитאני יכול לאכול זכוכית וזה לא מזיק לי我能吞下玻璃而不伤身

体私はガラスを食べられます。それは私を傷つけません"

was converted to utf-8 bytes 1000 times and the results stored in a

big array on SBCL 1.0.15

"with flexi-strems:string-to-octets"

Evaluation took:

  0.3 seconds of real time

  0.272195 seconds of user run time

  0.018398 seconds of system run time

  [Run times include 0.03 seconds GC run time.]

  0 calls to %EVAL

  0 page faults and

  5,442,888 bytes consed.

"with trivial-utf-8:string-to-utf-8-bytes"

Evaluation took:

  0.017 seconds of real time

  0.014656 seconds of user run time

  0.002209 seconds of system run time

  0 calls to %EVAL

  0 page faults and

  1,654,784 bytes consed.

"with babel:string-to-octets"

Evaluation took:

  0.006 seconds of real time

  0.005423 seconds of user run time

  5.07e-4 seconds of system run time

  0 calls to %EVAL

  0 page faults and

  380,872 bytes consed.

"with sb-ext:string-to-octets"

Evaluation took:

  0.004 seconds of real time

  0.004253 seconds of user run time

  5.35e-4 seconds of system run time

  0 calls to %EVAL

  0 page faults and

  376,664 bytes consed.

; note: if utf-8 breaks your slime/emacs try putting this in

your .emacs file:

(set-language-environment "UTF-8")

(setq slime-net-coding-system ‘utf-8-unix)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar *english* "I can eat glass")

(defvar *english/brail* "⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍")

(defvar *russian* "Я могу есть стекло, оно мне не вредит")

(defvar *hebrew* "אני יכול לאכול זכוכית וזה לא מזיק לי")

(defvar *chinese* "我能吞下玻璃而不伤身体")

(defvar *japanese* "私はガラスを食べられます。それは私を傷つけません")

(defvar *string* (concatenate ‘string *english* *english/brail*

*russian* *hebrew* *chinese* *japanese*))

(defvar *array-size* 1000)

(defvar *big-array* (make-array *array-size*))

(format t

        "~%the string ~%~%~S~%~%was converted to utf-8 bytes ~A times and the

results stored in a big array on ~A ~A~%"

        *string*

        *array-size*

        (lisp-implementation-type)

        (lisp-implementation-version))

(print "with flexi-strems:string-to-octets")

(let ((utf-8 (flexi-streams:make-external-format :utf-8)))

  (funcall (compile nil

                    (lambda ()

                      (time (map-into *big-array*

                                      (lambda ()

                                        (flexi-streams:string-to-octets *string* :external-format

utf-8))))))))

(print "with trivial-utf-8:string-to-utf-8-bytes")

(funcall (compile nil

                  (lambda ()

                    (time (map-into *big-array*

                                    (lambda ()

                                      (trivial-utf-8:string-to-utf-8-bytes *string*)))))))

(print "with babel:string-to-octets")

(funcall (compile nil

                  (lambda ()

                    (time (map-into *big-array*

                                    (lambda ()

                                      (babel:string-to-octets *string* :encoding :utf-8)))))))

#+sbcl

(progn

  (print "with sb-ext:string-to-octets")

  (funcall (compile nil

                    (lambda ()

                      (time (map-into *big-array*

                                      (lambda ()

                                        (sb-ext:string-to-octets *string* :external-format :utf-8))))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

No Comments

Changing a class' metaclass

Some people might have wondered whether it is possible to change the
metaclass of a class. The MOP seems to clearly disallow it, but
nevertheless some implementations do allow it. Here are the details:

"Some class metaobject classes allow their instances to be redefined.
When permissible, this is done by calling reinitialize-instance. This
is discussed in the next section."
 <http://www.lisp.org/mop/concepts.html#init-class>

"Some class metaobject classes allow their instances to be
reinitialized. This is done by calling reinitialize-instance. The
initialization arguments have the same interpretation as in class
initialization."  <http://www.lisp.org/mop/concepts.html#reinit-class>

But reinitialize-instance is just for slots, it does not accept
a :metaclass option. So that won’t work.

Maybe changing the metaclass can be done using ensure-class, which
forwards to ensure-class-using-class, and there we have:

"If the class of the class argument is not the same as the class
specified by the :metaclass argument, an error is signaled." <http://
www.lisp.org/mop/dictionary.html#ensure-class-using-class>

That is a clear NO.

SBCL 1.0.16 confirms it:

* (defclass my-metaclass (standard-class) ())
#<STANDARD-CLASS MY-METACLASS>
* (defclass foo (standard-class)())
#<STANDARD-CLASS FOO>
* (sb-pcl:ensure-class ‘foo :metaclass ‘my-metaclass)

debugger invoked on a SB-PCL::METAOBJECT-INITIALIZATION-VIOLATION:
  Cannot CHANGE-CLASS objects into CLASS metaobjects.
See also:
  AMOP, Initialization of Class Metaobjects

Nevertheless, Allegro 8.1 does accept it:

cl-user(2): (defclass my-metaclass (standard-class) ())
#<standard-class my-metaclass>
cl-user(3): (defclass foo (standard-class)())
#<standard-class foo>
cl-user(4): (mop:ensure-class ‘foo :metaclass ‘my-metaclass)
#<my-metaclass foo>

as does Lispworks 5.0.2:

CL-USER 2 > (defclass my-metaclass (standard-class) ())
#<STANDARD-CLASS MY-METACLASS 2009BDA3>

CL-USER 3 > (defclass foo (standard-class)())
#<STANDARD-CLASS FOO 200B7C3F>

CL-USER 4 > (defmethod clos:validate-superclass ((class my-metaclass)
superclass)
    (declare (ignorable class superclass))
    t)
#<STANDARD-METHOD VALIDATE-SUPERCLASS NIL (MY-METACLASS T) 200A01B3>

CL-USER 5 > (clos:ensure-class ‘foo :metaclass ‘my-metaclass)
#<MY-METACLASS FOO 200B7C3F>

- Willem

Comment (1)

bind*

I was thinking (like, perhaps, no less than half of the people in this
group) about unifying variable binding declarations (let, multiple-
value-bind, with-input-from-string etc.) in one form.

…Just as Gary King did, which resulted in him producing the METABANG-
BIND package. Recently I’ve had a look at it and felt, that it was a
little over-complicated for just a syntactic-sugar.  I don’t mean to
criticize Gary’s solution, the more so since my idea of bind-form
dispatch was different, i.e.: according to the structure of the bind
clause and types of it’s elements.

So, I’ve programmed the following simple implementation of a universal
bind form. What do you think of it? Is there any major flaw in it?

(defmacro bind* ((&rest clauses) &body body)
    (let ((rez body))
        (mapc #’(lambda (clause)
                          (setf rez `((,@(expand-bind-clause
clause) ,@rez)))
                    (reverse clauses))
        (car rez)))

(defparameter *bind-dispatch-table* nil)

(defmacro def-bind-rule (rule expansion)
  `(push (cons #’(lambda (clause)
                              (and (listp clause) (cdr clause) ,rule))
                       #’(lambda (clause)
                             ,expansion))
             *bind-dispatch-table*))

(defun expand-bind-clause (clause)
  (funcall (or (cdr (find-if #’identity *bind-dispatch-table*
                                      :key #’(lambda (x)
                                                    (funcall (car x) clause))))
                    (error "No bind* rule for clause: ~a" clause))
             clause))

; rules

(def-bind-rule (not (cddr clause))
                      `(let (,clause)))

(def-bind-rule (and (listp (car clause)) (listp (cadr clause)) (not
(cddr clause)))
                      `(destructuring-bind ,(car clause) ,(cadr
clause)))

(def-bind-rule (and (cddr clause) (every #’identity (mapcar #’atom
(butlast clause))))
                      `(multiple-value-bind ,(butlast clause) ,@(last
clause)))

(def-bind-rule (and (atom (car clause)) (eql (cadr clause) :in)
                               (cddr clause) (stringp (caddr clause)))
                       `(with-input-from-string (,(car clause) ,@(cddr
clause))))

(def-bind-rule (and (atom (car clause)) (eql (cadr clause) :in)
                               (cddr clause) (pathnamep (caddr clause)))
                      `(with-open-file (,(car clause) ,@(cddr
clause))))

(def-bind-rule (and (atom (car clause)) (eql (cadr clause) :o ut)
                              (let ((third (caddr clause)))
                                 (or (null third) (stringp third) (keywordp
third))))
                      `(with-output-to-string (,(car clause) ,@(cddr
clause))))

(def-bind-rule (and (atom (car clause)) (eql (cadr clause) :o ut)
                              (pathnamep (caddr clause)))
                      `(with-open-file (,(car clause) ,(caddr
clause) :direction :o utput ,@(cdddr clause))))

Best regards,
Vsevolod

Comments (7)

LET value being clobbered

Hello all,

I’m pretty new to lisp, coming from a C++ background, and I can’t figure
out how to not clobber the value of RESULT in HEAP-POP:

(Sorry for the formatting, it’s hard to fit in USENET preferred columns)

(defstruct (heap (:constructor make-heap (&key (test #’<=)
                 (key #’identity)
                 (size 10) &aux (count 0) (elements (make-array
                 size :adjustable t :fill-pointer 0)))))
                 count elements test key size)

(defun heap-push (heap obj)
  "Push a new OBJ onto a HEAP"
  (declare (type heap heap))
  (with-slots (key test elements count) heap
    (if (< (fill-pointer elements) (array-dimension elements 0))
        (vector-push nil elements)
        (vector-push-extend nil elements))
    (do* ((j (1+ count))
          (i (floor (/ j 2)) (floor (/ j 2)))
          (done nil))
         (done t)
      (if (or (eql i 0) (funcall test (funcall key (aref elements (1- i)))
                                      (funcall key obj)))
          (setf (aref elements (1- j)) obj count (1+ count) done t)
          (setf (aref elements (1- j)) (aref elements (1- i)) j i)))))

(defun heap-top (heap)
  "Get the topmost object from HEAP, without removing it"
  (declare (type heap heap))
  (if (> (heap-count heap) 0)
      (aref (heap-elements heap) 0)
      nil))

(defun heap-pop (heap)
  "Remove the topmost object from HEAP, returning it"
  (declare (type heap heap))
  (with-slots (key test elements count) heap
    (when (eql count 0)
      (return-from heap-pop nil))
    (decf count)
    (setf (aref elements 0) (aref elements count))
    (decf (fill-pointer elements))
    (let ((key-object (aref elements count))
          (i 1) (j 1) (done nil)
          (result (heap-top heap)))
      (loop while (null done) do
           (setf i j j (* j 2))
           (if (> j count)
               (setf done t)
               (progn
                 (when (and (/= j count)
                       (funcall test (funcall key (aref elements j))
                       (funcall key (aref elements (1- j)))))
                   (incf j))
                 (if (funcall test (funcall key key-object)
                                   (funcall key (aref elements (1- j))))
                     (setf done t)
                     (setf (aref elements (1- i))
                           (aref elements (1- j)))))))
    (setf (aref elements (1- i)) key-object)
    result)))

SKIRMISH> h
#S(HEAP
   :COUNT 0
   :ELEMENTS #()
   :TEST #<FUNCTION <=>
   :KEY #<FUNCTION IDENTITY>
   :SIZE 10)

SKIRMISH> (dotimes (i 1000) (heap-push h (random 1000)))
NIL

SKIRMISH> (heap-top h)
3

SKIRMISH> (heap-pop h)
464

What am I doing wrong to have RESULT be overwritten? I guess it’s because
the LET only stores a reference to (aref elements 0), rather than the
value. How do I extract the value to keep it separate from the array
reference?

("use CELLS" is not a proper answer)

Thanks
Adam

Comments (22)

[ANN] Aldor & Axiom / OpenAxiom / FriCAS Workshop 2008

(since the compilers of Aldor, Axiom, OpenAxiom and FriCAS currently all
compile to lisp, this might be interesting for some folks here, too…)

                          Aldor & Axiom Workshop 2008

                                    part of

                               RISC Summer 2008

                              Hagenberg, Austria
                                24-26 July 2008

The workshop aims at a cooperation of Aldor, Axiom, OpenAxiom, and FriCAS
developers with developers of packages written for other Computer Algebra
Systems, and mathematicians that would like to use a computer algebra system to
perform experiments.

Conference Website
——————
  http://axiom-wiki.newsynthesis.org/WorkShopRISC2008

Topics
——
  Similar to 2006 and 2007, the workshop will be organized as a mixture of
  talks and discussions. We will begin with an introduction to Axiom /
  OpenAxiom / FriCAS and the Aldor language, including a comparison with the
  approach employed by Sage and Python.

  We then plan to cover the following topics:

  Aldor, SPAD, and the interpreter

      – work on SPAD (eg., allow arbitrary conditional exports),

      – work on the interpreter (eg., it’s signature selection algorithm), and

      – improve the Axiom / OpenAxiom / FriCAS – Aldor interaction (eg., make
        Axiom / OpenAxiom / FriCAS understand Aldor’s extend or dependent
        signatures generated in Aldor code).

  interaction of Axiom / OpenAxiom / FriCAS with other systems

     We would like to explore the possibility and the usefulness of reusing
     third party code like PARI, GAP, Polymake, etc., but also interfacing with
     Sage.

  problems implementing mathematics in Aldor and SPAD

     We would like to tackle some particularly challenging implementation
     problems, including

       - combinatorial species – the multisort case,

       - how to organize domains and categories for recurrences and functions,

       - how to organize aggregates and matrices, in particular how to ensure
         efficient looping over aggregate elements, etc.

Contributions
————-
  If you would like to contribute a presentation to one of these topics or a
  related one, please send a message to the organisers.

Suggested reading
—————–
  Aldor User Guide (http://www.aldor.org/docs/aldorug.pdf)

  Axiom Book (http://wiki.axiom-developer.org/axiom-website/book.pdf)

  Multisort species (svn cat svn://svn.risc.uni-linz.ac.at/hemmecke/combinat/branches/multisort-experime nt/combinat/src/mspecies.as.nw)

Registration
————
  Registration is handled via the general RISC Summer 2008 Registration at

  http://www.risc.uni-linz.ac.at/about/conferences/summer2008/registrat…

  Please note that the fee (30 EUR) does not cover hotel, lunch, dinner, and
  transportation to Hagenberg.  You may reserve a hotel room in Hagenberg
  through the registration page.

Organisers
———-
  Ralf Hemmecke and Martin Rubey

No Comments

Why wasn't I told about logbitp?!

Damn language.

kenny


http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
ECLM rant:
http://video.google.com/videoplay?docid=-1331906677993764413&hl=en
ECLM talk:
http://video.google.com/videoplay?docid=-9173722505157942928&q=&hl=en

Comments (21)