Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

First CLISP functions of a babby

Name: EXPERT BABBY 2011-01-22 16:41

Hey /prague/,
what do you think of my first functions? Do you think i am corrupted by the procedural paradigm already?


(defun factorial (a)
    "Calcula el factorial de a"
    (if (< a 1)
        1
        (* a (factorial (- a 1)))))

(defun get-n-elements (a n)
    "Crea una lista con los n primeros elementos de a,
    si a tiene menos de n elementos, rellena los elementos
    restantes con NIL"
    (cond
        ((<= n 0) nil)
        (T (append (list (car a)) (get-n-elements (rest a) (- n 1))))))
       

(defun get-n-to-m-elements (a n m)
    "Crea una lista con los elementos entre n y m de a"
    (cond
        ((not a) nil)
        ((> n m) (get-n-to-m-elements a m n))
        (T (reverse (get-n-elements (reverse (get-n-elements a m)) (+ (- m n) 1))))))

Name: Anonymous 2011-01-23 0:08

>>30
it sure beats being an idiot all along *hint hint*

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List