Commits

Tim van der Linden committed 6a22025

Code cleanup: create more shorthands when defining and made version an implicit argument

Comments (0)

Files changed (1)

 	      type type message))))
 
 ; Helper for checking which type we have, did not want to use another dependency for that :)
-(define get-type
-  (lambda (x)
+(define (get-type x)
     (cond ((input-port? x) "an input port")
 	  ((output-port? x) "an output port")
 	  ((number? x) "a mumber")
           ((list? x) "a list")
 	  ((vector? x) "a vector")
 	  ((boolean? x) "a boolean")
-	  ("something unknown"))))
+	  ("something unknown")))
 
 ; Setup the server and return a procedure to setup the method and optional params
 ; Do some basic checking if the input, output and version are as expected
 ;; - input: input port of the JSON-RPC server
 ;; - ouptput: ouput port of the JSON-RPC server
 ;; - version: the JSON-RPC version in which we want to communicate
-(define json-rpc-server
-  (lambda (input output version)
+(define (json-rpc-server input output #!key (version "2.0"))
     (cond ((not (input-port? input)) (server-setup-arguments-error "input port" "input-port" (get-type input)))
 	  ((not (output-port? output)) (server-setup-arguments-error "output port" "ouput-port" (get-type output)))
 	  ((not (is-valid-version? version)) (server-setup-arguments-error "version" "2.0" version))
 					      (list (cons 'params (build-params params))))
 					  (list (cons 'id "1"))) ;ID is hardcoded, overkill to generate random ID, you can't handle more then one request/response at a time...or can you?
 				  input 
-				  output))))))))
+				  output)))))))
 
 ; Helper for building a vector or alist from the parameters if present
-(define build-params
-  (lambda (params)    
+(define (build-params params)    
     (if (keyword? (car params)) 
 	(build-alist params)
-	(list->vector (build-vector params)))))
+	(list->vector (build-vector params))))
 
 ; Helper for building an alist
-(define build-alist
-  (lambda (params)
+(define (build-alist params)
     (if (null? params) 
 	(append '())
-	(cons (cons (car params) (car (cdr params))) (build-alist (cdr (cdr params)))))))
+	(cons (cons (car params) (car (cdr params))) (build-alist (cdr (cdr params))))))
 
 ; Helper for building a vector
-(define build-vector
-  (lambda (params)
+(define (build-vector params)
     (if (null? params)
 	'()
-	(cons (symbol->string(car params)) (build-vector (cdr params))))))
+	(cons (symbol->string(car params)) (build-vector (cdr params)))))
 
 ; Check if the method is a string as defined in the spec
-(define is-valid-method?
-  (lambda (method)
-    (string? method)))
+(define (is-valid-method? method)
+    (string? method))
 
 ; Check if the params are a list (alist or vector) as defined in the spec
-(define are-valid-params?
-  (lambda (params)
-    (list? params))) ;Assumptions? Don't know if this check is enough (check for null (is also a list) or list)
+(define (are-valid-params? params)
+    (list? params)) ;Assumptions? Don't know if this check is enough (check for null (is also a list) or list)
 
 ; Check if the version is correctly formatted as defined in the spec
-(define is-valid-version?
-  (lambda (version)
-    (string=? version "2.0")))
+(define (is-valid-version? version)
+    (string=? version "2.0"))
 
 ; Send the actual request using Medea
-(define send-request
-  (lambda (request input output)
-    (write-json request output)))
+(define (send-request request input output)
+    (write-json request output))
 
 )