Note that there are some explanatory texts on larger screens.

plurals
  1. PORacket module import basics
    primarykey
    data
    text
    <p>I'm trying to <code>require</code> one file in another while working with Racket. I have two files in the same folder. They are <code>world.rkt</code> and <code>ant.rkt</code>.</p> <p><code>world.rkt</code>:</p> <pre><code>(module world racket (provide gen-grid gen-cell) (define (gen-cell item fill) (cons item fill)) (define (gen-grid x y fill) (begin (define (gen-row x fill) (cond ((&gt; x 0) (cons (gen-cell (quote none) fill) (gen-row (- x 1) fill))) ((&lt;= x 0) (quote ()) ))) (cond ((&gt; y 0) (cons (gen-row x fill) (gen-grid x (- y 1) fill))) ((&lt;= y 0) (quote ()) ))))) </code></pre> <p><code>ant.rkt</code>:</p> <pre><code>(module ant racket (require "world.rkt") (define (insert-ant grid x y) (cond ((&gt; y 0) (insert-ant (cdr grid) x (- y 1))) ((&lt; y 0) 'Error) ((= y 0) (begin (define y-line (car grid)) (define (get-x line x) (cond ((&gt; x 0) (get-x (cdr line) (- x 1))) ((&lt; x 0) 'Error) (= x 0) (gen-cell 'ant (cdr (car line))) )) (get-x y-line x)))))) </code></pre> <p>Now, I can type <code>(require "ant.rkt")</code> in the REPL, and then when I type <code>(gen-cell 'none 'white)</code> I get the error:</p> <pre><code>reference to undefined identifier: gen-cell </code></pre> <p>I've looked up documentation on imports and exports, but I can't get it to import correctly. I feel like it's something really simple that I just don't understand about the syntax.</p> <p>How should I change my code so that I can use <code>gen-grid</code> and <code>gen-cell</code> in <code>ant.rkt</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload