minor improvements; util: start with functional tools: curry
This commit is contained in:
parent
dd1501636e
commit
6498068924
4 changed files with 14 additions and 6 deletions
|
@ -21,7 +21,6 @@
|
|||
(defun login-form (ctx msg-in)
|
||||
(let ((msg (message:create '(:auth :form :login)
|
||||
:data (list
|
||||
;:fields (:login :password)
|
||||
:fields (login-fields)
|
||||
:button "Login"))))
|
||||
(actor:send (actor:customer msg-in) msg)
|
||||
|
|
|
@ -72,6 +72,8 @@
|
|||
(t:show-result))))
|
||||
|
||||
(deftest test-util ()
|
||||
(let ((35+ (util:curry #'+ 35)))
|
||||
(== (funcall 35+ 7) 42))
|
||||
(let ((now (get-universal-time)))
|
||||
(== (util:from-unix-time (util:to-unix-time now)) now))
|
||||
(let* ((x (util:ptr))
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
|
||||
(defun init ()
|
||||
(when (null lp:*kernel*)
|
||||
(format t "async:init ~a ~%"
|
||||
(setf lp:*kernel* (lp:make-kernel (serapeum:count-cpus))))))
|
||||
;(format t "async:init ~a ~%"
|
||||
(setf lp:*kernel* (lp:make-kernel (serapeum:count-cpus)))
|
||||
(util:lgi lp:*kernel*)))
|
||||
|
||||
(defun finish ()
|
||||
(when lp:*kernel*
|
||||
(lp:end-kernel)))
|
||||
|
||||
;;;; simple task = mailbox with result channel
|
||||
;;;; simple addressable task = mailbox with result channel
|
||||
|
||||
(defclass mailbox ()
|
||||
((queue :reader queue :initform (lpq:make-queue))
|
||||
|
@ -54,7 +55,7 @@
|
|||
(defun try-receive-result (mb)
|
||||
(lp:try-receive-result (channel mb)))
|
||||
|
||||
;;;; tasks - with behavior and thread-safe status
|
||||
;;;; real (restartable) task - with behavior and thread-safe status
|
||||
|
||||
(defclass task (mailbox)
|
||||
((behavior :accessor behavior :initarg :behavior)))
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
(:use :common-lisp)
|
||||
(:local-nicknames (:b64 :qbase64))
|
||||
#+sbcl (:import-from :sb-ext #:add-package-local-nickname)
|
||||
(:export #:make-vars-format #:lg #:lgd #:lgi #:lgw #:lgx
|
||||
(:export #:curry
|
||||
#:make-vars-format #:lg #:lgd #:lgi #:lgw #:lgx
|
||||
#:from-unix-time #:to-unix-time
|
||||
#:ptr
|
||||
#:rfill #:rtrim
|
||||
|
@ -19,6 +20,11 @@
|
|||
|
||||
(in-package :scopes/util)
|
||||
|
||||
;;;; functional tools
|
||||
|
||||
(defun curry (fn a)
|
||||
(lambda (&rest args) (apply fn a args)))
|
||||
|
||||
;;;; formatting and logging shortcuts
|
||||
|
||||
(defun make-vars-format (vars &optional info)
|
||||
|
|
Loading…
Add table
Reference in a new issue