本文整理汇总了C#中System.Environment.CreateChildEnvironment方法的典型用法代码示例。如果您正苦于以下问题:C# Environment.CreateChildEnvironment方法的具体用法?C# Environment.CreateChildEnvironment怎么用?C# Environment.CreateChildEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Environment
的用法示例。
在下文中一共展示了Environment.CreateChildEnvironment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyLambda
public object ApplyLambda(IList<object> arguments, Environment environment)
{
var parameterList = arguments.First() as IList<object>;
var body = arguments.Skip(1);
if (parameterList == null)
{
throw new ArgumentException("Missing parameter list in lambda!");
}
if (!parameterList.All(x => x is SymbolNode))
{
throw new ArgumentException("Parameters must be symbols!");
}
return new ProcedureNode(parameterList.Cast<SymbolNode>(), body, environment.CreateChildEnvironment());
}
示例2: ApplyLet
public object ApplyLet(IList<object> arguments, Environment environment)
{
/*
* (let ((var-a form-a) (var-b form-b)) (+ var-a var-b))
*/
var bindingList = (IList<object>) arguments.First();
var bodyforms = arguments.Skip(1).AsEnumerable();
var localEnv = environment.CreateChildEnvironment();
foreach (var binding in bindingList.OfType<IList<object>>())
{
var symbol = (SymbolNode)binding.First();
var form = binding.ElementAt(1);
var value = evaluator.Evaluate(form, localEnv);
localEnv.DefineSymbol(symbol, value);
}
return evaluator.Evaluate(bodyforms, localEnv);
}
示例3: ApplyDefMacro
public object ApplyDefMacro(IList<object> arguments, Environment environment)
{
if (arguments.Count != 3)
{
throw new ArgumentException("Wrong number of arguments given to defmacro! Expected: " + 3);
}
var symbol = arguments.ElementAt(0) as SymbolNode;
if (symbol == null)
{
throw new ArgumentException("First argument to defmacro not a symbol!");
}
var parameterList = arguments.ElementAt(1) as IList<object>;
if (parameterList == null)
{
throw new ArgumentException("Second argument to defmacro not a parameterlist!");
}
var body = arguments.ElementAt(2);
var macro = new ProcedureNode(parameterList.Cast<SymbolNode>(), new[] { body }, environment.CreateChildEnvironment(), true);
environment.DefineSymbol(symbol, macro);
return symbol;
}