abc(x)
(abc x)
1 + 2 * 3 - 5
(- (+ 1 (* 2 3)) 5)
def fib(x)
if (x < 3) then
1
else
fib(x-1)+fib(x-2);
(defun fib (x)
(if (< x 3)
1
(+ (fib (- x 1)) (fib (- x 2)))) )
def foo(x)
if (x < 3) then
1;
else
foo(x-1)
foo(x-2);
var y = 1;
cons a, y;
while i < y do
i + y
y + a;
end;
(defun foo( x )
(if (< x 3)
1
(progn
(foo(- x 1))
(foo(- x 2))
)
)
(setq y 1)
(cons a y)
(while (< i y)
(+ i y)
(+ y a)
)
)
Code - Auto/Visual Lisp: [Select]
Well then, give me two minutes and you shall have some to view. *smile*
First: Kaylee
Second: Autolisp
Code - C++: [Select]
def replace(aList position newItem) if (null(aList)) then if (position > 0) then cons car(aList), (replace(cdr(aList), (position - 1), newItem)) else cons newItem, cdr(aList) end;Code - Auto/Visual Lisp: [Select]
) ) )
Awesome! Thank you for the adjustment.
> (Completely guessing at the pseudo code)
You're a natural! Your code produced exactly what you wanted it to.
1 + 2 - 4 * 5 - 1
Would produce this:Current offering:Code - Auto/Visual Lisp: [Select]
_$ (replace2 '(1 2 3 3 2 1) 3 4)
(1 2 4 4 2 1)
(defun replace3 ( alist position newitem / i )
(setq i -1)
(mapcar '(lambda ( x ) (if (= position (setq i (1+ i))) newitem x)) alist)
)
However, note that subst will replace all occurrences of an item:
if null(aList) then
...
Would strictly be translated in Lisp to(if (null aList)
...
However Python disallows this non-standard comparison, e.g. a direct translation would beif null = aList
...
In both Lisp and Python its recommended to use the idea that an empty list evaluates to false. So the more "correct" translation would be(if (not aList)
...
if not aList
...
if null(aList) then
... do whatever is required when the list is empty;
else
... do whatever's to be done with a list containing at least one value;
Translated to lisp:(if aList
(... do whatever's to be done with a list containing at least one value)
(... do whatever is required when the list is empty)
)
Which makes the back-translation even more problematic. You either need to re-arrange the if portions, which you can't always do since there may not be an else portion. Or you need to change the (if aList intoif not (null (aList)) then