[racket] modules: require and provide behaviour

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Fri Apr 20 17:01:42 EDT 2012

Dear list members,

Perhaps someone could explain this "module,require and provide" behaviour.

I've created a Racket module that provides a procedure that creates a
simple GUI dialog to return a file path and another module that uses
the procedure.

The module to create the GUI is:


#lang racket/gui
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This module displays a gui file dialog
;; to return a page of devanagari text for
;; testing.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(provide get-devanagari-page)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Define and display top level window
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (get-devanagari-page)
  (define main-ocr-frame (new frame%
                              [label  "DEVANAGARI OCR"]	
                              [width  10000]	
                              [height 10000]))


  ;Main title
  (define title (new message%
                     [parent main-ocr-frame]
                     [label "DEVANAGARI OCR PROJECT"]
                     [font (make-object font% 20 'modern  'normal 'bold)]))

  ; Display main window
  (send main-ocr-frame show #t)

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  ;Display message-box allowing user to continue or exit program
  (when (equal? 'no (message-box
                     "CONVERT PAGE TO DEVANAGARI"	
                     "Do you want to continue?                 " 	
                     main-ocr-frame  ;parent	
                     '(yes-no)))     ;style
    (exit))

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


  ;If continuing then display a get file dialog to get devanagari-page
  ; which is a page of devanagari text to OCR.

  (get-file
   "Get Devanagari input file" ;title
   main-ocr-frame              ;parent
   "C:\\Users\\Harry\\OCR_PROJECT\\DEVANAGARI_PAGE_IMAGES" ;start directory
   "devanagari_page_3.gif" ;default filename
   #f ;default extension
   null ;style - on Windows null means use native window style,
   ;                       '(common) means use platform independent style
   '(("Any" "*.*") ("Common graphics jpg and gif" "*.jpg;*.gif")
("JPEG *.jpg" "*.jpg") ("GIF *.gif" "*.gif"))
   ))
-------------------------------------------
------------------------------------------
When I type
>(get-devanagari-page)
in the interactions window everything works fine and the window and
dialogs display and behave correctly.

BUT in following module which requires the above module, for it to
work I need to code "get-devanagari-page" NOT (get-devanagari-page)

I.e this works and returns a file path.:

Module get-devanagari-page.rkt
-----------------
#lang racket/gui
(require "imagemagick_interface.rkt")
(require "get-devanagari-page.rkt")
get-devanagari-page
----------------------------

BUT the following displays the gui and executes  but gives an
error:procedure application: expected procedure, given:
#<path:C:\Users\Harry\OCR_PROJECT\DEVANAGARI_PAGE_IMAGES\devanagari_page_3.gif>
(no arguments)

Module main.rkt
-------------------
#lang racket/gui
(require "imagemagick_interface.rkt")
(require "get-devanagari-page.rkt")

(get-devanagari-page)

---------------------------
It appears to me that coding "get-devanagari-page"  in module
"main.rkt" causes procedure "get-devanagari-page" to be applied.  Can
someone explain to me why in that case  it is applied and  it doesn't
just return #<procedure:get-devanagari-page> without being applied as
it does when typed in the interactions pane.

Thanks,
Harry Spier

Posted on the users mailing list.