From 0260c74e7f27178b78905f94e68dc42feb1b63b6 Mon Sep 17 00:00:00 2001 From: VaclavT Date: Tue, 8 Feb 2022 08:08:47 +0100 Subject: [PATCH] include env fix, decode-universal-time added --- Readme.md | 5 +---- ml.cpp | 6 +----- stdlib/stdlib.lsp | 2 +- tests/test.lsp | 1 + 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Readme.md b/Readme.md index 65e6836..e82440b 100644 --- a/Readme.md +++ b/Readme.md @@ -66,7 +66,6 @@ utils/local_install.sh ### KNOWNN BUGS -- in (include "file.lsp") are not available stdlib.lsp finctions like (string-trim ..) etc - (read-url "https://api.nasdaq.com/api/calendar/dividends/") ; hangs in sslclient.cpp line 132 ### TODO @@ -96,8 +95,6 @@ utils/local_install.sh - string functions - compare - needed for sorting, cmp ignore case - regexp match, regexp tokens -- date support - - decode-universal-time (http://www.lispworks.com/documentation/HyperSpec/Body/f_dec_un.htm) - env functions - get-env, set-env; set-env cannot be implemented in stdlib.lsp, because popen is in fact subshell - macros and then loop, let etc @@ -115,4 +112,4 @@ https://github.com/antirez/linenoise #### read stdout and stderr from popen -https://stackoverflow.com/questions/478898how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po +https://stackoverflow.com/questions/478898how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po \ No newline at end of file diff --git a/ml.cpp b/ml.cpp index ecc9620..61b14b3 100644 --- a/ml.cpp +++ b/ml.cpp @@ -1393,16 +1393,12 @@ MlValue tcp_client(std::vector args, MlEnvironment &env) { // Read a file and execute its code MlValue include(std::vector args, MlEnvironment &env) { - // Import is technically not a special form, it's more of a macro. - // We can evaluate our arguments. eval_args(args, env); if (args.size() != 1) throw MlError(MlValue("include", include), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS); - MlEnvironment e; - MlValue result = run(read_file_contents(args[0].as_string()), e); - env.combine(e); + MlValue result = run(read_file_contents(args[0].as_string()), env); return result; } diff --git a/stdlib/stdlib.lsp b/stdlib/stdlib.lsp index b157b49..243e834 100644 --- a/stdlib/stdlib.lsp +++ b/stdlib/stdlib.lsp @@ -180,7 +180,7 @@ (defn end-of-prev-month (datetime) (date-add (end-of-month datetime) -1 "month")) (defn start-of-year (datetime) (str-to-date (+ (date-to-str datetime "%Y") "-01-01 00:00:00") "%Y-%m-%d %H:%M:%S")) (defn end-of-year (datetime) (str-to-date (+ (date-to-str datetime "%Y") "-12-31 23:59:59") "%Y-%m-%d %H:%M:%S")) - +(defn decode-universal-time (time) (map (lambda (x) (int x)) (string-split (date-to-str time "%S %M %H %d %m %Y %w") "\s+"))) ; from list of lists creates csv string ; (print (make-csv '(("r1c1" "r1c2") ("r2c1" "r2c2")))) diff --git a/tests/test.lsp b/tests/test.lsp index dee7de1..84717b7 100644 --- a/tests/test.lsp +++ b/tests/test.lsp @@ -136,6 +136,7 @@ (ut::define-test "result of (end-of-prev-month)" '(ut::assert-equal 1619827199 (end-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")))) (ut::define-test "result of (start-of-year)" '(ut::assert-equal 1609459200 (start-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")))) (ut::define-test "result of (end-of-year)" '(ut::assert-equal 1640995199 (end-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")))) +(ut::define-test "result of (decode-universal-time 0)" '(ut::assert-equal '(0 0 0 1 1 1970 4) (decode-universal-time 0))) (ut::define-test "result of (read-file-lines \"/tmp/f.txt\" counter)" '(ut::assert-equal 3 (read-file-lines "/tmp/f.txt" counter)))