Tuesday, August 17, 2010

Bubble sort program in Arc, a dialect of LISP

Wrote a bubble sort program using Arc just to have a try of this Lisp dialect.

试着用Arc,Lisp的一种方言,写了一个冒泡排序程序。

試しに、Lispの一種、Arcを使ってバッブルソートプログラムを書いてみました。

-------------------------------
Use (quit) to quit, (tl) to return here after an interrupt.
arc> (def mn (s m)
     (if (no s) m
       (< (car s) m) (mn (cdr s) (car s))        (mn (cdr s) m))) arc> #
arc> (def bsort (s)
     (if (no s) nil
       (let x (mn s (car s))
 (cons x
       (bsort (rem [is _ x] s))))))
#
arc> :a
> (require (lib "trace.ss"))
> (trace _mn)
(_mn)
> (tl)
Use (quit) to quit, (tl) to return here after an interrupt.
arc> (bsort '(2 1 9 3))
|(_mn (2 1 9 3 . nil) 2)
|(_mn (1 9 3 . nil) 2)
|(_mn (9 3 . nil) 1)
|(_mn (3 . nil) 1)
|(_mn nil 1)
|1
|(_mn (2 9 3 . nil) 2)
|(_mn (9 3 . nil) 2)
|(_mn (3 . nil) 2)
|(_mn nil 2)
|2
|(_mn (9 3 . nil) 9)
|(_mn (3 . nil) 9)
|(_mn nil 3)
|3
|(_mn (9 . nil) 9)
|(_mn nil 9)
|9
(1 2 3 9)