A Simple Auction System


Problem

A set of items is offered for sale at an initial price. A server process holds the information about the items. Client processes connect to the server and bid on individual items. The auction terminates after a specified interval.

Code

K scripts for server and client.

Server

/ auction server

if[~_p;."\\m i 1234"]
\d A
desc:-20$("a book";"a chair";"a apple")
by:10 20 1.
who:0 0 0
num:0 0 0
bid:100 500 20.
\d ^
A[.;`e]:0
W:!0
.m.c:"W:W _dv _w"
get:{(T;A;*|W,:_w)}
set:{:[A.by[y]>x-A.bid y;_w 3:(`A;(`bid;y);:;A.bid y);accept[x]y]}
accept:{W 3:\:(`A;(`bid`who`num;y);:;A[`bid`who`num;y]:x,_w,1+A.num y)}
T:900
T..e:0
T..t:":[T;W 3:\\:(`T;();-;1);3::'W];"
.t..t:"if[.k.T>0;.k.T-:1]"
.k..c:`form
.k..a:`T`A
.k..l:`server
`show$`.k
\t 1

Client

/ auction client

H:3:(:[1>#_i;`;`$*_i];:[2>#_i;1234;0$_i 1])
.m.c:"H:0"
@[_d;`T`A`W;:;H 4:(`get;)];
T..e:0
A.bid..e..d:".k.H>0"
A.bid..t:"if[~_w;.k.H 3:(`set;(_v ._i;*_i))]"
A[.;`fg]:{:[W=A.who ._i;99]}
.k..c:`form
.k..a:`T`A
.k..l:`client
`show$`.k

GUI