public Value Next() { if (current == null) { current = seed; return(current); } using (var whileAssistant = new ParameterAssistant(whileBlock, true)) using (var incrementAssistant = new ParameterAssistant(increment, true)) { var block = incrementAssistant.Block(); if (block == null) { return(new Nil()); } incrementAssistant.IteratorParameter(); incrementAssistant.SetIteratorParameter(current); current = block.Evaluate(); whileAssistant.IteratorParameter(); whileAssistant.SetIteratorParameter(current); block = whileAssistant.Block(); if (block == null) { return(new Nil()); } if (block.Evaluate().IsTrue) { return(current); } } return(new Nil()); }
public Value For() { using (var assistant = new ParameterAssistant(Arguments)) { var block = assistant.Block(); assistant.IteratorParameter(); Reset(); var value = Next(); var index = 0; while (!value.IsNil && index++ <= MAX_LOOP) { assistant.SetIteratorParameter(value); block.Evaluate(); var signal = Signal(); if (signal == Breaking) { break; } switch (signal) { case Continuing: value = Next(); continue; case ReturningNull: return(null); } value = Next(); } } return(this); }
public static Value Group(INSGenerator generator, Arguments arguments) { var count = arguments[0].Int; if (count > 0) { var iterator = new NSIterator(generator); var array = new Array(); iterator.Reset(); var value = iterator.Next(); for (var i = 0; i < MAX_ARRAY && !value.IsNil; i += count) { var subArray = new Array(); for (var j = 0; j < count && !value.IsNil; j++) { subArray.Add(value); value = iterator.Next(); } array.Add(value); value = iterator.Next(); } return(array); } using (var assistant = new ParameterAssistant(arguments)) { var block = assistant.Block(); if (block == null) { return(ToArray(generator)); } var hash = new AutoHash <string, List <Value> > { Default = DefaultType.Lambda, DefaultLambda = k => new List <Value>(), AutoAddDefault = true }; assistant.IteratorParameter(); var iterator = new NSIterator(generator); iterator.Reset(); foreach (var item in iterator) { assistant.SetIteratorParameter(item); var key = block.Evaluate().Text; hash[key].Add(item); } var array = new Array(); foreach (var item in hash) { array[item.Key] = new Array(item.Value); } return(array); } }
public Value For() { using (var assistant = new ParameterAssistant(Arguments)) { var block = assistant.Block(); if (block != null) { assistant.IteratorParameter(); var count = 0; for (var current = start; current.CompareTo(stop) <= 0 && count++ < Runtime.MAX_LOOP; current = current.Succ()) { assistant.SetIteratorParameter(current); block.Evaluate(); var signal = ParameterAssistant.Signal(); if (signal == ParameterAssistant.SignalType.Breaking) { break; } switch (signal) { case ParameterAssistant.SignalType.Continuing: continue; case ParameterAssistant.SignalType.ReturningNull: return(null); } } } return(this); } }
public void Iterate(Lambda lambda) { using (var assistant = new ParameterAssistant(Arguments)) { var block = lambda.Block; if (block == null) { return; } assistant.IteratorParameter(lambda.Parameters); var count = 0; for (var current = start; current.CompareTo(stop) <= 0 && count++ < Runtime.MAX_LOOP; current = current.Succ()) { assistant.SetIteratorParameter(current); var text = block.Evaluate().Text; var signal = ParameterAssistant.Signal(); if (signal == ParameterAssistant.SignalType.Breaking) { break; } switch (signal) { case ParameterAssistant.SignalType.Continuing: continue; case ParameterAssistant.SignalType.ReturningNull: return; } Runtime.State.Print(text); } } }
public void Iterate(Lambda lambda) { using (var assistant = new ParameterAssistant(Arguments)) { var block = lambda.Block; if (block != null) { assistant.IteratorParameter(lambda.Parameters); var count = 0; if (start < stop) { for (var i = start; i <= stop && count++ < Runtime.MAX_LOOP; i += increment) { assistant.SetIteratorParameter(i); var record = block.Evaluate().Text; var signal = ParameterAssistant.Signal(); if (signal == ParameterAssistant.SignalType.Breaking) { break; } switch (signal) { case ParameterAssistant.SignalType.Continuing: continue; case ParameterAssistant.SignalType.ReturningNull: return; } Runtime.State.Print(record); } } else { for (var i = start; i >= stop && count++ < Runtime.MAX_LOOP; i -= increment) { assistant.SetIteratorParameter(i); var record = block.Evaluate().Text; var signal = ParameterAssistant.Signal(); if (signal == ParameterAssistant.SignalType.Breaking) { break; } switch (signal) { case ParameterAssistant.SignalType.Continuing: continue; case ParameterAssistant.SignalType.ReturningNull: return; } Runtime.State.Print(record); } } } } }
public Value For() { using (var assistant = new ParameterAssistant(Arguments)) { var block = assistant.Block(); if (block != null) { assistant.IteratorParameter(); var count = 0; if (start < stop) { for (var i = start; i <= stop && count++ < Runtime.MAX_LOOP; i += increment) { assistant.SetIteratorParameter(i); block.Evaluate(); var signal = ParameterAssistant.Signal(); if (signal == ParameterAssistant.SignalType.Breaking) { break; } switch (signal) { case ParameterAssistant.SignalType.Continuing: continue; case ParameterAssistant.SignalType.ReturningNull: return(null); } } } else { for (var i = start; i >= stop && count++ < Runtime.MAX_LOOP; i -= increment) { assistant.SetIteratorParameter(i); block.Evaluate(); var signal = ParameterAssistant.Signal(); if (signal == ParameterAssistant.SignalType.Breaking) { break; } switch (signal) { case ParameterAssistant.SignalType.Continuing: continue; case ParameterAssistant.SignalType.ReturningNull: return(null); } } } } return(this); } }
static Value tap(Value value, Arguments arguments) { using (var assistant = new ParameterAssistant(arguments)) { var block = assistant.Block(); if (block == null) { return(value); } assistant.IteratorParameter(); assistant.SetIteratorParameter(value); block.Evaluate(); return(value); } }