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-22 21:07

>>16
No, but if you want lazy support, there are plenty of libraries which provide it. Lisps tend not to be lazy by default like ML or Haskell, but support for lazyness is usually provided in libraries (it's not hard to implement it by yourself either).

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