Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement term:<rand>
  • Loading branch information
sorear committed May 16, 2011
1 parent 116226c commit ddee5a5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Builtins.cs
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace Niecza {
public class UpCallee: CrossDomainReceiver {
Expand Down Expand Up @@ -406,6 +407,14 @@ class SubstrLValue: Variable {
return Kernel.BoxAnyMO(d, Kernel.NumMO);
}

private static Random rng = new Random();

public static Variable GetRandom() {
double i;
lock (rng) { i = rng.NextDouble(); }
return Kernel.BoxAnyMO(i, Kernel.NumMO);
}

public static bool FileOrDirExists(string path) {
return File.Exists(path) || Directory.Exists(path);
}
Expand Down
1 change: 1 addition & 0 deletions lib/CLRBackend.cs
Expand Up @@ -3233,6 +3233,7 @@ class NamProcessor {
thandlers["bif_numlt"] = SimpleB("NumericLt");
thandlers["bif_numge"] = SimpleB("NumericGe");
thandlers["bif_numgt"] = SimpleB("NumericGt");
thandlers["bif_rand"] = SimpleB("GetRandom");
thandlers["bif_streq"] = SimpleB("StringEq");
thandlers["bif_strne"] = SimpleB("StringNe");
thandlers["bif_strle"] = SimpleB("StringLe");
Expand Down
2 changes: 2 additions & 0 deletions lib/CORE.setting
Expand Up @@ -1292,6 +1292,8 @@ my class Instant {
sub term:« now »() {
Instant.new( val => Q:CgOp { (bif_now) } );
}
sub term:« time »() { Q:CgOp { (bif_now) } }
sub term:« rand »() { Q:CgOp { (bif_rand) } }
my class IO {
has $.path; # Str
Expand Down
4 changes: 4 additions & 0 deletions src/niecza
Expand Up @@ -229,6 +229,10 @@ class RxOp::CutBrack is RxOp {
method lad() { [ 'Null' ]; }
}

augment class CgOp {
method bif_rand () { self._cgop("bif_rand") }
}

my $usage = q:to/EOM/;
niecza -- a command line wrapper for Niecza

Expand Down

0 comments on commit ddee5a5

Please sign in to comment.