[e-lang] Couple of newbie questions

Kevin Reid kpreid at mac.com
Sun Dec 24 15:24:38 CST 2006


On Dec 24, 2006, at 15:54, Chris Rathman wrote:

> I'm trying to translate the examples of the first chapter of SICP  
> into E
> (link at bottom).  A couple of questions I have.
>
> 1).  Random number generation:  I managed to piece together that  
> you can
> use the java random class, along the lines of:
>
> var random := <unsafe:java.util.makeRandom>()
> var x := random.nextInt(100)
>
> this gets the desired results.  I was just wondering if this is the  
> best
> way to generate random numbers in E?

? entropy.nextInt()
# value: 1985149289

> 2).  Current Time in Milliseconds:  One of the function I'm  
> translating
> tries to keep tabs on the amount of time.  In python, I'd do  
> something like:
>
> var y = timer.time()
>
> Is there a function that returns the current time in milliseconds?

? timer.now()
# value: 1166995022837

Both of these are in the privilegedScope as they are IO/ 
nondeterministic.

'timer' also allows scheduling actions to occur at a specified later  
time.

> I see that there is a function |(currentTimeMillis) in  
> java.lang.System, but there doesn't seem to be a makeSystem  
> function (like I did with the makeRandom above).

All Java classes are mapped in the same way; you may be confused by  
that everything in java.lang.System is a static method.

You should of course use the E Timer object when you can, but here's  
how you'd use java.lang.System:

? def system := <unsafe:java.lang.makeSystem>
# value: <makeSystem>

? system.currentTimeMillis()
# value: 1166995442090

-- 
Kevin Reid                            <http://homepage.mac.com/kpreid/>




More information about the e-lang mailing list