curious use of LENGTH?
[1/9] 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" ;
[2/9] from: rotenca:telvia:it at: 31-Jan-2002 14:51
Hi Joel,
> s: make string! 0
> foreach file dir [
<<quoted lines omitted: 16>>
> an error...)
>From Core 3-23 about 'if:
The condition is normally an expression that evaluates to true or false;
however,
other values can also be supplied. Only a false or a none value prevents the
block
from being evaluated. All other values (including zero) are treated as true,
and
cause the block to be evaluated.
> Any suggestions on why the above wasn't written simply as
>
> PRINT S
If 's would be empty, it would print a newline.
---
Ciao
Romano
[3/9] from: g:santilli:tiscalinet:it at: 31-Jan-2002 15:23
Hello Joel!
On 31-Gen-02, you wrote:
JN> Notice the last line -- I have no clue what it means in REBOL
JN> to use an integer-valued expression as the condition of IF. I
My guess is that that was written by someone who had spent all the day
coding in C. ;-)
Jeff? Holger? Carl?
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[4/9] from: lmecir:mbox:vol:cz at: 31-Jan-2002 15:32
Hi Joel,
even
while [((length? s) // max) <> 0] [append s " "]
looks unusual to me. I normally use:
insert/dup tail s " " max - ((length? s) // max)
Cheers
Ladislav
----- Original Message -----
From: "Joel Neely" <[joel--neely--fedex--com]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, January 31, 2002 2:16 PM
Subject: [REBOL] curious use of LENGTH?
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" ;
[5/9] from: lmecir:mbox:vol:cz at: 31-Jan-2002 15:37
Hi Gabriele,
simple and the most probable explanation.
Cheers
Ladislav
----- Original Message -----
From: "Gabriele Santilli" <[g--santilli--tiscalinet--it]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, January 31, 2002 2:23 PM
Subject: [REBOL] Re: curious use of LENGTH?
Hello Joel!
On 31-Gen-02, you wrote:
JN> Notice the last line -- I have no clue what it means in REBOL
JN> to use an integer-valued expression as the condition of IF. I
My guess is that that was written by someone who had spent all the day
coding in C. ;-)
Jeff? Holger? Carl?
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[6/9] from: lmecir:mbox:vol:cz at: 31-Jan-2002 15:57
Hi myself,
a (stupid) mistake. It should have been:
insert/dup tail s " " mod - length? s max
, but my mod function isn't a mezzanine (can be found in
http://www.sweb.cz/LMecir/rounding.r)
----- Original Message -----
From: "Ladislav Mecir" <[lmecir--mbox--vol--cz]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, January 31, 2002 3:32 PM
Subject: [REBOL] Re: curious use of LENGTH?
Hi Joel,
even
while [((length? s) // max) <> 0] [append s " "]
looks unusual to me. I normally use:
insert/dup tail s " " max - ((length? s) // max)
Cheers
Ladislav
[7/9] from: rotenca:telvia:it at: 31-Jan-2002 16:28
Hi, Joel, Gabriele
> My guess is that that was written by someone who had spent all the day
> coding in C. ;-)
Now i understand! Also a lenght of 0, print the string!...
---
Ciao
Romano
[8/9] from: joel::neely::fedex::com at: 31-Jan-2002 10:07
Hi, Romano,
Romano Paolo Tenca wrote:
> From Core 3-23 about 'if:
>
...
> > Any suggestions on why the above wasn't written simply as
> >
> > PRINT S
>
> If 's would be empty, it would print a newline.
>
If any numeric value counts as TRUE, then
if length? s [print s]
and
print s
do exactly the same thing, since the IF would always be satisfied!
Hence my question, why the IF ?
-jn-
[9/9] from: greggirwin:mindspring at: 31-Jan-2002 12:43
Hi Joel,
<<
If any numeric value counts as TRUE, then
if length? s [print s]
and
print s
do exactly the same thing, since the IF would always be satisfied!
Hence my question, why the IF ?
>>
I'd say it shouldn't be there, provided they intended to print just a
newline (in which case I hope it's commented that way. Bummer that we can't
see comments for mezzanine functions.).
If they intended it not to print 0 length strings, they need to change the
condition to reflect that.
Probably worth a submission to feedback, unless they jump in here. It might
be that the same thing occurs other places in their code as well.
--Gregg
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted