Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!hplabs!hplabsz!kirshenb From: kirshenb@hplabsz.HPL.HP.COM (Evan Kirshenbaum) Newsgroups: comp.lang.prolog Subject: Lists (was Arrays) in Prolog Message-ID: <6009@hplabsz.HPL.HP.COM> Date: 4 Oct 90 00:00:12 GMT References: <1238@ecrc.de> <1990Sep19.075314.14372@irisa.fr> <1403@ecrc.de> <34487@cup.portal.com> Reply-To: kirshenb@hplabsz.UUCP (Evan Kirshenbaum) Organization: Hewlett-Packard Laboratories Lines: 49 In article <34487@cup.portal.com> pgl@cup.portal.com (Peter G Ludemann) writes: >> I would like to point out that there is no such thing as >Can we change the subject a bit? How about list structures >which can be as easily accessed from the end as from the front? >That, to me, is the big advantage of arrays; not the performance >improvement. Does anyone have a nice notation for getting the >last element of a list as opposed to the first element? > Once upon a time, I was playing with the design of a language based on prolog, and one of the extensions was exactly this. The notation I used was: [A,B,C] a sequence containing exactly A, B, and C [A,...] a sequence starting with A [A,..As] a sequence with head A and tail As [...,L] a sequence ending in L [..Ls,L] a sequence ending in L with everything up to it Ls [...,X,...] a sequence containing X [..Pre,..Mid,..Post] a sequence partitioned into Pre, Mid, and Post [...,X,...,Y,...] a sequence in which X occurs before Y I called ..X a splice (... was equivalent to .._), and it was an actual object in the sequence (although you couldn't get one outside of a sequence). Unifying a sequence that contained splices was possibly nondeterministic, but was reasonably easy to implement. Multiple solutions were obtained on backtracking. This allowed you to define append(Xs,Ys,[..Xs,..Ys]). member(X,[...,X,...]). last(L,[...,L]). If you unified [..ButLast,Last] with [..Pre,X,..Post] you got ButLast = Pre = Post = [], Last = X and ButLast = [..Pre,X,..As], Post = [..As,L] My system also contained a notion of anonymous variables, so sequences with anonymous splices were relatively cheap as well (no structures needed to be consed). Evan Kirshenbaum HP Laboratories 3500 Deer Creek Road, Building 26U Palo Alto, CA 94304 kirshenbaum@hplabs.hp.com (415)857-7572