(mymachine (
(defmacro demoinside (expr)
(print expr)
)
(defmacro mymachineinside (exprs)
`(if ,(eq exprs nil)
nil
(progn
(demoinside ,(car exprs))
(mymachineinside ,(cdr exprs) )
)
)
)
(mymachineinside (
(defmacro demo (expr)
(print expr)
)
(defmacro mymachine (exprs)
`(if ,(eq exprs nil)
nil
(progn
(demo ,(car exprs))
(mymachine ,(cdr exprs) )
)
)
)
(defun mycons ( x y)
(lambda (p ) (funcall p x y) )
)
(defun mycar (n)
(funcall n (lambda( x y) x) )
)
(defun mycdr (n)
(funcall n (lambda( x y) y) )
)
(defun mycadr (n)
(mycar (mycdr n) )
)
(defun printlst (n)
(if (eq n nil)
nil
(progn
(print (mycar n) )
(printlst (mycdr n) )
)
)
)
(defun emerge (x y)
(if (eq x nil)
y
(if (eq y nil )
x
(if (> (mycar x ) (mycar y) )
(mycons (mycar y) (emerge x (mycdr y) ) )
(mycons (mycar x ) ( emerge (mycdr x) y ) )
)
)
)
)
(defun ptr ( x num )
(if (eq num 0)
x
(ptr (mycdr x ) (- num 1 ) )
)
)
(defun myget (x count )
(if (eq count 0)
nil
(mycons (mycar x) (myget (mycdr x ) (- count 1) ) )
)
)
(defun divi (x num )
(if (eq num 2)
(if (> (mycar x ) (mycadr x) )
(mycons (mycadr x ) (mycons (mycar x) nil) )
x
)
(emerge (divi (myget (ptr x 0 ) (/ num 2) ) (/ num 2) )
(divi (myget (ptr x (/ num 2) ) (/ num 2 ) ) (/ num 2) ) )
)
)
(setq y (mycons 23 (mycons 345 nil) ) )
(printlst (divi y 2) )
(setq y (mycons 345 (mycons 23 nil) ) )
(printlst (divi y 2))
(setq y (mycons 345 (mycons 23 (mycons 10 (mycons 89 (mycons 34 (mycons 2 (mycons 77
(mycons 864 nil)))))))))
(printlst (divi y 8) )
(setq z (mycons 23 (mycons 34 (mycons 11 (mycons 98 (mycons 456 (mycons 875 (mycons 76
(mycons 21 nil)))))))))
(printlst (divi z 8) )
))
))