File: mathpiperinit.mpi

package info (click to toggle)
mathpiper 0.0.svn2556-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,416 kB
  • ctags: 2,729
  • sloc: java: 21,643; xml: 751; sh: 105; makefile: 5
file content (99 lines) | stat: -rw-r--r-- 3,250 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99


/* This is the basic initialization file for MathPiper. It gets loaded
 * each time MathPiper is started. All the basic files are loaded.
 */

/* Set up drivers, configurable in the .mpiperrc
 *   Set(MultiNomialDriver,"org/mathpiper/scripts/multivar.rep/sparsenomial.mpi");
 *     or
 *   Set(MultiNomialDriver,"org/mathpiper/scripts/multivar.rep/partialdensenomial.mpi");
 */

/* The truly required files (MathPiper NEEDS to load). */
// syntax must be loaded first
Use("org/mathpiper/scripts/initialization.rep/stdopers.mpi");

/* Set of functions to define very simple functions. There are scripts that can
   be compiled to plugins. So MathPiper either loads the plugin, or loads the
   scripts at this point. The functions in these plugins need to be defined with
   these "Defun" functions.
 */
DefMacroRuleBase("Defun",{func,args,body});
Rule("Defun",3,0,True)
[
  Local(nrargs);
  Set(nrargs,Length(@args));
  Retract(@func, `(@nrargs));
  RuleBase(@func,@args);
  Local(fn,bd);
  Set(fn,Hold(@func)); Set(bd,Hold(@body));
  `Rule(@fn, @nrargs, 0,True)(@bd);
];

//TODO remove? Use("org/mathpiper/scripts/base.rep/math.mpi");

Use("org/mathpiper/scripts/patterns.rep/code.mpi");
// at this point <-- can be used

Use("org/mathpiper/scripts/deffunc.rep/code.mpi");

// at this point := and Function() can be used

Use("org/mathpiper/scripts/constants.rep/code.mpi");
Use("org/mathpiper/scripts/initialization.rep/standard.mpi");
Use("org/mathpiper/scripts/initialization.rep/stdarith.mpi");

// at this point arithmetic can be used

/* Load the def files for the other modules. The def files contain lists
 * of functions defined in that file. So, in solve.def you can find the
 * functions defined in the file solve. Each time a function is invoked
 * for which the interpreter can not find a definition, the file is loaded.
 */

RuleBase(LoadPackages,{packages});
Rule(LoadPackages, 1, 1, True)
[
	If(Equals(packages,{}), True,
	[
		DefLoad(Head(packages));
		LoadPackages(Tail(packages));
	]);
];

Use("org/mathpiper/scripts/initialization.rep/packages.mpi");
LoadPackages(DefFileList());


/* The read-eval-print loop */
RuleBase("REP",{});
LocalSymbols(input,stringOut,result,errorString)
Rule("REP",0,1,True)
[
  Local(input,stringOut,result);
  While(Not(IsExitRequested()))
  [
    Set(errorString, "");
    If(And(IsString(PrettyReader'Get()),Not(PrettyReader'Get() = "")),
      TrapError(Set(input, FromString(ReadCmdLineString("In> "))ApplyPure(PrettyReader'Get(),{})),Set(errorString,GetCoreError())),
      TrapError(Set(input, FromString(ConcatStrings(ReadCmdLineString("In> "),";"))Read()),Set(errorString,GetCoreError())));
    If(Not(errorString = ""), WriteString(errorString));
    If (Not(IsExitRequested()) And errorString="",
    [
      Set(stringOut,"");
      Set(result,False);
      Set(stringOut,ToString()[TrapError(Set(result,Eval(input)),Set(errorString,GetCoreError()));]);
      If(Not(stringOut = ""), WriteString(stringOut));
      If(Not(errorString = ""), WriteString(errorString));
      SetGlobalLazyVariable(%,result);
      If(PrettyPrinter'Get()="",
      [
        Write(Atom("Out> "),result);
        NewLine();
      ],
      Apply(PrettyPrinter'Get(),{result}));
    ]);
  ];
];