I want to use keyword "return" to return value for a function but I got a runtime error
I can only successfully return value as below. However, the function will not "end directly" after if condition == true at line #3.
Could someone give a hint how to use "return" keyword correctly?
AutoLISP does not have a return
function.
You would need to structure your code such that the remainder of the code is evaluated as part of the else
argument for the if
statement, e.g.:
(defun findLastDigitIndex ( str startIdx / char )
(setq char (substr str startIdx 1))
(if (or (< (ascii char) 48) (> (ascii char) 57))
nil
(progn
;; do stuff
)
)
)
But I might write the function as follows:
(defun findLastDigitIndex ( str startIdx / dif )
(setq str (substr str startIdx)
dif (- (strlen str) (length (vl-member-if-not '(lambda ( a ) (< 47 a 58)) (vl-string->list str))))
)
(if (< 0 dif) (+ startIdx dif -1))
)