From 8b54b05c54e076af2712ff2fe599cbc2bcd8d381 Mon Sep 17 00:00:00 2001 From: Vitaly Mayatskikh Date: Fri, 25 Sep 2009 22:53:48 +0200 Subject: [PATCH] Implement new rplet macro, zap rlet. rplet macro was rewritten using of eager-future. rlet was abandoned. --- cluster.lisp | 30 +++++++++++++++--------------- tests.lisp | 13 ++++++++++--- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/cluster.lisp b/cluster.lisp index 52fdc68..029c124 100644 --- a/cluster.lisp +++ b/cluster.lisp @@ -158,18 +158,18 @@ This is useful to skip interactive prompt.")) "Execute body at remote host." `(node-exec ,node (format nil "~s" '(progn ,@body)))) -(macrolet ((defrlet (name f doc) - `(defmacro ,name (node vars &body body) - ,doc - (let ((v (loop :for i :in vars - :collect (car i) :into x - :collect (cadr i) :into y - :finally (return (list (null x) x y))))) - `(node-exec ,node - ,(if (car v) `(format nil "~s" '(progn ,@body)) - `(format nil "(let ~s ~s)" - (mapcar #'list ',(cadr v) - (,,f #'eval ',(caddr v))) - '(progn ,@body)))))))) - (defrlet rlet 'mapcar "Let-like macro for remote lisp. Evaluate vars using mapcar.") - (defrlet rplet 'pmap "Let-like macro for remote lisp. Evaluate vars using pmap.")) +(defmacro rplet (node (&rest bindings) &body body) + "Let-like macro for remote lisp. Evaluate vars using pmap." + (let ((syms (mapcar (lambda (x) + (gensym (string (car x)))) + bindings))) + `(node-exec ,node + ,(if (null syms) `(format nil "~s" '(progn ,@body)) + `(format nil "(let ~s ~s)" + (let ,(loop for (nil exp) in bindings + for sym in syms + collect `(,sym (pexec ,exp))) + (list ,@(loop for (var nil) in bindings + for sym in syms + collect `(list ',var (yield ,sym))))) + '(progn ,@body)))))) diff --git a/tests.lisp b/tests.lisp index 2f9a779..e6f5388 100644 --- a/tests.lisp +++ b/tests.lisp @@ -6,7 +6,7 @@ (let ((node1 (make-instance 'node :host "rhel4" :connect t)) (node2 (make-instance 'node :host "rhel5" :connect t)) (node3 (make-instance 'node :host "rhel5" :lisp "/usr/bin/clisp -q" :connect t))) - (declare (special node1 node2 node3)) +; (declare (special node1 node2 node3)) (dolist (node (list node1 node2 node3)) (when (node-alive-p node) @@ -20,7 +20,7 @@ (error (condition) (format t "got error: ~A~%" condition))))) - (print (rlet node3 + (print (rplet node3 ((a (with-remote node1 (+ 1 2))) (b (with-remote node2 @@ -53,6 +53,14 @@ t (* a b)) +(plet + ((a (with-remote n1 + (+ 1 2))) + (b (with-remote n2 + (sqrt 7d0)))) + t + (* a b)) + ;; catch exception (with-remote n1 nil @@ -67,4 +75,3 @@ ;; avoid reader error (with-remote n1 (asdf:oos 'asdf:load-op :asdf)) - -- 2.11.4.GIT