zenspider
2017-7-15 07:07:44

Dynamically running Records1 code causes the following error:

10215 % racket driver.rkt
3
3
cannot instantiate `racket/gui/base' a second time in the same process
  context...:
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/wx/common/once.rkt: [running body]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/wx/common/utils.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/wx/cocoa/utils.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/wx/cocoa/pool.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/wx/cocoa/init.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/wx/cocoa/platform.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/wx/platform.rkt: [running body]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/kernel.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/private/mred.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/mred.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/mred/main.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/gui-lib/racket/gui/base.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/redex-gui-lib/redex/private/stepper.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/redex-gui-lib/redex/gui.rkt: [traversing imports]
   /MyApplications/dev/lisp/Racket/share/pkgs/redex-gui-lib/redex/main.rkt: [traversing imports]
   /Users/ryan/Library/Racket/6.9/pkgs/racket-school-mystery-languages/private/mystery.rkt: [traversing imports]
   ...

This is just down in the terminal. No possibility of a stepper. Is there some way around this?


zenspider
2017-7-15 07:07:49

I’m SOOO close


zenspider
2017-7-15 07:13:55
(define (compare src lang1 lang2)
  (define s1 (run-with-lang (open-input-string src) lang1))
  (define s2 (run-with-lang (open-input-string src) lang2))
  (equal? s1 s2))

(time                                   ; works fine
 (for ([i (in-range 10)])
   (compare "(+ 1 2)" 'racket 'RecImpl)))

(time                                   ; blows up
 (for/list ([i (in-range 1)])
   (compare "(+ 1 2)" 'racket 'RacketSchool/Records1)))

zenspider
2017-7-15 07:14:55

@robby would you be open to making (require redex) be more lightweight? (require redex/stepper) or (require redex/gui) to pull in the rest?


zenspider
2017-7-15 07:15:07

(happy to do the work)


zenspider
2017-7-15 07:28:17

YES!


zenspider
2017-7-15 07:29:16

@florence Because of the above I had to switch to using a shared namespace:

(define-namespace-anchor this-namespace-anchor)
(define ns (namespace-anchor->namespace this-namespace-anchor))

mflatt
2017-7-15 11:45:08

@zenspider To avoid multiple instantiations of racket/gui/base, you can use make-gui-namespace instead of make-namespace. The sandbox uses racket/gui/dynamic to decide which to use (and there are various dependency and historical reasons behind why it isn’t built-in).


robby
2017-7-15 12:33:14

@zenspider the redex module is already broken up and you can require redex/reduction-semantics for just the basics. I don’t think we can change what the redex module exports anymore.


zenspider
2017-7-15 15:04:47

@mflatt that’ll probably fix my original code right up. There are only 3–4 mentions of this on google (one was @florence and all(?) were to @greg on racket-mode iirc). If make-namespace made mention of it some of this could probably be avoided.

@robby nod makes sense. The problem (I think) is that everything is requiring redex straight and my module instantiator was getting beat up. But I think that’s probably solved now.


zenspider
2017-7-15 15:06:09

even if I leave the code as-is… since the best I can do with dynamic-require is grab the output, I don’t think my namespace-anchor route can get beat up THAT badly. I can’t even see provides because of the fixed module boundary


zenspider
2017-7-15 15:16:39

Single iteration of (+ 1 2)'read+eval cpu time: 12 real time: 13 gc time: 0 'racket cpu time: 28 real time: 28 gc time: 0 'RecImpl cpu time: 42 real time: 42 gc time: 25 'Records1 cpu time: 1012 real time: 1011 gc time: 268`


zenspider
2017-7-15 15:17:11

Records1’s interpreter is actually driving entirely through redex


zerusski
2017-7-15 20:39:53

Farewell SLC. Thank you everyone for making School fun :)


zenspider
2017-7-15 22:01:56

How am I supposed to write this?

(define-syntax (function stx)
  (syntax-parse stx
    [(_ id:id)
    #'(if (identifier-binding #'id)
          (if (procedure? id)           ; blows up here for missing
              id
              (or 'ERROR (error 'function "~v is not a function" id)))
          `(function ,'id)
        )]))

(define x 42)
(define y (fn 'y (lambda (x) 42)))

(function x)                            ; 'ERROR
(function y)                            ; (function y)
(function missing)                      ; missing: unbound identifier in module

zenspider
2017-7-15 22:02:24

dispatch elsewhere for the procedure? part?


zenspider
2017-7-15 22:02:45

also was looking at syntax-let…


zenspider
2017-7-15 23:27:57

I got everything working! On iteration 392 it found an equivalent to what @sorawee found!!


sorawee
2017-7-15 23:28:43

:slightly_smiling_face:


zenspider
2017-7-15 23:50:44

Not sure I agree with the error but I’ll fix it anyway. Thank you for finding and reporting it to me! It got me moving on making this verification framework.