axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] any?, member?, ...


From: Martin Rubey
Subject: [Axiom-developer] any?, member?, ...
Date: Wed, 23 Jun 2004 16:00:12 +0000

I noticed that these function evaluate the predicate for all elements of the
argument list, which I find rather strange. For example:

(2) -> any?(i+->(output(i);(i=1)::Boolean),[1,2,3])
   1
   2
   3

   (2)  true
                                                                Type: Boolean

Wouldn't it be sensible to define these functions so that they exit when the
result is determined, i.e., instead of

     any?(f, c)           == _or/[f x for x in parts c]
     every?(f, c)         == _and/[f x for x in parts c]

do

     any?(f, c) ==
       for x in parts c repeat
         if f x then return true
       false
       
     every?(f, c) ==
       for x in parts c repeat
         if not f x then return false
       true

It seems that for TREE, some shortcircuiting is done:

    any?(fn, t) ==  ---bug fixed
      t case empty => false
      fn value t or "or"/[any?(fn, c) for c in children t]
    every?(fn, t) == 
      t case empty => true
      fn value t and "and"/[every?(fn, c) for c in children t]

Martin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]