0

I thought there was a built in method for determining whether all / any members of a list satisfied a predicate test, but searching the documentation for lists, as well as searching the index for any of the keywords (at least those I could think of) didn't turn up anything.

I wrote a function that basically achieves this:

/* true_false allows one to specify whether to check for any "true" results or any "false" results */ 
any_list_member(aList, predicate_test, true_false):=
  block(
        [ aList:aList, 
          predicate_test:predicate_test, 
          true_false:true_false, 

          length_of_aList:length(aList),
          predicate_test_results
        ],

      predicate_test_results:map('predicate_test, aList), 

      if member(true_false, predicate_test_results)
      then true   
      else false  
  );

but generally prefer to rely on native Maxima scripts, as I don't have much experience programming, so work with the assumption that official scripts will be much more robust than my own :)

Is there a built in method for achieving this? If not, any suggestions for improved implementation are welcome and appreciated.

Rax Adaam
  • 790
  • 3
  • 11
  • 1
    Take a look at `some` and `every`. It's kind of funny that the terminology varies from one language to another ... I've seen equivalent functions named `any` and `all`, there are probably other variations. – Robert Dodier Oct 13 '21 at 21:28
  • Thanks Robert -- I also seem to struggle with the organization of the documentation: I looked under everything I could think of, but am still figuring out the logic (but it does feel like there's progress :D). Hope all's well on your end! – Rax Adaam Oct 14 '21 at 23:37
  • Yeah, it's not easy to find something in the documentation unless you know its name ... the maxima-discuss mailing list is probably the best forum for questions like that. Well, I guess it's true that Stackoverflow worked out fine in this case. – Robert Dodier Oct 15 '21 at 04:46

0 Answers0