threads work in progress

This commit is contained in:
2021-04-22 22:50:53 +02:00
parent b8d9690141
commit a2a01dd676
2 changed files with 93 additions and 38 deletions

View File

@@ -56,11 +56,12 @@
; (sleep 1.5)
(define multiply-by (lambda (n) (lambda (y) (* y n))))
(define doubler (multiply-by 2))
(define tripler (multiply-by 3))
(doubler 4)
(tripler 4)
;; does not work aif n is defined. in that case it is copied to lambda_scope
;; (define multiply-by (lambda (n) (lambda (y) (* y n))))
;; (define doubler (multiply-by 2))
;; (define tripler (multiply-by 3))
;; (doubler 4)
;; (tripler 4)
;https://github.com/anthay/Lisp90/blob/master/lisp90.cpp
@@ -77,8 +78,7 @@ x ; still 3
x ; is now 4
(defun mini-uuid (uuid_len)
(do
(defun mini-uuid (uuid_len) (do
(define a_list '("_" "-" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"))
(reduce (lambda (acc y) (+ acc y)) "" (map (lambda (e) (index a_list (random 0 (- (len a_list) 1)))) (range 0 uuid_len)))
))
@@ -86,40 +86,24 @@ x ; is now 4
(benchmark "uuid 1000x :" (define i 0) (while (< i 1000) (do (mini-uuid 5) (define i (+ i 1)))))
(defun ut::assert-equal (value form) (do
(define fvalue (eval form))
(if (= value fvalue)
1
nil
)
))
(define ut::assert-true (test) (ut::assert-equal 1 test))
(assert-false (test)() (asertt-equal nil test)
(defun ut::assert-true test) ()
(defun ut::assert-false test)
(define ut::tests_list '())
(defun ut::define-test (name exp_list) (
define test_list (push ut::tests_list (list name exp_list))))
(run-tests name1 name2 ...)
(defun plus-jedna() (do (set! xx (+ 1 xx))))
(define xx 3)
(defun define-test (name exp_list) (set! test_list (push test_list (list name exp_list))))
(defun run-tests () (do (for t test_list (if (eval (index t 1)) (print (+ "OK -> " (index t 0))) (print (+ "ERR -> " (index t 0)))))))
;(run-test name)
(define test_list '())
(define-test "je to dvojka" '(assert-equal 2 (+ 1 1)))
(define-test "je to trojka" '(assert-equal 3 (+ 1 1)))
(run-tests)
(plus-jedna)
(plus-jedna)
(define-test "je to dvojka" '(assert-equal 2 (+ 1 1)))
(define first_tid (thread-create (while 1 (do (thread-under-lock "ilock" (print 1)) (thread-sleep 50)))))
(define second_tid (thread-create (while 1 (do (thread-under-lock "ilock" (print 2)) (thread-sleep 75)))))
(print "first thread id:" first_tid)
(print "second thread id:" second_tid)
(threads-join)
(print "ok")