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

[REBOL] curious use of LENGTH?

From: joel:neely:fedex at: 31-Jan-2002 7:16

I happened to do SOURCE LIST-DIR this morning, and something caught my eye; at the end of that function is the following excerpt: ... s: make string! 0 foreach file dir [ append s file while [((length? s) // max) <> 0] [append s " "] if (length? s) > 60 [ print s clear s ] ] if length? s [print s] ] I only included so much to get all uses of S (local to LIST-DIR). Notice the last line -- I have no clue what it means in REBOL to use an integer-valued expression as the condition of IF. I tried some small experiments, and in every case IF treated an integer as TRUE (including zero and negative values). I then tried variations on a string value FOO in the phrase IF LENGTH? FOO ... and always got the equivalent of TRUE, regardless of its length. (The only exception was when FOO was UNSET, in which case I got an error...) Any suggestions on why the above wasn't written simply as PRINT S ?? Clearly it's there to flush a partial line at the end of grovelling through the list of file names, but why in the form shown by SOURCE above? -jn- -- ; sub REBOL {}; sub head ($) {@_[0]} REBOL [] # despam: func [e] [replace replace/all e ":" "." "#" "@"] ; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"} print head reverse despam "moc:xedef#yleen:leoj" ;