Exemplo n.º 1
0
 /// <summary>Native method implementing the .match Grace method
 /// for types</summary>
 /// <remarks>At present, this matching uses only the method
 /// names in both the object and the type.</remarks>
 public GraceObject Match(EvaluationContext ctx, GraceObject target)
 {
     if (requests == null)
     {
         var l = new List <MethodRequest>();
         foreach (var m in methods)
         {
             var req = new MethodRequest();
             foreach (var p in m)
             {
                 var rp = RequestPart.Nullary(p.Name);
                 req.AddPart(rp);
             }
             l.Add(req);
         }
         requests = l;
     }
     foreach (var req in requests)
     {
         if (!target.RespondsTo(req))
         {
             return(Matching.FailedMatch(ctx, target));
         }
     }
     return(Matching.SuccessfulMatch(ctx, target));
 }
Exemplo n.º 2
0
        /// <summary>Match a pattern against a target</summary>
        /// <param name="ctx">Current interpreter</param>
        /// <param name="pattern">Pattern to match</param>
        /// <param name="target">Target of the match</param>
        public static GraceObject Match(EvaluationContext ctx,
                                        GraceObject pattern,
                                        GraceObject target)
        {
            var matchReq = new MethodRequest();
            var rp       = new RequestPart("match", new List <GraceObject>(),
                                           new List <GraceObject>()
            {
                target
            });

            matchReq.AddPart(rp);
            return(pattern.Request(ctx, matchReq));
        }
Exemplo n.º 3
0
            private GraceObject apply(EvaluationContext ctx,
                                      GraceObject arg)
            {
                if (index >= _elements.Count)
                {
                    return(GraceObject.Done);
                }
                var el  = _elements[index++];
                var req = new MethodRequest();
                var rpn = new RequestPart("apply",
                                          new List <GraceObject>(),
                                          new List <GraceObject>()
                {
                    el, arg
                }
                                          );

                req.AddPart(rpn);
                _block.Request(ctx, req);
                return(GraceObject.Done);
            }