Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: strange any behaviour
Pages: [1] Print
Author Topic: strange any behaviour  (Read 286 times)
pepiporn
Newbie
*
Offline Offline

Posts: 8


View Profile
strange any behaviour
« on: December 02, 2004, 08:19:31 AM »

from the rebol console:

>> ? any
USAGE:
    ANY block

DESCRIPTION:
     Shortcut OR. Evaluates and returns the first value that is not FALSE or NONE.
     ANY is a native value.

ARGUMENTS:
     block -- Block of expressions (Type: block)
>> (= a "hugo") or (= a "hombo")
== true
>> a: "foo"
== "foo"
>> = a any [ "foo" "bar" ]
== true
>> = a any [ "bar" "foo" ]
== false
>> (= a "bar") or ( = a "foo" )
== true
>> (= a "foo") or ( = a "bar" )
== true

----

hm i would an expression that claims itself to be a shortcut to OR to have the same behaviour as OR but as you see it hasnt.

how to do it instead (if you figured out what i want)
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
strange any behaviour
« Reply #1 on: December 03, 2004, 12:53:29 AM »

You've misunderstood how ANY is used.  In your examples, this is what ANY's returning...

>> any ["foo" "bar"]
== "foo"
>> any ["bar" "foo"]
== "bar"

Values are considered true unless they're a NONE or FALSE.

So your....

>> = a any [ "foo" "bar" ]
>> = a any [ "bar" "foo" ]

reduces to...

>> = a "foo"
>> = a "bar"

Here's the correct conversion of your example to ANY...

>> any [(= a "bar") (= a "foo")]
== true
>> any [(= a "foo") (= a "bar")]
== true
>> any [(= a "bar") (= a "foot")]
== none

Hope that helps.
 
Logged

- Carl Read
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
strange any behaviour
« Reply #2 on: December 03, 2004, 03:54:45 AM »

Just a couple stylistic considerations:

1) If you prefer prefix syntax rather than infix, use equal? instead of =; that way it's much more readable.
Code:
any [equal? a "foo" equal? a "bar"]

2) Don't use too many parens, when you don't really need them. You don't need parens if you use equal? or = infix.
Code:
any [a = "foo"  a = "bar"]

3) Your example is probably better written as:
Code:
found? find ["foo" "bar"] a
(with found? only needed if you really want the reault to be a logic! value).
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: strange any behaviour
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 20, 2008, 08:14:37 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2286 Posts in 595 Topics by 3710 Members
Latest Member: Nqvyxwid

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc