I see several small things:
- The
loop syntax is not 100% correct, you missed a do keyword
(loop while (< k i) do (setq k (1+ k)))
^^
do keyword is missing!
- The syntax for the function call
promising(2) is also incorrect
(promising 2)
- The
return-from thing is unusual
The first reason is that the return value is always 1, in your case, you probably want to return k.
(DEFUN promising (i)
(setq k 1)
(loop while (< k i) (setq k (1+ k)))
(return-from promising 1))
^
Always return 1
The second reason is you don't need a return-from, the last value of a defun form will be given to the function caller.
(DEFUN promising (i)
(setq k 1)
(loop while (< k i) do (setq k (1+ k)))
k)
^
The last value will be returned to the function caller
- The
k variable should be defined locally and not use a global definition
The final code could be something like this:
(defun promising (i)
(let ((k 1))
(loop while (< k i) do (setq k (1+ k)))
;; return value
k))
(promising 2)
This should return:
2