(define (return x) x)
Gives me a self-documenting way of avoiding both catch, throw and eval as well. Please criticize?
How would that be used for that?
Like this
(define (parse-pawn-move s n)
(filter on-board?
(if (black-to-move? n)
(let (lst (list (next-diagl s)(next-diagr s)(next-row s)))
(if (= "6" (row s))
(append lst (list (next-row (next-row s))))
(return lst)))
(let (lst (list (prev-diagl s)(prev-diagr s)(prev-row s)))
(if (= "4" (row s))
(append lst (list (prev-row (prev-row s))))
(return lst))))))
This does the same thing:
(define (parse-pawn-move s n)
(filter on-board?
(if (black-to-move? n)
(let (lst (list (next-diagl s)(next-diagr s)(next-row s)))
(if (= "6" (row s))
(append lst (list (next-row (next-row s))))
lst))
(let (lst (list (prev-diagl s)(prev-diagr s)(prev-row s)))
(if (= "4" (row s))
(append lst (list (prev-row (prev-row s))))
lst)))))
Why yes it does. Too much of non-functional approach. It at least worked; but yours requires less typing and one less function call.
Return doesn't make sense in newlisp. The value of a call is the value of the last expression evaluated.
Hmmm, pretty sweeping statement there. That would imply that the idomatic use of catch and throw is never needed as well. I also remember seeing return in Common Lisp (granted as a macro), so while your statement is true for newLISP at least someone else found the need. I vaguely remember that MuLisp had one but I wouldn't swear to it. It was my first lisp back in the 80's (for an 8-bit machine) and I wrote several math packages for it--- seems like a 'return' would have been handy, but memory fades. Quote
The value of a call is the value of the last expression evaluated.
Speaking of memory, thank you for reminding me of this little detail. And least I be accused of being original, here is a quote from Guy L. Steele Jr.Quote
This function is occasionally useful as an argument to other functions that require functions as arguments (Got that?)
Kinda weak I'll admit--- but hey, what can I say!
Quote
That would imply that the idomatic use of catch and throw is never needed as well.
That's not the same thing. If I want to break a loop:
(set 'foo (catch (dotimes (i 10) (if (= i 5) (throw i)))))
That will give me 5. Catch also let's you work around error-prone routines (although many built-ins return nil and an error function in these cases).