Re: How do I shorten or split this function



On Feb 2, 5:10 pm, "An[z]elmus" <some...@xxxxxxxxxxxxx> wrote:
(defun field-matches-p (string field-type)
 "Predicate to test if STRING could be a field of type FIELD-TYPE"
 (let ((regex (cdr (assoc field-name *bib-regexes*))))     ;<<<<<<
   (if regex
   (scan regex string)
     t)))

Here you are using SCAN from the CL-PPCRE package.
Instead of field-name you mean field-type.

oops

I don't understand (yet) why the function returns true (if (not
regex))

If there's no regular expression associated with the field type, then
it doesn't test the string to see if it's of the suitable form for the
field, it just assumes that it is.

Back again to FIELD-MATCHES-P (and EVERY): in this case EVERY returns
true if and only if each element of record FIELD-MATCHES-P each
element of pattern.

Exactly. So you only test patterns of the same length as the input,
and you find the first one where every string in the input matches the
corresponding field of the pattern. The patterns are ordered so that
the more specific fields (author, title3) take precedence over the
less specific ones.

If you want to change the type of the records created, you just need
to change MAKE-BIB-ENTRY, similarly, you can set up various ways to
handle unmatched inputs (have a look at the section on error handling
in "Practical Common Lisp".

btw I had a look at the catalogue files & can only commiserate :)
.



Relevant Pages

  • Re: Regex question
    ... structure of the date you're trying to extract. ... For example, in Regex you can ... pattern that will ensure a valid date within the range allowed by T-SQL ... valid date from a string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: regex
    ... case sensitivity was part of the problem which I fixed with ... In other word I got syntax problem with the month pattern ... >>against the articles and help on regex, I still can't find the mistake I ... >> Public Function regtest(ByVal StringIn As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Expressing AND, OR, and NOT in a Single Pattern
    ... much better because the esoterica of regex can make the desired ... results hard to figure out and the bugs in the pattern even harder to ... The only thing I'd do differently to these patterns is add an anchor ... long strings, when the pattern was at the end of the string. ...
    (comp.lang.perl.misc)
  • Re: Interaction between two strings
    ... then the string XYZC should give a match. ... > string that is supplied separately from the regex. ... $patterns, you splice them all into one very big $pattern. ... Doing this is immensely faster than iterating through an array or the like: ...
    (comp.lang.perl.misc)
  • Re: Fastest way to search a string for the occurance of a word??
    ... but the OP's question was what's the "Fastest way to search a string ... in all the tests I did here, the Regex was by far superior. ... However, of course, if you've got new regular expressions all ... Sure - but just that extra Match object could be relevant if the search ...
    (microsoft.public.dotnet.languages.csharp)

Loading