Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcvax!enea!ttds!draken!sics!lhe From: lhe@sics.se (Lars-Henrik Eriksson) Newsgroups: comp.lang.prolog Subject: Re: Prolog riddle - (nf) Message-ID: <1343@sics.se> Date: Tue, 14-Jul-87 07:45:06 EDT Article-I.D.: sics.1343 Posted: Tue Jul 14 07:45:06 1987 Date-Received: Fri, 17-Jul-87 06:47:26 EDT References: <29400001@uklirb.UUCP> Reply-To: lhe@sics.se (Lars-Henrik Eriksson) Organization: Swedish Institute of Computer Science, Kista Lines: 27 In article <29400001@uklirb.UUCP> noekel@uklirb.UUCP writes: >does anyone out there in netland know whether it is possible to write a Prolog >program that > >(1) *generates* natural numbers in ascending order, >(2) does not make use of side effects (assert, retract etc.), >(3) generates the first n numbers in time O(n). > If you want the predicate to generate successive integers each time it is called, then it is impossible to do without side effects. Suppose the predicate foo/1 would do what you want. Then different calls foo(X) would instantiate X to different integers. In Prolog, as in any other language, this can only be done with side effects. If no side effects were involved, the program would have no way of knowing that it had been called before. In logic programming, it is conceivable that you could write a predicate foo/1 such that foo(N) holds for ANY natural number N, but some complex control information make sure that successive calls with N uninstantiated instantiates it to successive natural numbers, but I guess that is not really what you want. (It couldn't be done in Prolog anyway). Lars-Henrik Eriksson, Swedish Institute of Computer Science lhe@sics.sics.se ...mcvax!enea!sics!lhe