Prolog - List Append.

LA home
Computing
Logic
 Prolog
  Intro.
  Syntax
  Examples
   Windsor
   Append
   Aunt
   Solar
   Diff
   Tree
   Witch
The Append program can be used to append two lists:
append(c(H,T), B, c(H,TB)) <= append(T, B, TB).
append(nil, B, B).

? append( c(1, c(2, nil)), c(3, c(4, nil)), X).

{ Append run Forwards. }




 
The same program can also be run "backwards" to take a list apart:
append(c(H,T), B, c(H,TB)) <= append(T, B, TB).
append(nil, B, B).

? append( X, Y, c(1, c(2, c(3, nil))) ).

{ Append run Backwards. }




In this case there are four pairs of lists, X and Y, which give c(1, c(2, c(3, nil))) when appended.
www #ad:

↑ © L. Allison, www.allisons.org/ll/   (or as otherwise indicated).
Created with "vi (Linux)",  charset=iso-8859-1,   fetched Wednesday, 24-Apr-2024 21:21:39 UTC.

Free: Linux, Ubuntu operating-sys, OpenOffice office-suite, The GIMP ~photoshop, Firefox web-browser, FlashBlock flash on/off.