Re: [racket-users] How do I launch a REPL in the context of a file?

2018-11-30 Thread Alexis King
> On Nov 30, 2018, at 08:23, Sam Tobin-Hochstadt  wrote:
> 
> I'm not sure why `-e` doesn't evaluate in the same namespace as the
> REPL, but if you put `(enter! "my-file.rkt")` in `enter.rktl` then:

I’m curious about this, too. At first I thought it was just a misfeature, not 
necessarily a bug, but now I’m not so sure. The namespaces are not actually 
separate, as the following interaction demonstrates:

$ racket -ie '(define x 3)'
Welcome to Racket v7.1.0.1.
> x
3

So then what gives? After further experimentation, my running theory is that 
any mutation of `current-namespace` inside of -e is reverted when the REPL 
starts up. You can see this by skipping `enter!` completely and just modifying 
`current-namespace` directly:

$ racket -ie '(define ns (make-base-namespace)) (current-namespace ns)'
Welcome to Racket v7.1.0.1.
> (eq? ns (current-namespace))
#f

I don’t know if this is intentional behavior or just a bug.

Alexis

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[racket-users] How do I launch a REPL in the context of a file?

2018-11-29 Thread Habib Alamin
Hi,

I'm trying to set up a keybinding in my editor to enter the namespace of my 
current file in a REPL, similar to how Dr Racket's Run button works.

I can do a racket -e '(println "Hello!") -i and it loads the REPL after 
printing Hello. A racket -e '(define a "a") -i also works, in that I'm able 
to access a in the REPL. However, I can't do racket -e '(enter! 
"hello.rkt")' -i. The REPL starts, but I can't access anything defined in 
the file.

After asking in the IRC channel, I was asked to try

racket -e '(let ([racketrc-path (expand-user-path "~/.racketrc")]) (and 
(file-exists? racketrc-path) (load racketrc-path)) (void)) (enter! 
"current-file.rkt") (read-eval-print-loop)

which didn't work either. Neither did

racket -e '(enter! "file.rkt") (read-eval-print-loop)'

I can do a racket -if file.rkt if I get rid of the #lang racket line, but I 
hear using -f isn't good practice, and besides, I want to write valid 
Racket files; removing the #lang line breaks normal Racket operation; I 
can't just do a racket file.rkt.

I'd really appreciate any help in figuring out why this is happening and a 
simple fix.

Cheers,
Habib

-- 
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.
For more options, visit https://groups.google.com/d/optout.