parent
342eba3a0d
commit
d76e3f5341
|
@ -395,6 +395,7 @@ struct Environment defaultEnv()
|
|||
};
|
||||
|
||||
struct symFunc symFuncs[] = {
|
||||
pf(def),
|
||||
pf(add),
|
||||
pf(sub),
|
||||
pf(mul),
|
||||
|
|
|
@ -15,11 +15,9 @@
|
|||
(def clock (fn (ti) (cat (hour ti) ":" (zero ti's minute) ":" (zero ti's sec))))
|
||||
|
||||
(def prompt (fn (a) (
|
||||
(sys "echo")
|
||||
(def ti (time))
|
||||
|
||||
(def m ti's minute)
|
||||
(def s ti's sec)
|
||||
|
||||
(cat red bold "[sage] " blue (clock) nl green bold "pebblisp ~> " reset)
|
||||
(cat nl
|
||||
bold red "[sage] " blue (clock) nl
|
||||
green "pebblisp ~> " reset)
|
||||
)))
|
||||
|
|
|
@ -34,17 +34,16 @@
|
|||
* @param env The environment to add the new definition to
|
||||
* @return The symbol(s) defined
|
||||
*/
|
||||
Object evalDefArgs(const Object* symbol, const Object* value,
|
||||
struct Environment* env)
|
||||
Object def(Object* params, int length, struct Environment* env)
|
||||
{
|
||||
const char* name = symbol->string;
|
||||
const char* name = params[0].string;
|
||||
|
||||
Object finalValue = eval(value, env);
|
||||
Object finalValue = eval(¶ms[1], env);
|
||||
|
||||
addToEnv(env, name, finalValue);
|
||||
cleanObject(&finalValue);
|
||||
|
||||
return cloneObject(*symbol);
|
||||
return cloneObject(params[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,16 +133,7 @@ Object evalBuiltIns(const Object* first, const Object* rest,
|
|||
struct Environment* env, int* found)
|
||||
{
|
||||
*found = 1;
|
||||
if (strcmp(first->string, "def") == 0) {
|
||||
return evalDefArgs(rest, rest->forward, env);
|
||||
#ifndef LOW_MEM
|
||||
} else if (strcmp(first->string, "defe") == 0) {
|
||||
Object symbol = eval(rest, env);
|
||||
Object e = evalDefArgs(&symbol, rest->forward, env);
|
||||
cleanObject(&symbol);
|
||||
return e;
|
||||
#endif
|
||||
} else if (strcmp(first->string, "if") == 0) {
|
||||
if (strcmp(first->string, "if") == 0) {
|
||||
return evalIfArgs(rest, env);
|
||||
} else if (strcmp(first->string, "fn") == 0) {
|
||||
return evalLambdaArgs(rest, env);
|
||||
|
@ -381,7 +371,7 @@ Result parse(struct Slice* slices)
|
|||
Result readSeq(struct Slice* tokens)
|
||||
{
|
||||
Object res = listObject();
|
||||
int isHelp = 0;
|
||||
int forceString = 0;
|
||||
for (;;) {
|
||||
struct Slice* next = tokens;
|
||||
struct Slice* rest = next->text ? &next[1] : NULL;
|
||||
|
@ -389,8 +379,9 @@ Result readSeq(struct Slice* tokens)
|
|||
return (Result) {res, rest};
|
||||
}
|
||||
Result r = parse(tokens);
|
||||
sugar("(? fil) => (? 'fil')",
|
||||
if (isHelp && r.obj.type == TYPE_SYMBOL) {
|
||||
sugar("(? fil) => (? 'fil')" // or,
|
||||
"(def yee 10) => (def 'yee' 10)",
|
||||
if (forceString && r.obj.type == TYPE_SYMBOL) {
|
||||
r.obj.type = TYPE_STRING;
|
||||
}
|
||||
)
|
||||
|
@ -400,7 +391,7 @@ Result readSeq(struct Slice* tokens)
|
|||
nf_addToList(&res, cloneObject(r.obj));
|
||||
tokens = r.slices;
|
||||
cleanObject(&r.obj);
|
||||
isHelp = next->text[0] == '?';
|
||||
forceString = next->text[0] == '?' || (strncmp(next->text, "def", 3) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,4 +68,9 @@ int readFile(const char* filename, struct Environment* env);
|
|||
|
||||
#endif /* STANDALONE */
|
||||
|
||||
fn(def, "def",
|
||||
"Define a variable in the current scope.",
|
||||
"(def x 10) x", "10",
|
||||
);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue