Ejemplo n.º 1
0
 /// <summary>
 /// Define the counter primitives.
 /// </summary>
 /// <param name="primEnv">The environment to define the primitives into.</param>
 internal static void DefinePrimitives(PrimitiveEnvironment primEnv)
 {
     primEnv
         .DefinePrimitive(
             "trace-on",
             new[] { "(trace-on)" },
             (args, env, caller) => SetTraceFlag(caller, true),
             new ArgsInfo(0))
         .DefinePrimitive(
             "trace-off",
             new[] { "(trace-off)" },
             (args, env, caller) => SetTraceFlag(caller, false),
             new ArgsInfo(0))
         .DefinePrimitive(
             "counters-on",
             new[] { "(counters-on)" },
             (args, env, caller) => SetCountFlag(caller, true),
             new ArgsInfo(0))
         .DefinePrimitive(
             "counters-off",
             new[] { "(counters-off)" },
             (args, env, caller) => SetCountFlag(caller, false),
             new ArgsInfo(0))
         .DefinePrimitive(
             "backtrace",
             new[] { "(backtrace)" },
             (args, env, caller) => Backtrace(caller),
             new ArgsInfo(0))
         .DefinePrimitive(
             "debug",
             new[] { "(debug)" },
             (args, env, caller) => Debug(caller),
             new ArgsInfo(0))
         .DefinePrimitive(
             "list-primitives",
             new[] { "(list-primitives)" },
             (args, env, caller) => caller.Interp.PrimEnvironment.ListPrimitives(),
             new ArgsInfo(0))
         .DefinePrimitive(
             "describe",
             new[] { "(describe <obj>)" },
             (args, env, caller) => Describe(List.First(args)),
             new ArgsInfo(1, ArgType.Obj));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Define the procedure primitives.
        /// </summary>
        /// <param name="primEnv">The environment to define the primitives into.</param>
        internal static new void DefinePrimitives(PrimitiveEnvironment primEnv)
        {
            const int MaxInt = int.MaxValue;
            primEnv
                .DefinePrimitive(
                        "apply",
                        new[] { "6.9", "(apply <proc> <args>)", "(apply <proc> <arg1> ... <args>)" },
                        (args, env, caller) => ((Procedure)First(args)).Apply(ListStar(Rest(args)), env, caller, caller),
                        new ArgsInfo(2, MaxInt, ArgType.Proc, ArgType.Obj))
                .DefinePrimitive(
                        "call-with-current-continuation",
                        new[] { "6.9", "(call-with-current-continuation <proc>)" },
                        (args, env, caller) => ((Procedure)First(args)).CallCc(caller),
                        new ArgsInfo(1, ArgType.Proc))
                .DefinePrimitive(
                        "call/cc",
                        new[] { "(call/cc <proc>)" },
                        (args, env, caller) => ((Procedure)First(args)).CallCc(caller),
                        new ArgsInfo(1, ArgType.Proc))

                .DefinePrimitive(
                        "force",
                        new[] { "6.9", "(force <promise>)" },
                        (args, env, caller) => Force((Procedure)First(args), caller),
                        new ArgsInfo(1, ArgType.Proc))
                ////  Note: list(s) are optional and may be empty lists.
                .DefinePrimitive(
                        "for-each",
                        new[] { "6.9", "(for-each <proc> <list1> <list2> ...)" },
                        (args, env, caller) => EvaluateMap.Call((Procedure)First(args), Rest(args), false, caller.Env, caller),
                        new ArgsInfo(1, MaxInt, ArgType.Proc, ArgType.PairOrEmpty))
                ////  Note: list(s) are optional and may be empty lists.
                .DefinePrimitive(
                        "map",
                        new[] { "6.9", "(map <proc> <list1> <list2> ...)" },
                        (args, env, caller) => EvaluateMap.Call((Procedure)First(args), Rest(args), true, caller.Env, caller),
                        new ArgsInfo(1, MaxInt, ArgType.Proc, ArgType.PairOrEmpty))
                .DefinePrimitive(
                        "procedure?",
                        new[] { "6.9", "(procedure? <obj>)" },
                        (args, env, caller) => SchemeBoolean.Truth(First(args) is Procedure),
                        new ArgsInfo(1, ArgType.Obj));
        }