Re: we need official libs

new topic     » goto parent     » topic index » view thread      » older message » newer message

I agree on my preference of min() being the 2nd one.
I also think that the first is okay but really should have a
differrent name such as at_least() or more appropriately,
threshold_min().  After all, that is really what it is. A
threshold control with a minimium.  Of course even it needs
to be defined in functionality.

Example: print(1, threshold_min({0,1,2,3,4}, 2))
  should that print {0,0,2,3,4} or wouldn't it be better to
  print {2,2,2,3,4}  Thus forcing those below the threshold
  into the desired range.  I personally don't know which is
  better.  With the 1st value you are assuming that if it
  doesn't reach the threshold that the value should be 0 but
  with the 2nd you are assuming that anything below the
  threshold should be raised to the threshold miniumum.

    Same is true of threshold_max().  Should you zero those
beyond the threshold?  I really think not.  Even though my
previous code doesn't reflect it.  I embrace the 2nd method.
Bring the values outside the threshold_min() or max to the
specified threshold value.

    Below lies the correction to my previous sign() code.
this code will return -1 for (negative) 0 for (zero) and +1
for (positive).  Also is the threshold() routines to reflect
my preference of how they should be handled.

global function sign(object input)
  return ((input > 0) - (input < 0))
end function

global function threshold_min(object input, atom threshold)
  return ((input * (input >= threshold)) + ((threshold > input) *
threshold))
end function

global function threshold_max(object input, atom threshold)
  return ((input * (threshold >= input)) + ((input > threshold) *
threshold))
end function

        Lucius L. Hilley III
          lhilley at cdc.net
+----------+--------------+--------------+
| Hollow   | ICQ: 9638898 | AIM: LLHIII  |
|  Horse   +--------------+--------------+
| Software | http://www.cdc.net/~lhilley |
+----------+-----------------------------+

> ---------------------- Information from the mail
header -----------------------
> Poster:       Colin Taylor <cetaylor at COMPUSERVE.COM>
> Subject:      Re: we need official libs
> --------------------------------------------------------------------------
-----
>
> More on "min" and "max" ...
>
> After doing a fast review of the way similar Euphoria functions are
> written, I think that only two possible syntaxes (or is that syntices?) f=
> it
> the mold:
>
>     example 1:  obj = min(obj, obj)
>     example 2:  obj = min(seq)
>
> The first example doesn't add much to the language because its almost the=
>
> same as compare().  The second example would return the lowest top-level
> element in the sequence, treating the sequence in the same way as the
> sort(), find() and reverse() functions.  My vote is for the second exampl=
> e.
>
> More on voting ...
>
> We should remember that the Euphoria community is not a democracy.  I don=
> 't
> like the word "dictatorship", so maybe we should just call it a benevolen=
> t
> monarchy  blink
>
> And while I'm on this soap box ...
>
> There seems to be a growing trend toward changing the subject name (threa=
> d
> name) with each new message.  This makes it harder to follow a given thre=
> ad
> and also messes up the digests.
>
> Colin Taylor
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu