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

[REBOL] Re: false == 2 ??

From: joel:neely:fedex at: 1-Jul-2001 19:37

Hi, Larry, Not that I'm in the habit of tilting at windmills, but ... ;-) Larry Palmiter wrote:
> So PICK is an action. Actions are polymorphic functions that > can have very different effects depending on the datatype of > the arguments. >
True enough, but it pains me to have polymorphism used as shorthand for "there is no consistent pattern, just memorize it".
> PICK takes a number or a logic arg. If the arg is a number > it is used as an index into the series arg. If it is a logic > value, it returns the first element for true and the second > element for false. There is no connection with any numeric > value associated with true and false. >
Well... (grumble, grumble)... the above explanation clearly identifies "true" with "first" and "false" with "second". We already know that REBOL fairly rigidly identifies "first" with one and "second" with "two", at least in cases where counting is a meaningful operation (such as positions in a series!) So I think it's a bit unfair to say there's "no connection". Rather it seems reasonable to acknowledge that the terminology used by REBOL allows (if not invites) one to reason that true -> first -> one false -> second -> two which conflicts (at least in the mind of many readers, I'd suggest) with the inference based on type conversion.
> >> to-integer true == 1 > >> to-integer false == 0 > > Also > > >> to-logic 0 == false > >> to-logic -123.5 == true > >> to-logic 123.5 == true >
Again, let's play fair. There are more numeric values than logic values, so the pigeonhole principle requires that either we have a many-to-one relationship, or we rule some conversions as illegal and throw exceptions. REBOL chose door number 1 in this case, and we usually use fixpoints to determine the natural correspondence in such cases, as in
>> 0 == 0 >> to-logic 0 == false >> to-integer to-logic 0 == 0 >> to-logic to-integer to-logic 0 == false
>> 300 == 300 >> to-logic 300 == true >> to-integer to-logic 300 == 1 >> to-logic to-integer to-logic 300 == true >> to-integer to-logic to-integer to-logic 300 == 1
where we stop iterating when we reach stability, and conclude that the "natural" correspondence is true <--> 1 false <--> 0 I'd point out that in some languages, the correspondence is true <--> -1 false <--> 0 but then I'd have to talk about other languages and "bits", neither of which are legitimate REBOL concepts... ;-) In contrast, REBOL rules that strings of length <> 1 may not be converted to character values,
>> to-char "a" == #"a"
as distinct from
>> to-char "aa"
** Script Error: Invalid argument: aa ** Where: to-char ** Near: to char! :value so, in this case REBOL takes door number 2. There is a term (which escapes me at the moment, the hour being late) in crystallography for the following interesting phenomenon: When growing outward from a single "seed", many crystalline substances produce lovely, consistently- structured crystals in which everything aligns nicely. However, if a single environment contains multiple such seed-points, the result may be nicely-structured regions around the seeds, with chaotic jumbles at the boundaries where differently-aligned regions grew to collision and began competing over orientation. The presence of such boundaries of mis-aligned regions may very well serve as "fault lines" along which the structure as a whole is weakened and may be broken apart more easily. But I digress, since crystals are a non-REBOL concept. ;-) -jn- ------------------------------------------------------------ Programming languages: compact, powerful, simple ... Pick any two! joel'dot'neely'at'fedex'dot'com