Question: LISP SBCL Command line arguments. Need help to modify the function to accept 2 arguemtns, the second being the max random number: (defun randlist (n)
LISP SBCL Command line arguments.
Need help to modify the function to accept 2 arguemtns, the second being the max random number:
(defun randlist (n)
(let ((lst ()))
(dotimes (i n)
(setf lst (cons (random 1000) lst)))
lst))
(print (quicksort (randlist (parse-integer (nth 1 sb-ext:*posix-argv*)))))
Full prog--
#!/usr/bin/sbcl --script
(defun quicksort (lst)
(cond
((null lst) nil)
(t
(append
(quicksort (left (car lst) (cdr lst)))
(cons (car lst) nil)
(quicksort (right (car lst) (cdr lst)))))))
(defun left (a b)
(cond
((or (null a) (null b)) nil)
((< a (car b)) (left a (cdr b)))
(t (cons (car b) (left a (cdr b))))))
(defun right (a b)
(cond
((or (null a) (null b)) nil)
((>= a (car b)) (right a (cdr b)))
(t (cons (car b) (right a (cdr b))))))
(defun randlist (n)
(let ((lst ()))
(dotimes (i n)
(setf lst (cons (random 1000) lst)))
lst))
(print (quicksort (randlist (parse-integer (nth 1 sb-ext:*posix-argv*)))))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
