Implement loadfile in lib.pbl
This commit is contained in:
parent
a2b0e0813b
commit
9abec12d99
|
@ -209,7 +209,6 @@ struct Environment defaultEnv()
|
||||||
pf(numToChar),
|
pf(numToChar),
|
||||||
pf(printEnvO),
|
pf(printEnvO),
|
||||||
pf(systemCall),
|
pf(systemCall),
|
||||||
pf(loadFile),
|
|
||||||
pf(cd),
|
pf(cd),
|
||||||
pf(cwd),
|
pf(cwd),
|
||||||
pf(takeInput),
|
pf(takeInput),
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
(prn (cat _txt (ch 10)))
|
(prn (cat _txt (ch 10)))
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
(def loadfile (fn (file-name) (
|
||||||
|
(eval (rf file-name))
|
||||||
|
)))
|
||||||
|
|
||||||
; Exponentiate a^b
|
; Exponentiate a^b
|
||||||
(def exp (fn (a b)
|
(def exp (fn (a b)
|
||||||
(if (= b 0)
|
(if (= b 0)
|
||||||
|
|
12
src/plfunc.c
12
src/plfunc.c
|
@ -483,18 +483,6 @@ Object takeInput(Object* params, int length, unused struct Environment* env)
|
||||||
return errorWithContext(NULL_PARSE, "fgets() error");
|
return errorWithContext(NULL_PARSE, "fgets() error");
|
||||||
}
|
}
|
||||||
|
|
||||||
Object loadFile(Object* params, unused int length, struct Environment* env)
|
|
||||||
{
|
|
||||||
checkTypes(loadFile)
|
|
||||||
Object filename = params[0];
|
|
||||||
|
|
||||||
if (isStringy(filename)) {
|
|
||||||
readFile(filename.string, env);
|
|
||||||
return numberObject(0);
|
|
||||||
}
|
|
||||||
return numberObject(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object cd(Object* params, unused int length, unused struct Environment* env)
|
Object cd(Object* params, unused int length, unused struct Environment* env)
|
||||||
{
|
{
|
||||||
checkTypes(cd)
|
checkTypes(cd)
|
||||||
|
|
17
src/plfunc.h
17
src/plfunc.h
|
@ -248,10 +248,10 @@ tfn(numToChar, "ch",
|
||||||
);
|
);
|
||||||
|
|
||||||
fn(printEnvO, "penv",
|
fn(printEnvO, "penv",
|
||||||
"Prints out the current scoped environment.\n"
|
"Prints out the current scoped environment.\n"
|
||||||
"(penv) prints a mostly human-readable list of env variables.\n"
|
"(penv) prints a mostly human-readable list of env variables.\n"
|
||||||
"(penv T) prints a mostly list of env variables, including pointer addresses.\n"
|
"(penv T) prints a mostly list of env variables, including pointer addresses.\n"
|
||||||
"Calling (penv) with no argument is equivalent to (penv F)"
|
"Calling (penv) with no argument is equivalent to (penv F)"
|
||||||
);
|
);
|
||||||
|
|
||||||
tfn(systemCall, "sys",
|
tfn(systemCall, "sys",
|
||||||
|
@ -261,15 +261,6 @@ tfn(systemCall, "sys",
|
||||||
"(sys \"echo yee > /dev/null\")", "0",
|
"(sys \"echo yee > /dev/null\")", "0",
|
||||||
);
|
);
|
||||||
|
|
||||||
tfn(loadFile, "loadfile",
|
|
||||||
({ expect(isStringy), anyType }),
|
|
||||||
"Loads and parses the given file.\n"
|
|
||||||
"Returns 0 if the file was loaded and parsed successfully. Otherwise 1.\n"
|
|
||||||
"(loadfile \"printdate.pl\")\n"
|
|
||||||
"Mon 21 Mar 2022 10:35:03 AM EDT\n"
|
|
||||||
"=> 0"
|
|
||||||
);
|
|
||||||
|
|
||||||
tfn(cd, "cd",
|
tfn(cd, "cd",
|
||||||
({ expect(isStringy), anyType }),
|
({ expect(isStringy), anyType }),
|
||||||
"Change the current directory."
|
"Change the current directory."
|
||||||
|
|
Loading…
Reference in New Issue