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

Newbie expression question

 [1/7] from: kpeters::mvinc::net at: 11-Oct-2003 10:42


Thanks for your help again, guys! Another question: In the function below I have used a crutch in the form of a local variable because I haven't yet learned to "think" like Rebol's expression evaluator - what I wanted to write, though it is obviously flawed, was: if length? tlist/data > 1000 Can someone give me a pointer as to what i need to do? Thanks, Kai log: function [ tlist msg ] [ lines ] [ lines: length? tlist/data if lines > 1000 [ clear tlist/data append tlist/data "*** Log cleared ***" ] append tlist/data msg show tlist ]

 [2/7] from: SunandaDH:aol at: 11-Oct-2003 13:58


Kai:
> if length? tlist/data > 1000 > > Can someone give me a pointer as to what i need to do? >
REBOL's strict no-precedence interpretation causes problems as the line is read as: if length? (tlist/data > 1000) and that isn't valid. Try these: if (length? tlist/data) > 1000 or if 1000 <= length? tlist/data (I always go for the (...) solution as I can't be bothered with reversing boolean operations. Maybe this is a good starting point for another of Gregg's idiom discussions), Sunanda

 [3/7] from: carl:cybercraft at: 24-Dec-2003 22:39


On 12-Oct-03, [SunandaDH--aol--com] wrote:
> Kai: >> if length? tlist/data > 1000
<<quoted lines omitted: 11>>
> (I always go for the (...) solution as I can't be bothered with > reversing boolean operations.
For speed reasons though, avoiding parens is a good thing if you can. (When we're not talking about developement speed, that is;)
> Maybe this is a good starting point > for another of Gregg's idiom discussions), > Sunanda
-- Carl Read

 [4/7] from: joel:neely:fedex at: 11-Oct-2003 21:43


Hi, Sunanda, Minor quibble below... [SunandaDH--aol--com] wrote:
> Kai: >>if length? tlist/data > 1000
<<quoted lines omitted: 5>>
> or > if 1000 <= length? tlist/data
I think you meant if 1000 < length? tlist/data as equality isn't in the other cases. -jn-

 [5/7] from: brett:codeconscious at: 12-Oct-2003 13:00


> Try these: > > if (length? tlist/data) > 1000 > or > if 1000 <= length? tlist/data
The third option is: if greater? length? tlist/data 1000
> (I always go for the (...) solution as I can't be bothered with reversing > boolean operations. Maybe this is a good starting point for another of
Gregg's
> idiom discussions),
For speed, my brief timing tests (using Command) indicate that the reversed boolean style is faster than the other two. Regards, Brett.

 [6/7] from: joel:neely:fedex at: 11-Oct-2003 22:30


Ooops! I hit the send button before finishing... [SunandaDH--aol--com] wrote:
>>if length? tlist/data > 1000 > Try these:
<<quoted lines omitted: 3>>
> (I always go for the (...) solution as I can't be bothered with reversing > boolean operations.
I've been experimenting lately with restricting myself to using only < and <= to express ordered comparisons. There were a couple of initial reasons for the experiment: - as the number line (conventionally pictured, anyway!) contains smaller values on the left and larger values on the right, I wanted to test the mnemonic value of writing expressions with smaller/left and larger/right ordering; - it gives compound and range conditions a natural form: ... all [lowerlimit <= testvalue testvalue <= upperlimit] ... which resembles the normal mathematical notation: lowerlimit <= testvalue <= upperlimit (the only languages I can recall at the moment that understand that notation would be Python and Icon). - it's an interesting psychological experiment; mathematically the two expressions (e.g.) a < b and b > a are equivalent, so why is it that so many of us have learned to feel more comfortable with foo > 100 than 100 < foo in our programs? Is it because our "natural language" habits make us subconsciously think of the expresson(s) above as being more about FOO as the subject of the sentence, rather than about the relationship between two equally-important values? At any rate, it also has the interesting side effects that many REBOL expressions no longer need parentheses. It's also interesting to see the effect on one's thinking from deliberately breaking almost sub- conscious habits. -jn-

 [7/7] from: bry:itnisk at: 12-Oct-2003 16:09


> are equivalent, so why is it that so
many of us have learned to
> feel more comfortable with > > foo > 100 > > than > > 100 < foo > > in our programs? Is it because
our "natural language" habits make
> us subconsciously think of the expresson
(s) above as being more
> about FOO as the subject of the
sentence, rather than about the
> relationship between two equally-
important values? I think it's because with foo you've assigned a value to something, in doing so you are implicitly stating that foo is the more important element. I may also be wrong about this but it seems to me that with iterative languages it's a little more natural to use >, and with functional languages a little more natural to test if the value is <. This is probably just a habit I have, but with recursion I tend to subtract (I don't know why, but I've noticed it). So you have a greater feeling of naturalness in your example because the first element is one assigned a value by the programmer, whereas the second is intrinsically valued. If one had foo > bar and foo < bar then I start thinking, we're gonna be looping, and we're gonna be recursing in turn, and the naturalness of the examples depends on how I think of using the language. This however is probably a really weird personal idiosyncracy.

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted