Welcome to the CHICKEN Scheme pasting service

function to talk to i3 pasted by sECuRE on Mon Aug 27 19:46:35 2012

;; opens a UNIX socket and sends messages formatted as per
;; http://i3wm.org/docs/ipc.html#_sending_messages_to_i3
(define (i3-command msg)
    (let ((ipc (socket af/unix sock/stream)))
      (socket-connect ipc (unix-address (i3-socket-path)))
      ;; TODO: shorten the following?
      (socket-send-all ipc
		       (with-output-to-string
			   (lambda ()
			     (begin
			       (display "i3-ipc")
			       (write-u8vector (blob->u8vector/shared (u32vector->blob/shared (u32vector (string-length msg)))))
			       (write-u8vector (blob->u8vector/shared (u32vector->blob/shared (u32vector 0))))
			       (display msg)))))
      (socket-close ipc)))

refactoring suggestions added by DerGuteMoritz on Mon Aug 27 19:51:27 2012

(use clojurian-syntax)

(define write-u32
  (o write-u8vector blob->u8vector/shared u32vector->blob/shared u32vector))

(define (string->ipc-string msg)
  (with-output-to-string
      (lambda ()
        (display "i3-ipc")
        (write-u32 (string-length msg))
        (write-u32 0)
        (display msg))))

(define (i3-command msg)
  (doto (socket af/unix sock/stream)
        (socket-connect (unix-address (i3-socket-path)))
        (socket-send-all (string->ipc-string msg))
        (socket-close)))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the equality predicate for strings in R5RS?
Visually impaired? Let me spell it for you (wav file) download WAV