\documentclass{jarticle}

\usepackage[dvips]{graphics}
% \usepackage{moreverb}

\setlength{\textwidth}{14.5cm}
\setlength{\textheight}{22.5cm}
\setlength{\oddsidemargin}{0.75cm}
\setlength{\evensidemargin}{0.75cm}

\newcommand{\Comment}[1]{}

\title{}
 % DKLIC $B=hM}7O$K$*$1$kJ,;6O@M}JQ?t$N;q8;4IM}(B \\
 % Resource Management for Distributed Logic Variables of DKLIC }
\author{}
 % 600P031-4 $B9bLZM42p(B $B>eED8&5f<<(B \\
 % TAKAGI Yusuke, Ueda Laboratory }
\date{} % 2002$BG/(B2$B7n(B13$BF|(B }
\begin{document}
% \maketitle

\twocolumn

\begin{verbatim}
:- module rpc_client.

new(Host, Port, RPC) :- true |
  klicio:klicio(S),
  S = [connect(inet(Host, Port), R)]
  new1(RPC, R).
new1(RPC, R) :- R = normal(Sock) |
  rpc(RPC, Sock).

rpc(RPC, Sock) :- RPC=[M:Call|RPC1] |
  io:put(Sock, Sock1, M:Call, Res),
  RPC = [Res | RPC1],
  rpc(RPC1, Sock1).



:- module io.

put(Sock,Sock_,Put,Get) :- wait(Put) |
  Sock = [putt(Put),
    fwrite("\n."), fflush(F) | Sock1],
  get(Sock1, Sock_, F, Get).

get(Sock, Sock_, F, Get) :- wait(F) |
  Sock = [gett(Get) | Sock_].
\end{verbatim}

\section*{ Remote Predicate Call }
\newpage

\begin{verbatim}
:- module rpc_server.

args_vector(F,Arity,V,L) :- Arity=:=0 |
  new_vector(V, L).
args_vector(F,Arity,V,L) :- Arity > 0 |
  arg(Arity, F, Arg),
  L1 = [Arg | L],
  Arity1 := Arity - 1,
  args_vector(F, Arity1, V, L1).

new(Port) :- true |
  klicio:klicio([bind(inet(Port),R)]),
  new1(R).
new1(R) :- R = normal(ServSock) |
  accept(ServSock).

accept(ServSock) :- true |
  ServSock = [accept(R) | ServSock1],
  accept1(ServSock1, R).
accept1(ServSock,R) :- R=normal(Sock) |
  io:get(Sock, Sock1, 0, Get),
  rpcd(Sock, Get),
  accept(ServSock).

rpcd(Sock, Get) :- Get = (M:Call) |
  functor(Call, Name, Arity),
  Arity1 := Arity + 1,
  generic:new(module, Modu, M),
  generic:new(predicate,
    Pred, Modu, Name, Arity1),
  args_vector(Call, Arity, V, [Res]),
  apply(Pred, V),
  io:put(Sock, Sock1, Res, Get),
  rpcd(Sock1, Get).
\end{verbatim}

\newpage

\begin{verbatim}
:- module rpc_client.

new(Host, Port, RPC) :- true |
  dklicio:connect(Host, Port, R),
  new1(RPC, R).
new1(RPC, R) :- R = normal(Sock) |
  RPC = Sock.
\end{verbatim}

\newpage

\begin{verbatim}
:- module rpc_server.

args_vector(F,Arity,V,L) :- Arity=:=0 |
  new_vector(V, L).
args_vector(F,Arity,V,L) :- Arity > 0 |
  arg(Arity, F, Arg),
  L1 = [Arg | L],
  Arity1 := Arity - 1,
  args_vector(F, Arity1, V, L1).

new(Port) :- true |
  dklicio:bind(Port, R),
  new1(R).
new1(R) :- R = normal(ServSock) |
  accept(ServSock).

accept(ServSock) :- true |
  ServSock = [accept(R) | ServSock1],
  accept1(ServSock1, R).
accept1(ServSock,R) :- R=normal(Sock) |
  rpcd(Sock),
  accept(ServSock).

rpcd(Sock) :- Sock = [M:Call|Sock1] |
  functor(Call, Name, Arity),
  generic:new(module, Modu, M),
  generic:new(predicate,
    Pred, Modu, Name, Arity),
  args_vector(Call, Arity, V, []),
  apply(Pred, V).
\end{verbatim}

\onecolumn

\newcommand{\fig}[1]
  {\scalebox{0.5}{\includegraphics{fig/fuse#1.eps}}\vspace{4em}}

\fig{1}
\fig{2}

\newpage

\fig{3}
\fig{4}

\section*{ $B;0<TDL?.(B --- $BCf7Q$N=*N;(B }

\end{document}
