scheme - How to (re)load files in Racket (X)REPL? -
suppose have file like
#lang racket/base (define (hello) (print "hello")) ... more definitions ...
and load definitions in file interactively work them in (x)repl. how do that?
if start (x)repl , (load "/tmp/hello.rkt")
, hello
function not made available me:
-> (hello) ; hello: undefined;
if (require (file "/tmp/hello.rkt"))
, result same. can (enter! (file "/tmp/hello.rkt"))
, (hello)
works, seems rather ... unintuitive , beginner-unfriendly.
is indeed way should done , should read on modules , namespaces browse , experiment code or there simpler way i'm overlooking?
n.b. found how load file racket via command line?, explains how run file. not how load in repl, can test/debug specific definitions, edit, reload, etc.
since files start #lang
modules, nil if load
them. (actually something, not help you.) best avoid using load
completely, pretend it's not there.
now, using require
right thing, instantiate module , give access names provides. in case, didn't provide means can't utilize hello
. that, can add together (provide hello)
file. that's not want, since seems want debug code. (ie, won't want provide
module work on things.)
so right thing utilize enter!
, or if you're using xrepl, there's more convenient ,en
command. instantiate module , create repl utilize namespace of module, can access everything. (and don't need load
or require
it.) can utilize multiple times reload code if alter it. note there issues it, might need install nightly build work it.
finally, know that, working drracket create things much easier in general.
load scheme racket read-eval-print-loop
No comments:
Post a Comment