Ok so I am pretty fresh to programming, as you will see from my question. I know lisp uses lexical scoping and understand sequential statement thinking will not work. As a note: I have read a little bit about macros, but have not used them...haven't gotten to tail-recursive functions yet nor closures.... so far I'm just playing around with basic logic and syntax.... After playing for a bit I noticed my "set x" functions were clobbering each other...so I started converting all my function to use "let" statements. Most are working, but I have one function that I am struggling to make work. I understand why it doesn't work: because my lets don't know anything about each other under the lexical scope regime. I've re-written the function about 10 times re-working the logic, but so far I haven't got it working. I'm guessing I need to use an anaphoric operation like "aif", but maybe not.... Simplified (thus don't ask why): (def ugh (string)
(set x 5.0)
(for i 0 (- (len string) 1) (set v (/ 12 (+ i 1)))
(if (is "A" (cut string i (+ i 1)))
(set x (trunc (+ x v)))
(set x (trunc (- x v)))i))x) (ugh "ABABABABAB") result = 10 how do I change this so that I am not using "sets" ? Thanks in advance. |