Re: Help with a function to return the 'age' of itself
- To: mathgroup at smc.vnet.net
- Subject: [mg61435] Re: Help with a function to return the 'age' of itself
- From: albert <awnl at arcor.de>
- Date: Wed, 19 Oct 2005 02:16:13 -0400 (EDT)
- Organization: Arcor
- References: <dj2662$b76$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, Just one possibility of many: $starttime = None; timer := If[$starttime === None, $starttime = AbsoluteTime[]; 0., AbsoluteTime[] - $starttime ]; using the following you can reset the timer: SetAttributes[reset, HoldAll] reset[timer] := $starttime = None; reset[timer] timer Pause[3] timer actually I would prefer the following, so that it is more clear timer is a function (note that reset does not need to have the Attribute HoldAll in this case, and you don't necessarily need an extra symbol to store the start-value): timer[0] = None; timer[] := If[timer[0] === None, timer[0] = AbsoluteTime[]; 0., AbsoluteTime[] - timer[0] ]; reset[timer] := timer[0] = None; reset[timer] timer[] Pause[2] timer[]