cesky while1 - site about programming

LISP

sum_g + linear list sum
(defun sum_g(sequence) (cond ( (null sequence) 0 ) ( T (+ (car sequence) (sum_g (cdr sequence)) ) ) ) )
monot_up + subfunction for func. monot + test for nondescending linear list
(defun monot_up(sequence) ( cond ( (null sequence) nil ) ( (null (cdr sequence)) T ) ( (<=(car sequence)(cadr sequence))(monot_up (cdr sequence))) ) )
monot_down + subfunction for func. monot + test for nongrowing linear list
(defun monot_down(sequence) ( cond ( (null sequence) nil ) ( (null (cdr sequence)) T ) ( (>=(car sequence)(cadr sequence))(monot_down (cdr sequence))) ) )
monot + test for nondescending or nongrowing linear list progression + according to parameter rising : rising == 0 ... for nongrowing rising != 0 ... for nondescending
(defun monot (rising sequence) ( cond ( (zerop rising) (monot_down sequence) ) ( T (monot_up sequence) ) ) )
list_g + connection for func. reverse
(defun list_g(L1 L2) (cond ( (and (null L1)(atom L2)) (list L2) ) ( (null L1) L2 ) ( (and (atom L1)(atom L2)) (append (list L1) (list L2)) ) ( (atom L1) (append (list L1) L2 ) ) ( (atom L2) (append L1 (list L2)) ) (T (cons (car L1) (list_g (cdr L1) L2)) ) ) )
reverse_g + common list reverse
(defun reverse_g(sequence) ( cond ( (null sequence) nil ) ( (atom (car sequence)) ( list_g (reverse_g (cdr sequence)) (car sequence) )) ( T ( append (reverse_g (cdr sequence)) (list (reverse_g (car sequence))) )) ) )
sum_x + vector sum of two linear lists
(defun sum_x(mx1 mx2) (cond ( (or (null mx1)(null mx2)) nil ) ( (null (cdr mx1)) (list (+ (car mx1)(car mx2)) ) ) ( T (cons (+ (car mx1)(car mx2)) (sum_x (cdr mx1)(cdr mx2)) ) ) ) )
sum_m + matrix sum
(defun sum_m (width1 height1 width2 height2 matrix1 matrix2) (cond ( (or (null matrix1)(null matrix2)) nil ) ( (null (cdr matrix1)) (list (sum_x (car matrix1)(car matrix2)) ) ) ( T (cons (sum_x (car matrix1)(car matrix2)) (sum_m 1 1 1 1 (cdr matrix1)(cdr matrix2)) ) ) ) )
radek + returns value of index-th linear list element or nil if index is out of bound (> length)
(defun radek (index sequence) (cond ( (null sequence) nil ) ( (zerop index) (car sequence) ) ( T (radek (- index 1) (cdr sequence)) ) ) )
pole + returns matrix value on [x,y] (0..n) 0 1 x +-------> '((1 2) (3 4)) 0 | (1 2) 1 | (3 4) y | v
(defun pole (x y sequence) (cond ( (null sequence) nil ) ( (zerop y) (radek x (car sequence)) ) ( T (pole x (- y 1) (cdr sequence)) ) ) )
Contact
Accesibility
Print this page
Author: Vaclav Bubnik © 2005
vbubnik@post.cz