Maybe this coding style is just too confusing? :evil:
Note that because of all the setq's and the use of recursion the code will not be particularly fast.
Try a tail-recursive syntax.
Should "recursive annonymous function" be a more appropriate name? :tongue2:compare
(setq from_right 1 from_left 2)
((setq from_right (lambda (L)
(if (print (setq L (reverse (cdr (reverse L)))))
(from_left L)
(setq from_right nil
from_left nil
)
)
)
from_left (lambda (L)
(if (print (setq L (cdr L)))
(from_right L)
(setq from_left nil
from_right nil
)
)
)
)
'(1 2 3 4 5 6 7 8 9)
)
(print from_right)
(print from_left)
with(setq from_right 1 from_left 2)
((lambda (L from_right from_left) (from_left L))
'(1 2 3 4 5 6 7 8 9)
(lambda (L)
(if (print (setq L (reverse (cdr (reverse L)))))
(from_left L)
)
)
(lambda (L)
(if (print (setq L (cdr L)))
(from_right L)
)
)
)
(print from_right)
(print from_left)
Should "syntax masturbation" be a more appropriate name?
My point actually is that by condensing the code to fit on a limited number of lines you are confusing yourself, let alone the readers of your code. Just look at your (repeat ...) expression.Maybe this coding style is just too confusing? :evil:Yes - it looks confusing
(defun factorial (n)
(if (= n 1)
1
(* n (factorial (- n 1)))))
Command: (factorial 5)
Entering (FACTORIAL 5)
Entering (FACTORIAL 4)
Entering (FACTORIAL 3)
Entering (FACTORIAL 2)
Entering (FACTORIAL 1)
Result: 1
Result: 2
Result: 6
Result: 24
Result: 120
120
(defun factorial (n)
(fact-iter 1 n))
(defun fact-iter (product n)
(if (< n 2)
product
(fact-iter (* product n)
(- n 1))))
Command: (factorial 5)
Entering (FACTORIAL 5)
Entering (FACT-ITER 1 5)
Entering (FACT-ITER 5 4)
Entering (FACT-ITER 20 3)
Entering (FACT-ITER 60 2)
Entering (FACT-ITER 120 1)
Result: 120
Result: 120
Result: 120
Result: 120
Result: 120
Result: 120
No it's not (from what I remember).
Why isn't it optimized? ...*shrug* I don't have any more knowledge of the inside workings of the interpreter than you do (any more then observations).No it's not (from what I remember).
Why?
Why isn't it optimized? ...*shrug* I don't have any more knowledge of the inside workings of the interpreter than you do (any more then observations).No it's not (from what I remember).
Why?