Another option for FOR-ALL?

Q&A's, tips, howto's

Another option for FOR-ALL?

Postby JeremyDunn » Fri May 07, 2010 3:41 am

I would suggest generalizing FOR-ALL further to handle a list of test conditions as well as a single condition. There would also be an optional argument at the end where the user would define which logical operation is to be performed with all of the test conditions. The default for the optional argument would be the AND function. So

(for-all '(integer? zero?) '(0 0 0)) is the same as
(for-all '(integer? zero?) '(0 0 0) and)

this returns true if all members of the list satisfy all of the test conditions. If we wrote

(for-all '(integer? zero?) '(0 1 2) or)

this returns true if any of the test functions apply. Here is a sample implementation of the function:
Code: Select all
;; New FOR-ALL
(define (forall test lst (op and))
  (if-not (list? test)
     (for-all test lst)
     (apply op (map for-all test (dup lst (length test))))))
Posts: 11
Joined: Wed Apr 07, 2010 12:18 am

Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest