[REBOL] two-digit return of now switches Re:(3)

2000-05-09 Thread icimjs

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  [: - )]




[REBOL] two-digit return of now switches Re:(3)

2000-05-09 Thread agem



Note precedence in rebol works funny :)

 if 2  length? month  [insert month "0"]

you need a single argument on the left, ut on the right can 
be a whole call. 
2  1 + 3 ;works not, 
2  add 1 3 ;works
2  + 1 3 ; works too

Volker

 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"]
 
 How come?
 
 
   if (length? tmp: to-string now/day)  2 [insert tmp "0"]
 
 
 




[REBOL] two-digit return of now switches Re:(3)

2000-05-09 Thread norsepower

Ah, yes, thanks for the recommendation.

I am also including a wait statement in my foreach statement since I 
may be naming more than one file in a session. No sense naming two 
files within the same span of a second thus using the same name. 8-)

I'd recommend using only one "now" statement, since theoretically it's
possible that we call the first "now" at say 23:59:59.99 at 31 of 
December
2000. Then maybe the first statement takes some fraction of a second, 
so
the second "now" gets the date-time of 00:00:00 at 1 Jannuary 2001. 
Then it
rejoins this to.. 210100 when it should have been 
20001231235959 or
2001010100 - one year wrong. Oops.