mlisp/debug.lsp

114 lines
3.7 KiB
Common Lisp

(defun find-with-val-sublist (lst name)
(do
; (print "list:" lst " name:" name)
(define found_val nil)
(define i 0)
(while (and (>= i 0) (< i (len lst)))
(define e (index lst i))
; (print "testing element:" e " first e:" (first e))
(if (= (type (first e)) "list")
(do
(set! found_val (find-with-val-sublist (first e) name))
(if (!= found_val nil) (set! i -1))
)
; else
(do
;(print "compare" (first e) " with " name)
(if (= name (first e))
(do
; (print "found" name)
(set! found_val (second e)) (set! i -1)
)
; else
(if (= (type (second e)) "list")
(do (set! found_val (find-with-val-sublist (second e) name))
(if (!= found_val nil)
(set! i -1)
)
)
(define i (inc i))
)
)
)
)
)
found_val
))
(define str "{\"date_from\":\"2021-10-05\",\"date_to\":\"2021-10-05\",\"earnings\":{\"2021-10-05\":{\"stocks\":[{\"importance\":5,\"symbol\":\"PEP\",\"date\":\"2021-10-05\",\"time\":\"06:00:00\",\"title\":\"PepsiCo\"},{\"importance\":0,\"symbol\":\"SAR\",\"date\":\"2021-10-05\",\"time\":\"16:00:00\",\"title\":\"Saratoga Investment\"}],\"day\":\"Today\",\"month\":\"October\",\"year\":\"2021\",\"date_number\":\"05\",\"selected_copy\":\"PEP and SAR reporting Today\",\"deselected_copy\":\"PEP and SAR reporting Today\"}}}")
(define parsed_json (parse-json str))
;(print parsed_json "\n")
(define stocks (find-with-val-sublist parsed_json "stocks"))
(print stocks)
(for s stocks
(print s)
(print (find-with-val-sublist parsed_json "date"))
)
;; (define a 25)
;; (cond
;; ((> a 30) (print "a > 30"))
;; ((> a 20) (print "a > 20"))
;; (1 (print "a je" a)))
;; (define csv_date (str-to-date "01/01/2021" "%m/%d/%Y"))
;; (date-to-str 3141583200 "%m/%d/%Y")
;; (define time (get-universal-time))
;; (str-to-date (date-to-str time "%Y-%m-%d %H:%M:%S") "%Y-%m-%d %H:%M:%S")
;; (define create_tbl_sql "create table prices (datetime integer, symbol varchar(8), prev_close float, open float, price float, change float, change_prct varchar(16))")
;; (define insert_sql "insert into prices (datetime, symbol, prev_close, open, price, change, change_prct) values (1626979443, 'MPC', 54.08, 53.82, 53.63, -0.832101, '-0.83 %')")
;; (define select_sql "select to_string(datetime, '%d.%m.%Y %H:%M:%S'), symbol, prev_close, open, price, change, change_prct from prices")
;; (print (usql create_tbl_sql))
;; (print (usql insert_sql))
;; (print (usql select_sql))
;; (print (usql "select to_string(datetime, '%d.%m.%Y %H:%M:%S'), symbol, prev_close, open, price, change, change_prct from prices"))
;; (define var "promena var")
;; (define var2 "promena var2")
;; (print var)
;; (print var2)
;; (print (+ "select min(adjClose), max(adjClose) from history_prices where symbol = '" var "'"))
;; (print (usql "create table data (ticker varchar(8), price float null)"))
;; (usql "load data from '/Users/vaclavt/Library/Mobile Documents/com~apple~CloudDocs/Development/usql/data.csv')")
;; (print (usql "select ticker, price from data"))
;; (read-url "https://api.nasdaq.com/api/calendar/dividends/")
;; (define fc 5)
;; (define sc 5)
;; (define first_tid (thread-create (while (> fc 0) (do (thread-under-lock "ilock" (do (set! fc (dec fc))(print 1))) (thread-sleep 500)))))
;; (define second_tid (thread-create (while (> sc 0) (do (thread-under-lock "ilock" (do (set! sc (dec sc))(print 2))) (thread-sleep 750)))))
;; (print "first thread id:" first_tid)
;; (print "second thread id:" second_tid)
;; (threads-join)
;; (print "ok")
;; (try
;; (ls-dir "nonexisting/dir")
;; (print "dir not exists"))
;; (try
;; (throw "my-exception")
;; (print "exception caught:" ml-exception))
;; (/ 1 0)