Could anyone help me with kinda my kinda clueless fumbling? ^_^; (I'm kinda new to the whole programming thing.)
I was thinking that it'd be kinda neat to be able to take the data from my school work and run correlation tests on everything against everything. I'm trying to implement quicksort as the first step in doing that.
Anyway, first I tried writing it out like this:
Code: Select all
(defun test (lst)
(let ((pivot (car lst))
(smaller-than (remove-if (< pivot) lst) )
(larger-than (remove-if (> pivot) lst) ))
(setf pivot (cons (test smaller-than) pivot))
(cons pivot (test larger-than))))
Code: Select all
warning:
undefined variable: PIVOT
--> PROGN
==>
(THE REAL PIVOT)
I did think maybe you weren't allowed have one definition in let dependent on something else in the let. Which seems supported by a quick test in the REPL:
Code: Select all
(let (
(x 1)
(y (+ x 1))))
; in: LET ((X 1) (Y (+ X 1)))
; (LET ((X 1) (Y (+ X 1)))
; )
;
; caught STYLE-WARNING:
; The variable X is defined but never used.
;
; caught STYLE-WARNING:
; The variable Y is defined but never used.
; in: LET ((X 1) (Y (+ X 1)))
; (+ X 1)
;
; caught WARNING:
; undefined variable: X
Code: Select all
(defun test (lst)
(defvar pivot (car lst))
(defvar smaller-than (remove-if (< pivot) lst) )
(defvar larger-than (remove-if (> pivot) lst) )
(setf pivot (cons (test smaller-than) pivot))
(cons pivot (test larger-than))))
Code: Select all
warning:
undefined variable: PIVOT
--> PROGN
==>
(THE REAL PIVOT)
warning: undefined variable: SMALLER-THAN
Did think I might not understand how defvar was used but this works:
Code: Select all
(defvar x (car '(1 2)))
=> X
X
=> 1
SBCL if that's relevant.
Thanks! Apologies if this is in the wrong place ^_^