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

[Values] Penultimate Coerce

 [1/2] from: AJMartin::orcon::net::nz at: 24-Dec-2003 22:49


>> last "abcde"
== #"e"
>> penultimate "abcde"
== #"d" Penultimate: func [ "Returns the next-to-last value of a series." Series [series! port! tuple!]] [ pick tail Series -2 ]
>> coerce 1 none 12
== 1 Coerce: func [ "Forces a value to be within limits." Low_Limit [number! pair! char! money! date! time! tuple! series!] "Lower limit for value." Value [any-type!] "The value to limit." High_Limit [number! pair! char! money! date! time! tuple! series!] Upper limit for value. ] [ if not number? Value [ Value: Low_Limit ] Value: max Low_Limit Value Value: min Value High_Limit ] Enjoy! Andrew J Martin Speaking in tongues and performing miracles. ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/

 [2/2] from: atruter:labyrinth:au at: 27-Nov-2003 10:20


Hi Andrew,
> Penultimate: func [ > "Returns the next-to-last value of a series." > Series [series! port! tuple!]] [ > pick tail Series -2 > ]
Neat. Certainly better than mine ;) second-last: func [series] [ pick series (length? series) - 1 ]
> Coerce: func [ > "Forces a value to be within limits."
<<quoted lines omitted: 11>>
> Value: min Value High_Limit > ]
What's with the Capitalized_And_Underscored word names? ;) Apart from that, how about the following minor changes? coerce: func [ "Forces a value to be within limits, or none if types do not match." low-limit [number! pair! char! money! date! time! tuple!] "Lower limit for value." value [number! pair! char! money! date! time! tuple! none!] "The value to limit." high-limit [number! pair! char! money! date! time! tuple!] "Upper limit for value." ][ either all [(type? low-limit) = type? value (type? high-limit) = type? value] [ value: max low-limit value value: min value high-limit ][ none ] ]
>> coerce 1-Jan-1980 23-Dec-1999 30-Dec-1990
== 30-Dec-1990
>> coerce $10 $30 $20
== $20.00
>> coerce 1 none 2
== none Regards, Ashley

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