Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Can I define an anti function?

From: andreas:bolka:gmx at: 24-Feb-2004 13:53

Monday, February 23, 2004, 8:55:15 PM, Ladislav wrote:
> Question: Is the guess about Rebol correct? (I will post my answer > later)
I'll second Gabriele's answer: The reasoning seems to be intriguing at first glance, but it's (at least partly) wrong. A (naive) demonstration: anti: func [ f ] [ func first :f compose [ not (second :f) ] ] f: func [ a b ] [ = a b ] anti-f: anti :f f 1 2 ; == false anti-f 1 2 ; == true The above obviously does not cope with functions where 'return is used, however I'm not going into more detail here, as I'm really looking forward to Ladislav's answer (which will be more correct than mine could ever be, anyway). But let me explain why I weakened my above statement with 'at least partly'. In Scheme the following is perfectly legal: (define (anti f) (lambda args (not (apply f args)))) (define (f a b) (equal? a b)) ((anti f) 1 2) ; == #t In REBOL however, my naive approach given above would not give the desired results in this case (anti :f 1 2), as anti :f does not return a "loaded" function, i.e. we'd have to force it's application by using 'do:
>> do anti :f 1 2
== true
>> do anti :f 1 1
== false In my opinion, that is the perfect REBOL equivalent to the special Scheme form used above. However, Scheme purists may argue with me on that point :) Nevertheless, even in Scheme, I imagine the "typical" use of anti would be: (define anti-f (anti f)) -- Best regards, Andreas