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

[REBOL] Re: Return of a function

From: joel:neely:fedex at: 19-Apr-2002 6:58

Hi, Philippe, Philippe Oehler wrote:
> Hi, > > I really need to understand why the return of this function > doesn't work. >
The function *does* return a value (if, as Sunanda points out, you call it by its actual name ;-)... Cutting and pasting from your email:
>> transfo-time: func [hm] [
[ [ hm: parse hm "." [ hm/1: to-integer hm/1 [ hm/2: to-integer hm/2 [ hm: to-time join hm/1 [":" hm/2] [ hm [ ]
>> >> heure: "12.01"
== "12.01"
>> >> transo-time heure
** Script Error: transo-time has no value ** Near: transo-time heure Calling with the actual name:
>> transfo-time heure
== 12:01 But the rest of your question isn't about a return value:
> heure: hm > print heure; nothing is print.. heure has no value now.. why ??? >
You seem to expect that a global word HM would be set by the evaluation of TRANSFO-TIME but that won't happen. Your definition of TRANSFO-TIME begins with transfo-time: func [hm] [ which means that the word HM within the function body is local to the function because it is the argument to the function. With all that said, the function itself is a bit puzzling to me. If you really expect a string which represents a time (but with a dot instead of the colon that REBOL expects) then the conversions (from string to block, block of strings to block of integers, integers back to string) are unnecessary overhead. Why not say transf-time: func [s] [ to-time replace s "." ":" ] which does this:
>> transf-time "12.01"
== 12:01
>> type? transf-time "12.34"
== time! -jn- -- ; Joel Neely joeldotneelyatfedexdotcom REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] { | e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]