: ) wonderful world ( :

the metasyntactic variable

Archive for October 2006

without comments

In the Examples section of the Revised5 Report on the Algorithmic Language Scheme there is a Runge-Kutta solver of Ordinary Differential Equations (ODEs). Here comes an example of usage of that stuff.

Let’s solve the ODE y’=y with initial value y(0)=1. The analytic solution is exp(x):

(define rk
  (integrate-system (lambda (y) y)
                    #(1)
                    .001))

(define prefix
  (lambda (n stream)
    (let loop ((i n) (v '()) (sys stream))
      (if (= i 0)
          v
          (loop (- i 1)
                (cons (head sys) v)
                (tail sys))))))

(define sol
  (prefix 1001 rk))

For the numeric solution’s last value:

> (car sol)
#(2.7182818284590247)
> (exp 1)
2.718281828459045
> (abs (- (exp 1) (vector-ref (car sol) 0)))
2.042810365310288e-014
>

Written by grault

October 30, 2006 - 11:21 pm at October 30, 2006 - 11:21 pm

without comments

Written by grault

October 27, 2006 - 11:38 am at October 27, 2006 - 11:38 am

without comments

To extract the text from a textbox on Symbian:

_LIT(title,"Information");
CCknInfoDialog::RunDlgLD(title, iRichText->Read(0));

Written by grault

October 27, 2006 - 11:34 am at October 27, 2006 - 11:34 am

without comments

To collect files with some defined extension form a directory, use statement

LIST = [ GLOB . : *.ext ] ;

Written by grault

October 27, 2006 - 1:16 am at October 27, 2006 - 1:16 am

without comments

I searched a lot for some tutorial on jam for make-users. Specially I wanted jam to acts like make when one use rules like

%.ext1 : %.ext2
        SOMETOOL $< $@

but without success. Now I’d like to present a Jamfile-segment for this purpose

actions SOMETOOLAction
{
  SOMETOOL $(2) $(1) ;
}

rule SOMETOOLRule
{
  Depends all : $(1) ;
  Depends all : $(2) ;

  Clean clean : $(1) ;

  SOMETOOLAction $(1) $(2) ;
}

VAR = file1 file2 file3 ;

for _i in $(VAR)
{
  SOMETOOLRule $(_i).ext2 : $(_i).ext1 ;
}

which made with a lot of effort…

Written by grault

October 27, 2006 - 12:46 am at October 27, 2006 - 12:46 am

without comments

My very first PLT servlet:

(require (lib "unitsig.ss")
         (lib "servlet-sig.ss" "web-server"))

(unit/sig ()
  (import servlet^)

  (define (f y)
    (* y 2))

  (send/finish
   `(html
     (body
      (p "the answer:")
      (p ,(number->string
           (f (string->number
               (extract-binding/single
                'num
                (request-bindings
                 (send/suspend
                  (lambda (k-url)
                    `(html
                      (body
                       (form
                        ((action ,k-url))
                        (input ((type "text")
                                (name "num")
                                (id "num")))
                        (input ((type "submit"))))))))))))))))))

Written by grault

October 26, 2006 - 5:24 pm at October 26, 2006 - 5:24 pm

without comments

If

assert(q0);
s0;
assert(r);

and

assert(q1);
s1;
assert(r);

then

assert(q0 || q1);
if(q0) s0; else s1;
assert(r);

Written by grault

October 24, 2006 - 4:53 pm at October 24, 2006 - 4:53 pm

without comments

If one have

s1;
if(pi)
{
  s0;
  s1;
}

and s1 is huge, than

c=1;
while(c!=3)
{
  s1;
  if(c==1)
  {
    if(pi)
    {
      c=2;
      s0;
    }
    else
    {
      c=3;
    }
  }
  else
  {
    c=3;
  }
}

can solve the problem.

Written by grault

October 24, 2006 - 4:48 pm at October 24, 2006 - 4:48 pm

without comments

Once upon a time i decided to separate a given functionality of class B and implement it in a class A, and finally inherit B from A. Everything went fine, but i had a selector in B which returned a new instance of B. It was part of that naughty functionality set to move. So this method was changed to return an instance of A. During compilation i recognized: i have a function with a parameter of type B and i call it with a result of that selector. :)

Written by grault

October 5, 2006 - 10:26 am at October 5, 2006 - 10:26 am

without comments

Hi,

If one make the files below:

login09% cat trafo.scm

(define (trafo fn)
  (with-input-from-file
    fn
    (lambda ()
      (let loop ((c (peek-char)))
        (if (eof-object? c)
          '()
          (begin
            (if (char=? #\( c)
              (eval (read))
              (write-char (read-char)))
            (loop (peek-char))))))))

login09% cat trafo.sh
#!/usr/bin/zsh
guile -l trafo.scm -c "(trafo \"$1\")" > $1.tex
login09%

then he can mix the scheme code with the latex (with some limitations). Like this:

login09% cat prob.scm
\documentclass{article}
\usepackage{pstricks}
(define (L) (display "("))
(define (R) (display ")"))

\begin{document}
\begin{pspicture}(L)10,10(R)
(define pts
  '((1 1)
    (2 3)
    (4 5)
    (4 3)))%
(define (dotgen c)
  (begin
    (display (string-append "\\psdots("
                            (number->string (car c))
                            ","
                            (number->string (cadr c))
                            ")%"))
    (newline)))%
(map dotgen pts)%
\end{pspicture}

\end{document}
login09% ./trafo.sh prob.scm
login09% cat prob.scm.tex
\documentclass{article}
\usepackage{pstricks}

\begin{document}
\begin{pspicture}(10,10)
%
%
\psdots(1,1)%
\psdots(2,3)%
\psdots(4,5)%
\psdots(4,3)%
%
\end{pspicture}

\end{document}
login09%

The only problem is the usage of the parens in tex code.

Written by grault

October 4, 2006 - 5:27 pm at October 4, 2006 - 5:27 pm