Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!olivea!samsung!munnari.oz.au!lee From: lee@munnari.oz.au (Lee Naish) Newsgroups: comp.lang.prolog Subject: Re: Standards question: behavior of arg/3 Keywords: ANSI, standard Message-ID: <5817@munnari.oz.au> Date: 19 Oct 90 09:18:17 GMT References: <9888@bunny.GTE.COM> Sender: news@cs.mu.oz.au Reply-To: lee@munmurra.UUCP (Lee Naish) Organization: Comp Sci, University of Melbourne Lines: 28 In article brahme@vlsic2.ti.com (Dan Brahme) writes: >If the ISO standard arg(N, Term, Arg) reports error when N is greater >than the arity, it is a nuisance. > >Then we cannot do > bagof(Arg, N^arg(N, Term, Arg), Args). Sorry to be pedantic, but you can't do that anyway in most systems (see other postings on this topic). >or > bagof(Arg, N^(positive_integer(N), arg(N, Term, Arg)), Args). > where positive_integer is > positive_integer(1). > positive_integer(N) :- positive_integer(N1), N is N1 + 1. This code loops. One way to do it properly is to use functor/3 to get the arity, then use this as a bound on the integers you generate (use between/3 in Quintus or iota in NU-Prolog). However, if you really want to get a list of all the args in a term you do not want to use bagof. There is already a builtin for that: Term =.. [Functor | Args] lee