本文整理汇总了C#中System.Machine.SetVariableValue方法的典型用法代码示例。如果您正苦于以下问题:C# Machine.SetVariableValue方法的具体用法?C# Machine.SetVariableValue怎么用?C# Machine.SetVariableValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Machine
的用法示例。
在下文中一共展示了Machine.SetVariableValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvaluateUnqualifiedSymbolAsDefinedVariableInCurrentNamespace
public void EvaluateUnqualifiedSymbolAsDefinedVariableInCurrentNamespace()
{
Symbol symbol = Symbol.Create("foo");
Machine machine = new Machine();
Variable variable = Variable.Intern(machine, (string) machine.Environment.GetValue(Machine.CurrentNamespaceKey), "foo");
machine.SetVariableValue(variable, "bar");
IExpression expression = new SymbolExpression(symbol);
Assert.AreEqual("bar", expression.Evaluate(machine, machine.Environment));
Assert.AreEqual(symbol, expression.Value);
}
示例2: Apply
public object Apply(Machine machine, ValueEnvironment environment, object[] arguments)
{
Symbol symbol = (Symbol)arguments[0];
if (!string.IsNullOrEmpty(symbol.Namespace))
throw new InvalidOperationException("Defined name should not have namespace");
Variable variable = Utilities.ToVariable(machine, environment, symbol);
object value = machine.Evaluate(arguments[1], environment);
if (symbol.Metadata != null)
{
IDictionary dictionary = (IDictionary)symbol.Metadata;
IDictionary evaluated = new Hashtable();
foreach (object key in dictionary.Keys)
{
object val = machine.Evaluate(dictionary[key], environment);
evaluated[key] = val;
}
variable.ResetMetadata(new DictionaryObject(evaluated));
}
else
variable.ResetMetadata(null);
IPersistentMap metadata = variable.Metadata;
if (metadata != null && metadata.ContainsKey(macroKeyword))
if ((bool)metadata.ValueAt(macroKeyword) && value is DefinedFunction)
value = ((DefinedFunction)value).ToMacro();
machine.SetVariableValue(variable, value);
if (value is IFunction && ((IFunction)value).IsSpecialForm)
machine.Environment.SetValue(variable.Name, value, true);
return value;
}
示例3: SetMacro
public void SetMacro(Machine machine)
{
object obj = machine.GetVariableValue(this);
if (obj is DefinedFunction)
{
obj = ((DefinedFunction)obj).ToMacro();
machine.SetVariableValue(this, obj);
}
else if (obj is DefinedMultiFunction)
{
obj = ((DefinedMultiFunction)obj).ToMacro();
machine.SetVariableValue(this, obj);
}
else if (!(obj is DefinedMacro))
throw new InvalidOperationException();
if (this.metadata != null)
this.metadata = this.metadata.Associate(Keyword.Create("macro"), true);
else
{
IDictionary dict = new Hashtable();
dict[Keyword.Create("macro")] = true;
this.metadata = new DictionaryObject(dict);
}
}
示例4: SetMacroOnDefinedMultiFunction
public void SetMacroOnDefinedMultiFunction()
{
Machine machine = new Machine();
machine.CreateNamespace("ns");
FnStarPrimitive fnprim = new FnStarPrimitive();
Parser parser = new Parser("([x] (+ x 1)) ([x y] (+ x y 1))");
object[] parameters = new object[2];
parameters[0] = parser.ParseForm();
parameters[1] = parser.ParseForm();
object result = fnprim.Apply(machine, machine.Environment, parameters);
DefinedMultiFunction multifn = (DefinedMultiFunction)result;
Variable variable = Variable.Intern(machine, "ns/func");
machine.SetVariableValue(variable, multifn);
variable.SetMacro(machine);
object mresult = machine.GetVariableValue(variable);
Assert.IsNotNull(mresult);
Assert.IsInstanceOfType(mresult, typeof(DefinedMultiMacro));
}
示例5: SetMacroOnDefinedFunction
public void SetMacroOnDefinedFunction()
{
Machine machine = new Machine();
machine.CreateNamespace("ns");
Variable variable = Variable.Intern(machine, "ns/func");
Parser parser = new Parser("[x y] (list x y) 1 2");
object argumentNames = parser.ParseForm();
object body = parser.ParseForm();
DefinedFunction func = new DefinedFunction("simple-list", (ICollection)argumentNames, Utilities.ToExpression(body));
machine.SetVariableValue(variable, func);
variable.SetMacro(machine);
object result = machine.GetVariableValue(variable);
Assert.IsNotNull(result);
Assert.IsInstanceOfType(result, typeof(DefinedMacro));
}