: ) wonderful world ( :

the metasyntactic variable

Archive for the ‘imported kotee.freeblog.hu’ Category

without comments

New stuff.

Written by grault

October 22, 2007 - 3:55 pm at October 22, 2007 - 3:55 pm

without comments

I duplicate an element like this:

afroid-laptop% cat cikl.bf
,
[
> + > + <&lt -
]
>.>.
> ++++++++++ . end of line
afroid-laptop% echo a | bf cikl.bf
aa
afroid-laptop%

Written by grault

October 4, 2007 - 11:48 pm at October 4, 2007 - 11:48 pm

without comments

I decided to solve a problem in Brainfuck, so I started training myself. My first attempt is a program which prints out the decimal digits (on linux):

++++++++
++++++++
++++++++
++++++++
++++++++
++++++++ (0x30) >

++++++++++ 10
[
< . + > -
]
> ++++++++++ . end of line

Written by grault

October 4, 2007 - 11:37 pm at October 4, 2007 - 11:37 pm

without comments

Medicine works with correlations. This is good as every experimental science works with them. People having a certain type of cancer, which is a well defined situation, often die in two years, which is also a well defined state. If you have a certain symptom it correlates with the possible causes known by the medical community. But everybody knows that correlation doesn’t have much in common with causality. The latter is stronger.

If you have a certain symptom A and the doctor have information about correlations with B, C and D and B have the highest score (in absolute value) then he or she will, for the first time, try avoiding B. Than C. Than D. Then who knows : )

Let’s see in practice.

  • I’ve trouble with my lungs.
  • Do you smoke?
  • I do.
  • Give up smoking then.

It’s too expensive or time consuming to figure out other possibilities.

In general I honor and respect doctors. It is a wonderful and difficult job.

Let’s see correlation again. So I said A have a strong correlation with B. Let’s suppose avoiding B helps, but not solves the problem. There will be some other effect which will be another symptom. Here we go again. And our case can be worse. Perhaps avoiding B changes the problem which isn’t the previous any more.

Written by grault

September 24, 2007 - 6:58 pm at September 24, 2007 - 6:58 pm

without comments

This is crazy (quote from comp.lang.lisp):

CL-USER> (defmethod fib ((n (eql 0))) 1)
#<STANDARD-METHOD FIB ((EQL 0)) {486206CD}>
CL-USER> (defmethod fib ((n (eql 1))) 1)
#<STANDARD-METHOD FIB ((EQL 1)) {4871255D}>
CL-USER> (defmethod fib (n)
           (let ((answer (+ (fib (- n 1))
                            (fib (- n 2)))))
             (defmethod fib ((x (eql n))) answer)
             answer))
#<STANDARD-METHOD FIB (T) {488E12B5}>
CL-USER> (fib 100)
573147844013817084101

It MEMOIZEs the methods : )

Written by grault

September 19, 2007 - 9:24 pm at September 19, 2007 - 9:24 pm

without comments

One can represent a graph of objects in REPL:

CL-USER> (defmacro link (a b) `(push (lambda () ,b) (cdr ,a)))
LINK
CL-USER> (defmacro new (n o) `(defvar ,n ,o))
NEW
CL-USER> (new *h1* '(1))
*H1*
CL-USER> *h1*
(1)
CL-USER> (new *h2* '(2))
*H2*
CL-USER> *h2*
(2)
CL-USER> (link *h1* *h2*)
(#<FUNCTION (LAMBDA #) {ACE38AD}>)
CL-USER> *h1*
(1 #<FUNCTION (LAMBDA #) {ACE38AD}>)
CL-USER> (funcall (second *h1*))
(2)
CL-USER> (defun succs (n) (mapcar #'funcall (cdr n)))
SUCCS
CL-USER> (succs *h1*)
((2))
CL-USER> (link *h2* *h1*)
(#<FUNCTION (LAMBDA #) {ADFF51D}>)
CL-USER> (succs *h1*)
((2 #<FUNCTION # {ADFF51D}>))
CL-USER> (link *h1* *h1*)
(#<FUNCTION (LAMBDA #) {AE2E13D}> #<FUNCTION (LAMBDA #) {ACE38AD}>)
CL-USER> (succs *h1*)
((1 #<FUNCTION # {AE2E13D}> #<FUNCTION # {ACE38AD}>)
 (2 #<FUNCTION # {ADFF51D}>))
CL-USER> *h2*
(2 #<FUNCTION (LAMBDA #) {ADFF51D}>)
CL-USER> (setf (car *h2*) '(1 2 3))
(1 2 3)
CL-USER> *h2*
((1 2 3) #<FUNCTION (LAMBDA #) {ADFF51D}>)
CL-USER> (succs *h1*)
((1 #<FUNCTION # {AE2E13D}> #<FUNCTION # {ACE38AD}>)
 ((1 2 3) #<FUNCTION # {ADFF51D}>))

Written by grault

September 10, 2007 - 9:08 pm at September 10, 2007 - 9:08 pm

without comments

(defun compose (&rest funs)
  (if (null funs)
      (lambda (k) k)
      (lambda (k)
	(funcall (car funs)
		 (funcall (apply #'compose (cdr funs)) k)))))
CL-USER> (funcall (compose (lambda (k) (* k 2)) (lambda (k) (sqrt k))) 2)
2.828427
CL-USER> (funcall (compose (lambda (k) (* k 2))) 2)
4
CL-USER> (funcall (compose) 2)
2
CL-USER>

Written by grault

August 14, 2007 - 10:56 pm at August 14, 2007 - 10:56 pm

without comments

One can reverse the pages of a PDF document by using the pdftk package under linux and fire a command like this:

pdftk input.PDF cat end-1 output output.PDF

Written by grault

June 18, 2007 - 9:07 pm at June 18, 2007 - 9:07 pm

without comments

My first hunchentoot page setup:

% pwd
/home/kotee
% ls -d slime
slime
% ls slime/slime.el
slime/slime.el
% cat .emacs
(set-variable 'scheme-program-name "guile")
(setq inferior-lisp-program "/usr/local/bin/sbcl")
  (add-to-list 'load-path "/home/kotee/slime")
  (require 'slime)
  (slime-setup)

% cat .sbclrc
(require 'asdf)
(push "/home/kotee/asdfsys/" asdf:*central-registry*)

(asdf:oos 'asdf:load-op :hunchentoot)
(asdf:oos 'asdf:load-op :cl-who)
% ls -1 asdfsys/*.asd
asdfsys/acl-compat.asd
asdfsys/cffi.asd
asdfsys/chunga.asd
asdfsys/cl-base64.asd
asdfsys/cl-ppcre.asd
asdfsys/cl+ssl.asd
asdfsys/cl-who.asd
asdfsys/flexi-streams.asd
asdfsys/html-template.asd
asdfsys/hunchentoot.asd
asdfsys/hunchentoot-test.asd
asdfsys/md5.asd
asdfsys/rfc2388.asd
asdfsys/trivial-gray-streams.asd
asdfsys/url-rewrite.asd
% cat hunchen.lisp

(defpackage :first
  (:use :cl :hunchentoot :cl-who :sb-ext))

(in-package :first)

(defmacro with-html (&body body)
  `(with-html-output-to-string
    (*standard-output* nil :prologue t)
    ,@body))

(defun main-page ()
  (no-cache)
  (with-html
    (:html
     (:head (:title "first page"))
     (:body
      (:h1 "first page")))))

(push (create-prefix-dispatcher "/first"
                                'main-page)
      *dispatch-table*)

(defparameter *server* '())
(setf *server* (hunchentoot:start-server :port 4242))
% ls -1 asdfsys/*.asd

After this you can start emacs and start slime (ESC-x slime RET). Split the display with
C-x 2 and find the hunchen.lisp file with C-x C-f. Then type C-c C-k and finally one can open the http://localhost:4242/first page.

Written by grault

June 3, 2007 - 2:20 pm at June 3, 2007 - 2:20 pm

without comments

Written by grault

May 12, 2007 - 4:02 pm at May 12, 2007 - 4:02 pm