Article View: comp.lang.prolog
Article #1060Re: Simple Prolog Question
From: Saumya K. Debray
Date: Fri, 10 Aug 1990 17:04
Date: Fri, 10 Aug 1990 17:04
30 lines
1193 bytes
1193 bytes
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
Technical Details
Message-ID:
<24120@megaron.cs.arizona.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!noao!arizona!debrayReferences:
<2157@cernvax.UUCP> <3542@goanna.cs.rmit.oz.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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