small fixes

This commit is contained in:
VaclavT 2021-03-10 23:10:21 +01:00
parent 3f46ae9c94
commit 11ad7fc3bc
5 changed files with 31 additions and 35 deletions

View File

@ -1,11 +1,10 @@
### BUGS
- (read-file "nonexisting/file.csv") shows only "could not open file"
### TODO
- test whether AIG,,,10 csv row is parsed
- support for (), nil, t, in lsp code replace 0 by nil in logicals
- some performance functionality (at least counting how many times symbol was evaluated)
- download 10 years of data from api.nasdaq.com into test dir
- documentation
- add url of source/inspiration to clib/*.cpp
- add stdtest - to test every functionality
@ -27,6 +26,8 @@
- string functions
- compare - needed for sorting
- uppper/lower case
- trim
- replace
- regexp functions
- date support
- decode-universal-time
@ -36,22 +37,23 @@
- add hash datatype
- conversion functions like parse-integer
- in test.lisp some explaining prints
- format (printf)
- format (sprintf)
- setq
- mapcar (funcall, apply)
#### Performance
- push_back - repeatedly without reserving size
- mini_sprintf - unnecesary copying between vector and list
#### Install
```
cp build/ml /usr/local/bin/ml
cp stdlib/stdlib.lsp /usr/local/var/mlisp/stdlib.lsp
cp stdlib/*.lsp /usr/local/var/mlisp/
```
#### Compile
```
gcc -o ml -I/usr/local/opt/openssl/include -Iclib -L/usr/local/lib -L/usr/local/opt/openssl/lib -lm -lstdc++ -lcrypto -lssl -Wl,-stack_size -Wl,0x1000000 --std=c++17 ml.cpp ml_io.cpp ml_date.cpp ml_string.cpp clib/json11.cpp clib/csvparser.cpp clib/sslclient.cpp
gcc -o ml -I/usr/local/opt/openssl/include -Iclib -L/usr/local/lib -L/usr/local/opt/openssl/lib -lm -lstdc++ -lcrypto -lssl -Wl,-stack_size -Wl,0x1000000 --std=c++17 ml.cpp ml_io.cpp ml_date.cpp ml_string.cpp clib/json11.cpp clib/csvparser.cpp clib/sslclient.cpp clib/printf.cpp
```
or
cmake

View File

@ -1,35 +1,26 @@
; (print (sprintf "\033[31mred text"))
; (print (sprintf "\x1B[31mred text"))
;; (print (sprintf "%.2f" (list 1.25)))
;; (print (sprintf "%.2f" '(1.23456)))
;; (print (sprintf "%d" '(10000000)))
(define q 1.23)
(print (sprintf "%+.2f%%" (list q)))
(define q -1.23)
(print (sprintf "%+.2f%%" (list q)))
(define term-rst-esc "\x1B[0m")
(define term-red-esc '"\x1B[31m")
(define term-green-esc "\x1B[32m")
(define term-yellow-esc "\x1B[33m")
(define term-blue-esc "\x1B[34m")
(define term-magenta-esc "\x1B[35m")
(define term-cyan-esc "\x1B[36m")
(define term-white-esc "\x1B[37m")
(define term-bold-esc "\x1B[1m")
(define term-underline-esc "\x1B[4m")
(defun term-red (str) (sprintf (+ term-red-esc str term-rst-esc)))
(defun term-green (str) (sprintf (+ term-green-esc str term-rst-esc)))
(defun term-yellow (str) (sprintf (+ term-yellow-esc str term-rst-esc)))
(defun term-blue (str) (sprintf (+ term-blue-esc str term-rst-esc)))
(defun term-magenta (str) (sprintf (+ term-magenta-esc str term-rst-esc)))
(defun term-cyan (str) (sprintf (+ term-cyan-esc str term-rst-esc)))
(defun term-white (str) (sprintf (+ term-white-esc str term-rst-esc)))
(defun term-bold (str) (sprintf (+ term-bold-esc str term-rst-esc)))
(defun term-underline (str) (sprintf (+ term-underline-esc str term-rst-esc)))
(print (term-red "red text"))
(print (term-green "green text"))
(print (term-yellow "yellow text"))
(print (term-blue "blue text"))
(print (term-magenta "magenta text"))
(print (term-cyan "cyan text"))
(print (term-white "white text"))
(print (term-bold "bold text"))
(print (term-underline "underline text"))
(print "normal text")
(print (term-red "red") (sprintf "%.2f" (list 1.11)) "ss")
(define q_change_str (sprintf "%+.2f %%" (list q)))
;; (if (>= q_change 0.0)
;; (define q_change_str (term-green q_change_str))
;; (define q_change_str (term-red q_change_str)))

3
ml.cpp
View File

@ -477,7 +477,7 @@ MlValue MlValue::operator%(const MlValue &other) const {
}
// Get the name of the type of this value
std::string MlValue::get_type_name() {
std::string MlValue::get_type_name() const {
switch (type) {
case QUOTE:
return QUOTE_TYPE;
@ -1524,7 +1524,6 @@ namespace builtin {
MlValue sprintf(std::vector<MlValue> args, MlEnvironment &env) {
eval_args(args, env);
std::string result;
if (args.size() < 1 || args.size() > 2)
throw MlError(MlValue("sprintf", sprintf), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);

2
ml.h
View File

@ -182,7 +182,7 @@ public:
MlValue operator%(const MlValue &other) const;
// Get the name of the type of this value
std::string get_type_name();
std::string get_type_name() const;
std::string display() const;

View File

@ -158,9 +158,13 @@
(print "list:" l)
(print "flatten-ed list:" (flatten l))
(print (sprintf "%.2f" (list 1.25)))
(print (sprintf "%.2f" '(1.23456)))
(print (sprintf "%d" '(10000000)))
(define q 1.23)
(print (sprintf "%.2f" (list q)))
(print (term-red "red text"))
(print (term-green "green text"))