Next: serialiser Up: Beispiele in zwei Previous: revise

serialisef


rfi-p> 
style lisp
rfi-l> destroy
rfi-l> consult "/home/rfm/RFM/extensions/serialisef.rf"
; Reading file "/home/rfm/RFM/extensions/serialisef.rf" ..
rfi-l> listing
(ft (serialise _l)
    (numbered (arrange (pairlists _l _r)) 1)
    _r )
(ft (pairlists (tup _x | _l) (tup _y | _r))
    (tup
     `(pair _x _y)
     |
     (pairlists _l _r) ) )
(ft (pairlists (tup) (tup))
    (tup) )
(ft (arrange (tup _x | _l))
    (partition _l _x _l1 _l2)
    (is _t1 (arrange _l1))
    (is _t2 (arrange _l2))
    `(tree _t1 _x _t2) )
(ft (arrange (tup))
    void )
(hn (partition (tup _x | _l) _x _l1 _l2)
    (partition _l _x _l1 _l2) )
(hn (partition
     (tup _x | _l)
     _y
     (tup _x | _l1)
     _l2 )
    (before _x _y)
    (partition _l _y _l1 _l2) )
(hn (partition
     (tup _x | _l)
     _y
     _l1
     (tup _x | _l2) )
    (before _y _x)
    (partition _l _y _l1 _l2) )
(hn (partition (tup) _y (tup) (tup)))
(hn (before (pair _x1 _y1) (pair _x2 _y2))
    (string< _x1 _x2) )
(ft (numbered
     (tree _t1 (pair _x _n1) _t2)
     _n0 )
    (numbered _t2 (1+ (is _n1 (numbered _t1 _n0)))) )
(ft (numbered void _n)
    _n )
rfi-l> style prolog
rfi-p> listing
serialise(L) :- numbered(arrange(pairlists(L, R)), 1) & R.
pairlists([X | L], [Y | R]) :-& tup(pair[X, Y] | pairlists(L, R)).
pairlists([], []) :-& tup().
arrange([X | L]) :- partition(L, X, L1, L2),
                    T1 is arrange(L1),
                    T2 is arrange(L2) &
                    tree[T1, X, T2].
arrange([]) :-& void.
partition([X | L], X, L1, L2) :- partition(L, X, L1, L2).
partition([X | L],
          Y,
          [X | L1],
          L2) :- before(X, Y), partition(L, Y, L1, L2).
partition([X | L],
          Y,
          L1,
          [X | L2]) :- before(Y, X), partition(L, Y, L1, L2).
partition([], Y, [], []).
before(pair[X1, Y1], pair[X2, Y2]) :- string<(X1, X2).
numbered(tree[T1, pair[X, N1], T2], N0) :-& 
  numbered(T2, 1+(N1 is numbered(T1, N0))).
numbered(void, N) :-& N.


Harold Boley & Michael Herfert (herfert@dfki.uni-kl.de)