Showing posts with label scheme. Show all posts
Showing posts with label scheme. Show all posts

Friday, February 18, 2011

Chicken Scheme's zmq egg


Well, I looked further into zeromq after watching the youtube video and reading the guide.
My last post was just my curiosity about it. Zeromq is a messaging library with many different language bindings although I prefer to use scheme for most programming tasks. Moritz Heidkamp implemented an excellent chicken scheme language binding for zeromq. Zeromq eases the task of writing distributed applications so it can make our life easier and there is no need to learn erlang to accomplish writing distributed programs.

Compared to other language bindings for this library the chicken scheme zmq egg provides a much higher level of abstraction than most of the other language bindings for zeromq messaging library. In my opinion it's a much easier to use binding for working with zeromq.

So I thought I'll try my hand at writing the example programs in scheme from the guide using the zmq egg.
hwserver.scm
(use zmq format loop ports)

(define serializer (make-parameter write))
(define deserializer (make-parameter read))


(define (main)
  (let ((responder (make-socket 'rep))
        (reply "World"))
    (bind-socket responder "tcp://127.0.0.1:5555")
    (loop
     (format #t "Received request: ~A~%"
             (with-input-from-string
                 (let goto ()
                   (let ((msg (receive-message responder)))
                     (or msg (begin
                               (thread-wait-for-i/o! (socket-fd responder) #:input)
                               (goto)))))
               (deserializer)))
    ;; Do some work
     (sleep 1)

     ;; Send reply back to client
     (send-message responder
                   (with-output-to-string (cut (serializer) reply))))))
(main)

hwclient.scm
(use zmq format ports miscmacros)

(define serializer (make-parameter write))
(define deserializer (make-parameter read))

(define (main)
  (let ((sock (make-socket 'req)))
    (format "Connecting to hello world server...~%")
    (connect-socket sock "tcp://127.0.0.1:5555")

    ;; Do 10 requests, waiting each time for a response
    (dotimes (request-cnt 10)
             (let ((request "Hello"))
               (format #t "Sending request ~D...~%" request-cnt)
               (send-message sock
                             (with-output-to-string (cut (serializer) request)))

               ;; Get the reply
              (format #t "Received reply ~D: ~A~%"
                        request-cnt
                        (with-input-from-string
                            (let loop ()
                              (let ((msg (receive-message sock)))
                                (or msg (begin
                                          (thread-wait-for-io! (socket-fd sock) #:input)
                                          (loop)))))
                          (deserializer)))))))
(main)

Networking just got a little more simpler with zeromq. Thanks to Pieter Hintjens, Moritz Heidkamp an every one on #chicken and #zeromq at irc.freenode.net.

Saturday, February 12, 2011

ØMQ with scheme language bindings are nice ;)



'(ØMQ-language-bindings)
But just how nice? Guess I'll have to investigate further.

Wednesday, January 12, 2011

Emacs + Scheme IDE

Recently I just be relaxing and being lazy. Although over the last few
days I had been contemplating on setting up myself a more comfortable
environment for scheme within Emacs for Scheme programming.

Seeing that I am not a WIMP addict, so an Emacs solution will suffice for my purposes.  In the pursuit of automatic indenting on hitting the return when
working the REPL or with a file.

After searching I've ran across iuscheme from Indiana University.

Now I can use Ctrl-C Ctrl-I to re-indent definitions quickly and easily and
it automatically indents my code properly at the REPL and within files.


I am no scheme expert just another scheme enthusiast looking for a
comfortable work environment with Scheme '(Larceny) and Emacs.