Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!noao!arizona!debray From: debray@cs.arizona.edu (Saumya K. Debray) Newsgroups: comp.lang.prolog Subject: Re: Simple Prolog Question Message-ID: <24120@megaron.cs.arizona.edu> Date: 10 Aug 90 17:04:15 GMT References: <2157@cernvax.UUCP> <3542@goanna.cs.rmit.oz.au> Organization: U of Arizona CS Dept, Tucson Lines: 30 Richard A. O'Keefe (ok@goanna.cs.rmit.oz.au) writes: > A pure way of doing it is > > remove_leading_blanks([], []). > remove_leading_blanks([H|T], [H|T]) :- H =\= " ". > remove_leading_blanks([H|T], R ) :- H =:= " ", > remove_leading_blanks(T, R). > > If you don't mind a red cut, you can do > > remove_leading_blanks([32|T], R) :- !, > remove_leading_blanks(T, R). > remove_leading_blanks(T, R). I think I would prefer the following ("look, Ma, no choice points"): remove_leading_blanks([], []). remove_leading_blanks([H|T], L) :- H =:= " " -> remove_leading_blanks(T, L) ; L = [H|T]. -- Saumya Debray CS Department, University of Arizona, Tucson internet: debray@cs.arizona.edu uucp: uunet!arizona!debray