title: Detecting if script executed from command line in Racket?
body: <p>I'm new to Racket (and Lisp's in general) and I'm wondering if there's a canonical way to detect if a script was run from the command line?</p>
  
  <p>For example, in Python the standard way to do this would be with <code>if __name__ == __main__:</code> as so:</p>
  
  <pre><code>def foo():
      "foo!"
  
  if __name__ == "__main__":
      foo()
  </code></pre>
  
  <p>Now, suppose I having the following Racket code, and I'd like <code>respond</code> to be invoked only when this is run as a script.</p>
  
  <pre><code>#lang racket
  (require racket/cmdline)
  
  (define hello? (make-parameter #f))
  (define goodbye? (make-parameter #f))
  
  (command-line #:program "cmdtest"
                #:once-each
                [("-H" "--hello") "Add Hello Message" (hello? #t)]
                [("-G" "--goodbye") "Add goodbye Message" (goodbye? #t)])
  
  (define (respond)
    (printf "~a\n"
            (apply string-append 
                   (cond
                    [(and (hello?) (goodbye?)) '("Hello" " and goodbye.")]
                    [(and (hello?) (not (goodbye?))) '("Hello." "")]
                    [(and (not (hello?)) (goodbye?)) '("" "Goodbye.")]
                    [else '("" "")]))))
  </code></pre>
  
  <p>Is there an easy/standard way to achieve what I want?</p>