Sorry, but I did not make myself clear. Mapping 'true?' over the list will *not* help, since I am trying to do something akin to Lutz's example:
However, by analogy, my usage would look like:
Code: Select all
(set 'foo (or (returns-a-list-or-nil) '()))
so that 'foo' would be guaranteed to be a list (even if the empty list).
Now, I could go the macro workaround which I did (lest I stop hacking newlisp -- perish the thought :-). I actually went the route of nikus80:
Code: Select all
(define-macro (myor)
(catch
(dolist (a (args))
(let (v (eval a))
(if v (throw v))))))
> (myor nil 42)
42
> (myor nil '())
()
And this is exactly what I want.
However, I'd like to appeal to Lutz to change the behavior of the intrinsic 'or' to that of 'myor' defined above. That is, 'or' should be defined as
(or e1 e2 ... eN)
returns the first true value encountered in the list (e1 e2 ... eN-1), as each element is evaluated in turn, from left to right. If none evaluates to a true value, return the value of eN.
Another way to think of it is that in
we have lost a piece of information we could potentially use, namely the '(). The better implementation of 'or' is one which preserves this information. For this reason '(or nil 42)' does not currently return 'true' -- it returns 42, as it should.
Now, if 'or' is implemented in the manner described, it will not change its boolean interpretation[*], but will gain the added benefit of using any value's normal interpretation in subsequent (or surrounding) non-boolean expressions. (The implementation of 'and' should also be similarly re-aligned.) Of course, you could tell me to sod off and I'd still have my macro but I think this software change request will improve the newlisp core in a positive way.
Thanks!
--Rick
[*] -- Note that any value seems to have two interpretations, a normal one and a boolean one. For instance, when evaluated, the expression '42' has a normal interpretation of the integer 42 and a boolean interpretation of true, A "true value" is any value that has a boolean interpretation of true, i.e. 'e' is a "true value" if the expression '(if e 1 0)' evaluates to 1. For instance, 42 is a "true value". Additionally, 'true' is a true value.