I am trying to learn Racket, and in the process I am trying to rewrite the Python filter. There are two pairs of functions in my code:
def dlv(text): """ Returns True if the given text corresponds to the output of DLV and False otherwise. """ return text.startswith("DLV") or \ text.startswith("{") or \ text.startswith("Best model") def answer_sets(text): """ Returns a list comprised of all of the answer sets in the given text. """ if dlv(text):
From what I can say, the implementation of the first function in Racket will be something like the following lines:
(define (dlv-input? text) (regexp-match? #rx"^DLV|^{|^Best model" text))
It seems to work correctly. While working on the implementation of the second function, currently I have come up with the following (for starters):
(define (answer-sets text) (cond [(dlv-input? text) (regexp-match* #rx"{(.*?)}" text)]))
This is not true since regexp-match* gives a list of strings that match the regular expression, including curly braces. Does anyone know how to achieve the same behavior as in a Python implementation? In addition, any suggestions on how to make regular expressions โbetterโ would be greatly appreciated.
ggelfond
source share