Brief Intro Script

rfi-l> exec brief-intro

rfi-l> style lisp
rfi-l> inter
rfi-l> replace brief-intro
; Reading file "/serv-301a/sintek/RELFUN/RFM/demo/sampler/brief-intro.rf" ..
rfi-l> ;-----------------------------------------------------------------------
rfi-l> ;|  A brief introduction to basic RELFUN, using its LISP-like syntax   |
rfi-l> ;|                          Harold Boley                               |
rfi-l> ;|                   Mar 1991 (rev.: Feb 1992)                         |
rfi-l> ;-----------------------------------------------------------------------
rfi-l> 
rfi-l> ; In RELFUN, a LISP list (e1 ... eN) or PROLOG list [e1,...,eN] is
rfi-l> ; represented as an (N-)tup(le) structure (tup e1 ... eN).
rfi-l> ; Logical variables are marked by an underscore, "_".
rfi-l> ; The PROLOG list pattern [1,2|V] becomes (tup 1 2 | _v),
rfi-l> ; matching instances like (tup 1 2 3 4 5) with the binding
rfi-l> ; _v = (tup 3 4 5).
rfi-l> 
rfi-l> ; A PROLOG clause c(...) :- b1(...), .., bM(...). in RELFUN becomes a
rfi-l> ; 'hornish' (or hn) clause (hn (c ...) (b1 ...) .. (bM ...)),
rfi-l> ; where facts just have no premise (M=0).
rfi-l> ; A conditional equation g(...) = f(...) if b1(...), .., bM(...)
rfi-l> ; in RELFUN is generalized to (ft (g ...) (b1 ...) .. (bM ...) (f ...)),
rfi-l> ; an ft (or 'footed') clause, whose "b" premises may accumulate partial
rfi-l> ; results and whose "f" premise returns possibly (non-)ground/
rfi-l> ; (non-)deterministic values.
rfi-l> 
rfi-l> ; As in LISP, nestings like (+ (* 3 3) (1- 8)) => 16 are reduced
rfi-l> ; call-by-value. "Passive" structures are marked by a backquote, "`",
rfi-l> ; except in clause heads.
rfi-l> ; RELFUN's tup FUNCTION returns the tup STRUCTURE of its evaluated
rfi-l> ; arguments:
rfi-l> ; (ft (tup | _r) `(tup | _r)) 
rfi-l> ; _r will be bound to the tup of all arguments.
rfi-l> ; This permits calls like
rfi-l> (is _t 3) (tup `(* _t _t) (1- 8))
`(tup (* 3 3) 7)
(_t = 3)
rfi-l> 
rfi-l> ; The below definitions of append and naive reverse illustrate our
rfi-l> ; RELational/ FUNctional merger (e.g., "is" can invert functions almost
rfi-l> ; as if relations).
rfi-l> ; PROLOGish REL style (inversion (revrel _u (tup 1 2)) loops on MORE):
rfi-l> ; Using nested or flattened clauses, the RELFUN interpreter allows
rfi-l> ; this dialog:
rfi-l> 
rfi-l> ; relational:
rfi-l> (apprel (tup 1 2) (tup a) _u)
true
(_u = `(tup 1 2 a))
rfi-l> 
rfi-l> ; functional:
rfi-l> (appfun (tup 1 2) (tup a))
`(tup 1 2 a)
rfi-l> 
rfi-l> ; relational:
rfi-l> (apprel _i _j (tup 1 2 a)) 
true
(_i = `(tup))
(_j = `(tup 1 2 a))
rfi-l> more
true
(_i = `(tup 1))
(_j = `(tup 2 a))
rfi-l> more
true
(_i = `(tup 1 2))
(_j = `(tup a))
rfi-l> 
rfi-l> ; functional
rfi-l> (is (tup 1 2 a) (appfun _i _j))
`(tup 1 2 a)
(_i = `(tup))
(_j = `(tup 1 2 a))
rfi-l> more
`(tup 1 2 a)
(_i = `(tup 1))
(_j = `(tup 2 a))
rfi-l> more
`(tup 1 2 a)
(_i = `(tup 1 2))
(_j = `(tup a))
rfi-l> 
rfi-l> ; A function called with a non-ground "|"-list:
rfi-l> (revfun (tup a b | _v))
`(tup b a)
(_v = `(tup))
rfi-l> ; Returned value no. 1 is ground (variableless) because _v can be
rfi-l> ; bound to the empty list.
rfi-l> more
`(tup _first*21 b a)
(_v = `(tup _first*21))
rfi-l> ; The request for MORE solutions (PROLOG's ";") returns a 3-list pattern
rfi-l> ; starting with _first:xx, a (free) variable also occurring in _v.
rfi-l> more
`(tup _first*33 _first*32 b a)
(_v = `(tup _first*32 _first*33))
rfi-l> ; Another MORE (of infinitely many successes) now returns a non-ground
rfi-l> ; list of length 4, whose first two elements reverse those in _v.