Lambdas return only last item. EOL file comments
Added (penv) to print the current environment Changed "Duplicate" test to work with new Lambda structure
This commit is contained in:
parent
ba74561bed
commit
3319fdf2c3
|
@ -230,7 +230,7 @@ struct Environment defaultEnv()
|
||||||
{"ap", &append}, {"pre", &prepend},
|
{"ap", &append}, {"pre", &prepend},
|
||||||
{"at", &at}, {"rest", &rest}, {"rev", &reverse},
|
{"at", &at}, {"rest", &rest}, {"rev", &reverse},
|
||||||
{"isnum", &isNum},
|
{"isnum", &isNum},
|
||||||
{"prn", &print},
|
{"prn", &print}, {"penv", &printEnvO},
|
||||||
};
|
};
|
||||||
|
|
||||||
for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) {
|
for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) {
|
||||||
|
|
|
@ -154,6 +154,11 @@ Object evalList(const Object *obj, struct Environment *env)
|
||||||
Object ret = eval(&first_eval.lambda->body, &newEnv);
|
Object ret = eval(&first_eval.lambda->body, &newEnv);
|
||||||
deleteEnv(&newEnv);
|
deleteEnv(&newEnv);
|
||||||
cleanObject(&first_eval);
|
cleanObject(&first_eval);
|
||||||
|
Object *t = tail(&ret);
|
||||||
|
if(t) {
|
||||||
|
// cleanObject(&ret);
|
||||||
|
return cloneObject(*t);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -387,6 +392,15 @@ Object print(Object p, Object ignore, struct Environment *env)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object printEnvO(Object i1, Object i2, struct Environment *env) {
|
||||||
|
while(env->outer) {
|
||||||
|
env = env-> outer;
|
||||||
|
}
|
||||||
|
|
||||||
|
printEnv(env);
|
||||||
|
return numberObject(0);
|
||||||
|
}
|
||||||
|
|
||||||
void copySlice(char * dest, struct Slice *src)
|
void copySlice(char * dest, struct Slice *src)
|
||||||
{
|
{
|
||||||
if(!dest || !src)
|
if(!dest || !src)
|
||||||
|
@ -573,20 +587,27 @@ int readFile(const char *filename, struct Environment *env) {
|
||||||
}
|
}
|
||||||
Object r = numberObject(0);
|
Object r = numberObject(0);
|
||||||
char page[4096] = "";
|
char page[4096] = "";
|
||||||
char line[256];
|
const unsigned LINE_MAX = 256;
|
||||||
if(fgets(line, 256, input)){
|
char line[LINE_MAX];
|
||||||
|
if(fgets(line, LINE_MAX, input)){
|
||||||
if(line[0] != '#' || line[1] != '!') {
|
if(line[0] != '#' || line[1] != '!') {
|
||||||
strncat(page, line, strlen(line) - 1);
|
strncat(page, line, strlen(line) - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(fgets(line, 256, input)) {
|
while(fgets(line, LINE_MAX, input)) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < 256; i++) {
|
for(i = 0; i < LINE_MAX; i++) {
|
||||||
if(line[i] != ' ') {
|
if(line[i] != ' ') {
|
||||||
if(line[i] == ';') {
|
if(line[i] == ';') {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
strncat(page, line, strlen(line) - 1);
|
int j = 0;
|
||||||
|
for(j = i; j < LINE_MAX; j++) {
|
||||||
|
if(line[j] == ';' || line[j] == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
strncat(page, line, j);
|
||||||
|
strcat(page, " ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,5 +58,6 @@ Object reverse(Object _list, Object ignore, struct Environment *ignore2);
|
||||||
Object isNum(Object test, Object ignore, struct Environment *ignore2);
|
Object isNum(Object test, Object ignore, struct Environment *ignore2);
|
||||||
|
|
||||||
Object print(Object p, Object ignore, struct Environment *ignore2);
|
Object print(Object p, Object ignore, struct Environment *ignore2);
|
||||||
|
Object printEnvO(Object i1, Object i2, struct Environment *env);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -146,7 +146,7 @@ check "Factorial" "(def fac (fn (a) \
|
||||||
)));\
|
)));\
|
||||||
(fac 11)" "39916800"
|
(fac 11)" "39916800"
|
||||||
check "LambdaClone" "(def y (fn (a) (* 10 a))) (def b y) (def y 12345) ((b 5) y)" "( 50 12345 )"
|
check "LambdaClone" "(def y (fn (a) (* 10 a))) (def b y) (def y 12345) ((b 5) y)" "( 50 12345 )"
|
||||||
check "Duplicate" "(def dupe (fn (a) (a a a)));(dupe (*10 10))" "( 100 100 100 )"
|
check "Duplicate" "(def dupe (fn (a) (() (a a a))));(dupe (*10 10))" "( 100 100 100 )"
|
||||||
endBlock
|
endBlock
|
||||||
|
|
||||||
title "Cat"
|
title "Cat"
|
||||||
|
|
Loading…
Reference in New Issue