Преправљена ламбда функција

This commit is contained in:
kappa 2019-02-04 21:16:35 +01:00
parent 916d3683ff
commit 93969f9588
4 changed files with 44 additions and 5 deletions

View file

@ -9,7 +9,7 @@ PREFIX = /usr/local
# флегови за C компајлер и линкер
CPPFLAGS = -D_POSIX_C_SOURCE=200809L
# CFLAGS = -g -std=c99 -pedantic -Wall -O0
CFLAGS = -std=c99 -pedantic -Wall -O1
CFLAGS = -std=c99 -pedantic -Wall -O2
LDFLAGS = -lm -lc
CC = cc

View file

@ -1,3 +1,5 @@
#include <string.h>
#include "symtable.h"
#include "util.h"
#include "eval.h"
@ -30,6 +32,11 @@ int allSyms(object list)
return 1;
}
object ifStatement(object parameters)
{
*/
object add(object parameters)
{
object result;
@ -206,6 +213,36 @@ object quote(object parameters)
return result;
}
int validArgumentList(object list)
{
if (!properList(list) || !allSyms(list))
{
return 0;
}
else
{
int allUniqueSyms = 1;
object *currentSymbol1 = &list;
while (TYPE(*currentSymbol1) != nilObject)
{
object *currentSymbol2 = &CDR(*currentSymbol1);
while (TYPE(*currentSymbol2) != nilObject)
{
if (!strcmp(SYM(CAR(*currentSymbol1)),
SYM(CAR(*currentSymbol2))))
{
allUniqueSyms = 0;
goto breakloop;
}
currentSymbol2 = &CDR(*currentSymbol2);
}
currentSymbol1 = &CDR(*currentSymbol1);
}
breakloop:
return allUniqueSyms;
}
}
object lambda(object parameters)
{
object result;
@ -214,8 +251,7 @@ object lambda(object parameters)
TYPE(result) = errorObject;
ERR(result) = argumentNumberError;
}
else if (!(TYPE(CAR(parameters)) == consObject &&
allSyms(CAR(parameters))))
else if (!validArgumentList(CAR(parameters)))
{
TYPE(result) = errorObject;
ERR(result) = typeError;
@ -227,6 +263,7 @@ object lambda(object parameters)
PROC_TYPE(result) = compoundProc;
PROC_COMP_ARGS(result) = copyObject(CAR(parameters));
PROC_COMP_BODY(result) = copyObject(CDR(parameters));
PROC_COMP_TABLE(result) = currentTable;
}
return result;

1
read.c
View file

@ -347,7 +347,6 @@ object dispatchedChar(wchar_t c)
case L'|':
for (;;)
{
if ((c = scanwc(stdin)) == L'|' &&
(c = scanwc(stdin)) == L'#')
{

3
util.h
View file

@ -26,6 +26,7 @@
#define PROC_BUILTIN(x) ((x).value.proc->value.builtin)
#define PROC_COMP_ARGS(x) ((x).value.proc->value.compound.args)
#define PROC_COMP_BODY(x) ((x).value.proc->value.compound.body)
#define PROC_COMP_TABLE(x) ((x).value.proc->value.compound.table)
#define NUM(x) ((x).value.num)
#define NUM_TYPE(x) ((x).value.num.type)
@ -125,6 +126,7 @@ struct procedure
{
object args;
object body;
int table;
} compound;
} value;
};
@ -135,6 +137,7 @@ int listLength(object list);
void deleteObject(object input);
object copyObject(object input);
object list
object longlongToNumber(long long int input);
object shortenFractionNum(object a);