Пример #1
0
        /// <summary>
        /// This is known as an abstraction algorithm. It converts from 
        /// a form with named parameters to point-free form.
        /// </summary>
        public static void Convert( AstDef d ) {
            List<string> locs = new List<string>();
            foreach (AstDef loc in d.mLocals)
                locs.Add( loc.mName );
            ConvertLocalCalls( d.mTerms, d.mLocals );
            ConvertTerms( locs, d.mTerms );

            foreach (AstDef loc in d.mLocals)
                d.mTerms.Insert( 0, new AstQuote( loc.mTerms ) );
            List<string> args = new List<string>();
            foreach (AstParam p in d.mParams)
                args.Add( p.ToString() );
            ConvertTerms( args, d.mTerms );
        }
Пример #2
0
        /// <summary>
        /// This is known as an abstraction algorithm. It converts from
        /// a form with named parameters to point-free form.
        /// </summary>
        /// <param name="sRightConsequent"></param>
        public static void Convert(AstDef d)
        {
            if (IsPointFree(d))
            {
                return;
            }

            List <string> args = new List <string>();

            foreach (AstParam p in d.mParams)
            {
                args.Add(p.ToString());
            }

            ConvertTerms(args, d.mTerms);
        }
Пример #3
0
        public Function MakeFunction(AstDef def)
        {
            bool bLambda = def.mParams.Count > 0 || def.mLocals.Count > 0;

            if (bLambda)
            {
                CatLambdaConverter.Convert(def);
            }
            CatExpr  fxns = NodesToFxns(def.mName, def.mTerms);
            Function ret  = new DefinedFunction(def.mName, fxns);

            if (def.mpMetaData != null)
            {
                ret.SetMetaData(new CatMetaDataBlock(def.mpMetaData));
            }
            if (bLambda && Config.gbOptimizeLambdas)
            {
                MetaCat.ApplyMacros(this, fxns);
            }

            AddFunction(ret);
            return(ret);
        }
Пример #4
0
 public static bool IsPointFree(AstDef d)
 {
     return(d.mParams.Count == 0);
 }
Пример #5
0
        /// <summary>
        /// This is known as an abstraction algorithm. It converts from 
        /// a form with named parameters to point-free form.
        /// </summary>
        public static void Convert(AstDef d)
        {
            List<string> locs = new List<string>();
            foreach (AstDef loc in d.mLocals)
                locs.Add(loc.mName);
            ConvertLocalCalls(d.mTerms, d.mLocals);
            ConvertTerms(locs, d.mTerms);

            foreach (AstDef loc in d.mLocals)
                d.mTerms.Insert(0, new AstQuote(loc.mTerms));
            List<string> args = new List<string>();
            foreach (AstParam p in d.mParams)
                args.Add(p.ToString());
            ConvertTerms(args, d.mTerms);
        }