Re: Suggestions for dcg_basics
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 10/18/2013 01:59 AM, Richard A. O'Keefe wrote: > > On 18/10/2013, at 3:16 AM, Jan Wielemaker wrote: > >> On 10/17/2013 02:56 AM, Richard A. O'Keefe wrote: >>> (By the way, string//1 is a *bad* name for this predicate because it is >>> *NOT* in any way restricted to strings. > >> Not sure I agree here. The library as a whole is defined to do meaningful things with strings of character codes, such as parsing >> numbers, skipping blanks, etc. In that context string//1 is IMHO >> a fair name. This doesn't exclude an equivalent predicate with >> a different name that fits another domain. > > How many copies of append/3 do we need? It doesn't really hurt to have domain dependent names. For example library(ordsets) has ord_empty/1, which is the same as X = []. We I didn't invent that ... We could defend that as an abstract data type, but I think it is not a secret that ordered sets are lists with ordered elements and one is allowed to use normal list operations on them (e.g., maplist). `String' means `sequence of characters', which is exactly what it matches. I did invent string//1. According to Wikipedia, we also have "In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set called an alphabet.", an interpretation that makes string//1 a fair name for lists that do not represent characters. > In a "library" which "is defined to do meaningful things with strings > of character codes, such as parsing numbers, skipping blanks, etc.", > I expect string//1 to match a string literal. > > In fact, *especially* in such a library do I expect it to > match nothing other than a string literal. I'd call that quoted_string//1, string_literal//1 or something similar. Afterall, it does a lot more than handling a simple sequence, such as interpreting escape sequences. I'm happy to include your code into this library if you are happy if it is renamed and comment layout is changed to match PlDoc. Cheers --- Jan > Like the attached code, which may be of use to somebody. > (I wanted to put it inline, but > TextEdit/Copy + Mail/Paste flattened it into a sequence of words. > How do I get that combination to preserve layout?) > This code has been *partly* tested, but not really thoroughly. > I whipped it up just now to make a point. > > -------------- next part -------------- > A non-text attachment was scrubbed... > Name: string.pl > Type: text/x-perl-script > Size: 6129 bytes > Desc: not available > URL: <https://lists.iai.uni-bonn.de/pipermail/swi-prolog/attachments/20131018/2262a17d/attachment.bin> > -------------- next part -------------- > > > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog >