If you hate parentheses, you can use the prefix property of <

>> <  length? "123" 10
== true
>>
but it must be the first op on a line, or otherwise be preceded by a (  {and
a corresponding closing ) must follow somewhere}

Russell [EMAIL PROTECTED]
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 08, 2000 10:06 PM
Subject: [REBOL] two-digit return of now switches Re:(3)


> Hi RChristiansen,
>
> you wrote:
> >This doesn't work...
> >
> >month: to-string now/month
> >if (length? month < 2) [insert month "0"]
> >
> >** Script Error: Expected one of: string! - not: integer!.
> >** Where: if (length? month < 2) [insert month "0"]
>
> Try:
>
> >> if (length? month) < 2 [insert month "0"]
> == "5"
>
> >How come?
>
> Since you ask:
>
> 1. < is polymorph:
>
> String comparison:
>
> >> "1" < "2"
> == true
>
> When the left argument to < is of type string, < expects the right
argument
> to be of type string as well.
>
> 2. Precedence:
> The < is evaluated first, then the length? operator. Example:
> >> "123" < "1234"
> == true
> >> length? "123" < "1234"
> ** Script Error: length? expected series argument of type: series port
tuple.
> ** Where: length? "123" < "1234"
>
> What's the complaint? First "123" < "1234" is evaluated and returns true.
> Then length? is applied to true. We are applying length? here to a boolean
> value.
>
> Accordingly, this does not work:
>
> >> length? "123" < 10
> ** Script Error: Expected one of: string! - not: integer!.
> ** Where: length? "123" < 10
>
> Precedence, < is applied before length? Polymorphism, < detects that its
> left argument is a string, and therefore expects the right argument to be
a
> string as well.
>
> But this does work, because we force length? to be applied first and <
> detects an integer left and expects an integer as its right argument:
>
> >> (length? "123") < 10
> == true
>
>
>
> ;- Elan >> [: - )]
>

Reply via email to