I've written the following simple filter in Racket as my first Racket program and am wondering if I am writing it in an "idiomatic Racket style".
#! /usr/bin/env racket
#lang racket
(require racket/cmdline)
(define a-prolog-mode? (make-parameter #f))
;; parses the options passed on the command-line
(command-line
#:program "patoms"
#:once-any
[("-a" "--aprolog") "output as A-Prolog code"
(a-prolog-mode? #t)])
;; dlv-input? : string -> boolean
;; Returns True if the given text corresponds to the output of DLV
;; and False otherwise. DLV's output is prefixed by one of the following
;; strings: "DLV", "{", or "Best model".
(define (dlv-input? text)
(regexp-match? #rx"^DLV|^{|^Best model" text))
;; text->answer-sets : string -> list of strings
;; Returns a list comprised of all of the answer sets in the given text.
(define (text->answer-sets text)
(cond
[(dlv-input? text) (regexp-match* #rx"{(.*?)}" text #:match-select cadr)]
[else null]))
;; write-as-code : string
;; Writes the given answer set in plain text form to standard output.
(define (write-as-text answer-set)
(let ([literals (map string-trim (string-split answer-set ","))])
(cond
[(empty? literals) (printf "~a~n" "{}")]
[else (for-each (λ (literal) (printf "~a~n" literal)) literals)])
(printf "~a~n" "::endmodel")))
;; write-as-code : string
;; Writes the given answer set as A-Prolog code to standard output.
(define (write-as-code answer-set)
(let ([literals (map string-trim (string-split answer-set ","))])
(for-each (λ (literal) (printf "~a.~n" literal)) literals)
(printf "~a~n" "%%endmodel")))
;; main
;; Serves as the main function of the program. If a-prolog-mode is specified
;; by the user via the command-line, all of the answer sets that may be parsed
;; from standard input are written to standard output as A-Prolog. Otherwise
;; the answer sets are written in a plain text format.
(define (main)
(let* ([text (port->string (current-input-port))]
[answer-sets (text->answer-sets text)])
(cond
[(a-prolog-mode?) (for-each write-as-code answer-sets)]
[else (for-each write-as-code answer-sets)])))
(main)
In general, any and all feedback would be very much appreciated given that this is my first foray into Racket.
Thank you kindly in advance.