public static IEnumerable <bool> For(WamMachine machine, WamReferenceTarget[] arguments) { Debug.Assert(arguments.Length == 3); var wamReferenceTargetFrom = arguments[1].Dereference(); var wamValueIntegerFrom = wamReferenceTargetFrom as WamValueInteger; if (wamValueIntegerFrom == null) { yield break; } var wamReferenceTargetTo = arguments[2].Dereference(); var wamValueIntegerTo = wamReferenceTargetTo as WamValueInteger; if (wamValueIntegerTo == null) { yield break; } for (var index = wamValueIntegerFrom.Value; index <= wamValueIntegerTo.Value; ++index) { var wamValueIntegerResult = WamValueInteger.Create(index); if (machine.Unify(arguments[0], wamValueIntegerResult)) { yield return(true); } else { yield break; } } }
public static bool GetSeed(WamMachine machine, WamReferenceTarget[] arguments) { Debug.Assert(arguments.Length == 1); var operand = arguments[0]; var seed = WamValueInteger.Create(s_seed); return(machine.Unify(operand, seed)); }
public static bool SetSeed(WamMachine machine, WamReferenceTarget[] arguments) { Debug.Assert(arguments.Length == 1); WamValueInteger operand = arguments[0].Dereference() as WamValueInteger; if (operand == null) { return(false); } s_seed = operand.Value; s_random = new Random(s_seed); return(true); }
/// <remarks> /// See also CodeValue.Create. /// </remarks> public static WamValue Create(CodeValue value) { if (value == null) { return(WamValueObject.Create(null)); } if (value is CodeValueBoolean) { return(WamValueBoolean.Create(((CodeValueBoolean)value).Value)); } if (value is CodeValueDateTime) { return(WamValueDateTime.Create(((CodeValueDateTime)value).Value)); } if (value is CodeValueDouble) { return(WamValueDouble.Create(((CodeValueDouble)value).Value)); } if (value is CodeValueException) { return(WamValueException.Create(((CodeValueException)value).Value)); } if (value is CodeValueInteger) { return(WamValueInteger.Create(((CodeValueInteger)value).Value)); } if (value is CodeValueString) { return(WamValueString.Create(((CodeValueString)value).Value)); } if (value is CodeValueType) { return(WamValueType.Create(((CodeValueType)value).Value)); } return(WamValueObject.Create(value.Object)); }
public static bool Next(WamMachine machine, WamReferenceTarget[] arguments) { Debug.Assert(arguments.Length == 3); var minValue = arguments[0].Dereference() as WamValueInteger; if (minValue == null) { return(false); } var maxValue = arguments[1].Dereference() as WamValueInteger; if (maxValue == null) { return(false); } var operand = arguments[2]; var value = WamValueInteger.Create(s_random.Next(minValue.Value, maxValue.Value)); return(machine.Unify(operand, value)); }