~ubuntu-branches/ubuntu/oneiric/yacas/oneiric

« back to all changes in this revision

Viewing changes to src/mathcommands2.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gopal Narayanan
  • Date: 2002-04-23 13:50:51 UTC
  • Revision ID: james.westby@ubuntu.com-20020423135051-bbd6ov4orr8eufmw
Tags: upstream-1.0.51
ImportĀ upstreamĀ versionĀ 1.0.51

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
#include "yacasbase.h"
 
4
#include "lispenvironment.h"
 
5
#include "standard.h"
 
6
#include "lispeval.h"
 
7
#include "lispatom.h"
 
8
#include "lispparser.h"
 
9
#include "stdfileio.h"
 
10
#include "stringio.h"
 
11
#include "lisperror.h"
 
12
#include "infixparser.h"
 
13
#include "lispuserfunc.h"
 
14
#include "mathuserfunc.h"
 
15
#include "platmath.h"
 
16
#include "numbers.h"
 
17
#include "anumber.h"
 
18
#include "arrayclass.h"
 
19
#include "patternclass.h"
 
20
#include "substitute.h"
 
21
#include "errors.h"
 
22
 
 
23
#define InternalEval aEnvironment.iEvaluator->Eval
 
24
 
 
25
 
 
26
void LispSubst(LispEnvironment& aEnvironment, LispPtr& aResult,
 
27
               LispPtr& aArguments)
 
28
{
 
29
    TESTARGS(4);
 
30
 
 
31
    LispPtr from,to,body;
 
32
    InternalEval(aEnvironment, from, Argument(aArguments,1));
 
33
    InternalEval(aEnvironment, to  , Argument(aArguments,2));
 
34
    InternalEval(aEnvironment, body, Argument(aArguments,3));
 
35
    SubstBehaviour behaviour(aEnvironment,from, to);
 
36
    InternalSubstitute(aResult, body, behaviour);
 
37
}
 
38
 
 
39
 
 
40
void LispLocalSymbols(LispEnvironment& aEnvironment, LispPtr& aResult,
 
41
                      LispPtr& aArguments)
 
42
{
 
43
    LispInt nrArguments = InternalListLength(aArguments);
 
44
 
 
45
    LispInt nrSymbols = nrArguments-2;
 
46
 
 
47
    LispStringPtr *names = (LispStringPtr *)PlatAlloc(sizeof(LispStringPtr)*nrSymbols);
 
48
    LispStringPtr *localnames = (LispStringPtr *)PlatAlloc(sizeof(LispStringPtr)*nrSymbols);
 
49
    //TODO names and localnames should be pushed on the cleanup stack!!!
 
50
    CHK(names != NULL,KLispErrNotEnoughMemory);
 
51
    CHK(localnames != NULL,KLispErrNotEnoughMemory);
 
52
 
 
53
    LispInt uniquenumber = aEnvironment.GetUniqueId();
 
54
    LispInt i;
 
55
    for (i=0;i<nrSymbols;i++)
 
56
    {
 
57
        LispStringPtr atomname = Argument(aArguments, i+1).Get()->String();
 
58
        CHK_ARG(atomname != NULL, i+1);
 
59
        names[i] = atomname;
 
60
 
 
61
        LispInt len = atomname->NrItems()-1;
 
62
        CHK_ARG(len<64,i+1);
 
63
        char newname[100];
 
64
        newname[0] = '$';
 
65
        PlatMemCopy(&newname[1], atomname->String(), len);
 
66
 
 
67
        InternalIntToAscii(&newname[1+len],uniquenumber);
 
68
        LispStringPtr variable = aEnvironment.HashTable().LookUp(newname);
 
69
        localnames[i] = variable;
 
70
        aEnvironment.NewLocal(variable,NULL);
 
71
    }
 
72
    
 
73
 
 
74
    LocalSymbolBehaviour behaviour(names,localnames,nrSymbols);
 
75
    LispPtr result;
 
76
    InternalSubstitute(result, Argument(aArguments, nrArguments-1), behaviour);
 
77
    PlatFree(names);
 
78
    PlatFree(localnames);
 
79
 
 
80
 
 
81
    InternalEval(aEnvironment, aResult, result);
 
82
}
 
83