private void addFuncHelper(string name, ArrayFunc func, int paramNum = -1) { if (variables.ContainsKey(name) || !var_match(name)) { throw new ArgumentException($"Given function name '{name}' is either invalid or already exists."); } FunctionsDict.Add(name, func); Tokenizer.TokenDict.Add(name, new Tuple <Type, int>(typeof(CallerFuncToken), paramNum)); }
static void Main(string[] args) { Console.WriteLine("Task 1"); ArrayFunc arrayFunc = new ArrayFunc(); int[] A = arrayFunc.GettingArray(); arrayFunc.PrintArray(A); Array.Sort(A); arrayFunc.PrintArray(A); arrayFunc.ElementForSearch(A); }
/// <summary> /// Adds a custom function specified by a mathematical expression string. /// </summary> /// <param name="name">The name of the function.</param> /// <param name="expression">The function definition as an expression string</param> /// <param name="args">A list of the names of the function's parameters.</param> public void AddFunction(string name, string expression, params string[] args) { Parser funcParser = new Parser(args); try { ArrayFunc func = funcParser.Parse(expression).Compile(args); addFuncHelper(name, func, args.Length); } catch (ParserException ex) { throw new InvalidFunctionException(name, ex); } }
public void Update() { if (reset) { donePath = false; ArrayFunc.Clear(ref solvedPath); reset = false; } if (start == null || end == null) { Debug.LogWarning("Need 'start' and or 'end' defined!"); enabled = false; return; } startIndex = Closest(sources, start.transform.position); endIndex = Closest(sources, end.transform.position); if (startIndex != lastStartIndex || endIndex != lastEndIndex) { reset = true; lastStartIndex = startIndex; lastEndIndex = endIndex; return; } for (int i = 0; i < sources.Count; i++) { if (AStarHelper.Invalid(sources[i])) { continue; } sources[i].nodeColor = nodeColor; } PulsePoint(lastStartIndex); PulsePoint(lastEndIndex); if (!donePath) { solvedPath = AStarHelper.Calculate(sources[lastStartIndex], sources[lastEndIndex]); donePath = true; } // Invalid path if (solvedPath == null || solvedPath.Count < 1) { Debug.LogWarning("Invalid path!"); reset = true; enabled = false; return; } //Draw path for (int i = 0; i < solvedPath.Count - 1; i++) { if (AStarHelper.Invalid(solvedPath[i]) || AStarHelper.Invalid(solvedPath[i + 1])) { reset = true; return; } Debug.DrawLine(solvedPath[i].Position, solvedPath[i + 1].Position, Color.cyan * new Color(1.0f, 1.0f, 1.0f, 0.5f)); } }
public ArrayFuncWrapper(ArrayFunc <T1, T> del) : base(del) { ArgumentTypes = new ImmutableArray <Type>(new Type[1] { typeof(T1) }); }
/// <summary> /// Adds a custom function with an array of values as parameter. /// </summary> /// <param name="name">The name of the function.</param> /// <param name="method">The function's delegate, taking an array as parameter.</param> public void AddFunction(string name, ArrayFunc method) => addFuncHelper(name, method);