Thanks, Jon.  I'm going to try Alex's solution first but I may get back to this.


On May 6, 2020, at 8:49 PM, Jon Zeppieri wrote:

> On Wed, May 6, 2020 at 7:50 PM James Platt <j...@biomantica.com> wrote:
>> 
>> I'm working on organizing and documenting some things and I have some code, 
>> below, which works but I don't understand why.  Specifically, why don't I 
>> get an error about table3 not being defined?
> 
> The reason you don't get an error for the code you posted is because
> the mention of `table3` (before its definition) in `info-menu-item` is
> inside a function body. The referent of the name `table3` isn't
> required to define `info-menu-item`; it's sufficient to know that it
> refers to _something_, and that it will be available when that
> function is (later) called.
> 
>> In other words, I want to be able to define table3 in one file which 
>> requires the file where row-edit-menu is defined but I can't seem to figure 
>> out how to get this to work.
> 
> It's a bit trickier to define these things in separate files, because
> their definitions refer to each other (though indirectly in this
> case), and the module system does not tolerate cyclic dependencies.
> The most straightforward way to break the cycle would be to take
> advantage of the fact that `table3` and `info-menu-item` each depends
> on `row-edit-menu`, and `info-menu-item` further depends on `table3`,
> but `row-edit-menu` doesn't depend on either. So the dependencies
> aren't really cyclical. You can divide stuff up into separate modules
> like so:
> 
> menu.rkt
> ```
> #lang racket
> 
> (require racket/gui/base)
> 
> (provide frame3
>         row-edit-menu)
> 
> (define frame3
>  (new frame%
>       [label "myTable 3"]
>       [width 800]
>       [height 600]))
> 
> (define row-edit-menu (new popup-menu%))
> ```
> 
> 
> table.rkt
> ```
> #lang racket
> 
> (require racket/gui/base
>         qresults-list
>         "menu.rkt")
> 
> (provide table3
>         add-rows)
> 
> ;set up columns
> (define (column1 data) (vector-ref data 0))
> (define (column2 data) (vector-ref data 1))
> 
> (define my-columns
>  (list
>   (qcolumn "Column1" column1 column1)
>   (qcolumn "Column2"
>            (λ (row)
>              ;(displayln row)
>              ;(displayln (db-row-ref row "Column2" headers 1))
>              (if (number? (column2 row)) (number->string (column2
> row)) "");This allows a cell to be blank.
>              ;(number->string (column2 row))
>              )
>            column2)))
> 
> (define table3
>  (new (class qresults-list% (init) (super-new))
>       [parent frame3]
>       [pref-tag 'preferences-tag]
>       [selection-type 'multiple]
>       [right-click-menu row-edit-menu]))
> 
> (define (add-rows)
>  (send table3 add-row (vector "R1C1" 10))
>  (send table3 add-row (vector "R2C1" 11))
>  (send table3 add-row (vector "R3C1" 12))
>  (send table3 add-row (vector "R4C1" 13)))
> ```
> 
> 
> menu-item.rkt
> ```
> #lang racket
> 
> (require racket/gui/base
>         "menu.rkt"
>         "table.rkt")
> 
> (provide info-menu-item)
> 
> (define info-menu-item
>  (new menu-item%
>       [label "info"]
>       [parent row-edit-menu]
>       [callback (λ (menu-item event)
>                   (message-box "Info"
>                                (~a "You have selected " (length (send
> table3 get-selected-row-indexes)) " rows")
>                                #f))]))
> ```
> 
> 
> main.rkt
> ```
> #lang racket
> 
> (require "menu.rkt"
>         "table.rkt")
> 
> (send frame3 show #t)
> (add-rows)
> ```
> 
> Hope that helps.
> 
> - Jon
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CAKfDxxwofLFVTkcGii%2BtLGKYCBFVNY2Tw9m8ZNjR--Hh_FRtEw%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/58CCDAB6-F650-4582-9038-5BA3C78728E8%40biomantica.com.

Reply via email to