[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Scheme-reports] No procedure to ask the current time?
- To: scheme-reports@x
- Subject: [Scheme-reports] No procedure to ask the current time?
- From: Jeronimo Pellegrini <j_p@x>
- Date: Tue, 31 Aug 2010 09:49:33 -0300
I was wondering if it isn't worth to include the timing part
of SRFI-18 in the small version of Scheme. The procedures
that I suppose would be interesting are:
- (time->seconds time)
- (seconds->time x)
- (time? obj)
Just that. No threads, mutexes or signals.
The reason for this is that those procedures would be useful
to implement two important didactic examples:
- A PRNG:
I agree with those that think that including simple randomness
in "small" Scheme is not encessary, since it's easy to write a
PRNG that would work fine for didatic purposes: a linear
congruential PRNG is trivial to write, easy to understand and
a nice example of procedure. It's also a nice example of a
referentially transparent procedure if you don't hide its
state -- and later in the course it's possible to talk about
encapsulation of state using it again as an example.
However, it would be good to have some way to seed the PRNG
with a minimally unpredictable number, which could be obtained
from (time->seconds (current-time)) (for simple randomness
for students this is usually good enough).
- A threading system:
A didactic Metacircular evaluator could in principle
be used to teach about threading: it would switch threads
after K calls to eval. But having (current-time) available
would allow one to write a metacircular evaluator that
actually checks, at the end of EVAL, if a certain quantum
of time has passed -- and then switch threads if so.
This is conceptually closer to a threading system with
preemption and would make a better example (although I also
think coroutines should be taught -- and I already do that).
What do others think?
-- Jeronimo Pellegrini
Scheme-reports mailing list