: ) wonderful world ( :

the metasyntactic variable

Archive for January 2007

without comments

Let’s have a look on
Cells
:

login08% cat .ccells
(load "~/asdfsys/asdf.lisp")
(pushnew #p"~/asdfsys/" asdf:*central-registry*)
(asdf:oos 'asdf:load-op :cells)
(in-package :cells)

(defmodel my-first-cell-class ()
  ((val :cell t
        :initform (c-in 10)
        :initarg :val
        :accessor val)
   (fun :cell t
        :initform (c? (* (val self) 2))
        :initarg :fun
        :accessor fun)))

(setf e (to-be (make-instance 'my-first-cell-class)))

login08% clisp -i .ccells

; [...] messages and messages

;; Loaded file .ccells
[1]> (in-package :cells)
#<PACKAGE CELLS>
CELLS[2]> e
#<MY-FIRST-CELL-CLASS #x20417846>
CELLS[3]> (val e)
10
CELLS[4]> (fun e)
20
CELLS[5]> (setf (val e) 3)
3
CELLS[6]> (fun e)
6
CELLS[7]>
Bye.
login08%

The documentations teach to use cv where I’ve got c-in, but in the CVS
version right now, there isn’t any cv macro or function :(. It took
two hours to recognize this :)…

Written by grault

January 28, 2007 - 12:18 pm at January 28, 2007 - 12:18 pm

without comments

Gram-Smidth ortogonalization in scheme:

(define dotprod
  (lambda (a b)
    (apply +
	   (map * a b))))

(define norm
  (lambda (a)
    (sqrt (dotprod a a))))

(define elementwise
  (lambda (f)
    (lambda arguments
      (apply map
	     f
	     arguments))))

(define transpose
  (lambda (matrix)
    (apply (elementwise list) matrix)))

(define premap
  (lambda (arg fun)
    (lambda (vector)
      (map (lambda (y) (fun arg y)) vector))))

(define postmap
  (lambda (fun arg)
    (lambda (vector)
      (map (lambda (y) (fun y arg)) vector))))

(define normalize
  (lambda (vector)
    (let ((c (norm vector)))
      ((postmap / c) vector))))

(define ortogonalizer
  (lambda vecs
    (lambda (vec)
      (if (null? vecs)
	  vec
	  ((elementwise -)
	   vec
	   (apply
	    (elementwise +)
	    (map (lambda (vec num) ((postmap * num) vec))
		 vecs
		 ((postmap dotprod vec) vecs))))))))

(define gram-smidth
  (lambda vectors
    (reverse
     (let loop ((vectors vectors) (ortonormed '()))
       (if (null? vectors)
	   ortonormed
	   (loop (cdr vectors)
		 (cons
		  (normalize
		   ((apply ortogonalizer ortonormed) (car vectors)))
		  ortonormed)))))))

Written by grault

January 22, 2007 - 8:50 pm at January 22, 2007 - 8:50 pm

without comments

If one want to visualize clearly a big graph (my general graphviz parameters):

digraph spec {
  edge [ arrowsize = 0.5, arrowhead = odot ] ;
  graph [ overlap = none, outputorder = edgesfirst, splines = true ] ;
  node [ style = filled, fillcolor = "white" ] ;

...

}

Written by grault

January 19, 2007 - 3:43 pm at January 19, 2007 - 3:43 pm

without comments

Here is how to setup asdf-install (example):

(load #p"/cygdrive/c/lisp/asdf.lisp")

(pushnew #p"/cygdrive/c/asdf/" asdf:*central-registry*)

(asdf:operate 'asdf:compile-op :asdf-install)
(asdf:operate 'asdf:load-op :asdf-install)
(setf asdf-install:*verify-gpg-signatures* nil)
(asdf-install:install :cl-ppcre)
(asdf:oos 'asdf:load-op :cl-ppcre)

Written by grault

January 19, 2007 - 2:24 pm at January 19, 2007 - 2:24 pm

without comments

Here is the code to create an empty PDF document with one sheet in common lisp with the asdf packages cl-pdf and cl-typesetting:

(load #p"/cygdrive/c/lisp/asdf.lisp")

(pushnew #p"/cygdrive/c/asdf/" asdf:*central-registry*)

(asdf:oos 'asdf:load-op :cl-pdf)
(asdf:oos 'asdf:load-op :cl-typesetting)

(pdf:with-document
 ()
 (pdf:with-page
  ())
 (pdf:write-document #p"apple.pdf"))

Written by grault

January 19, 2007 - 12:37 pm at January 19, 2007 - 12:37 pm

without comments

In asdf (tutorial here) the paths in asdf:*central-registry* must end with a slash.

Written by grault

January 19, 2007 - 11:01 am at January 19, 2007 - 11:01 am