[racket-users] Calling into a Chez Scheme library -- imported symbol rewritten in vm-eval?
I have a Chez Scheme library "foo.ss": (library (foo) (export bar) (import (rnrs)) (define (bar) "hello")) >From Chez Scheme: $ chezscheme Chez Scheme Version 9.5.4 Copyright 1984-2020 Cisco Systems, Inc. > (eval '((lambda () (import (foo)) (bar "hello" A Racket program "call.rkt" which attempts to use the library: #lang racket (require ffi/unsafe/vm) (vm-eval '((lambda () (import (foo)) (bar $ racket call.rkt variable bar554 is not bound context...: body of "/home/andrew/prj/audit/compile/call.rkt" What would be the right way to do this? Thank you, Andrew -- This group is deprecated and retained as an archive. Racket discussions have moved to the Racket Discourse at https://racket.discourse.group/ . --- 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. --- 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/40a8ebe9-f48f-47ed-9e2e-266aa02fa844n%40googlegroups.com.
Re: [racket-users] Is there a way to eval a custom language from inside a module... without instantiating modules multiple times?
> > 2. Just use the same namespace as eval-example.rkt > I had tried this, but it evals not just the example language but Racket+example (i.e. Racket forms also eval, and the example language has to be compatible with Racket). 1. Keep the new namespace, but use namespace-attach-module to attach > runtime.rkt from eval-example.rkt to example-namespace before > (namespace-require example). > That worked! I'm now able to define a struct in my runtime library, and it ends up being the same struct type in both modules. Thank you! You've mentioned that you want to "define a custom language" and evaluate > it. But so far I don't see any sign that you're using Racket's dedicated > facilities for doing this (especially `#%module-begin` and `module`). If > this is a deliberate choice, carry on. If not, consider investigating them, > because they streamline the very chores you're finding painful. Yes, I understand :-) -- 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] Is there a way to eval a custom language from inside a module... without instantiating modules multiple times?
I'd like to be able to eval a custom language from inside a module... without instantiating modules multiple times. With the help of Matthew Butterick, I've gotten this far: ; runtime.rkt #lang racket (printf "This is runtime.rkt~n") ; example.rkt #lang racket (require "runtime.rkt") (provide foo) (printf "This is example.rkt~n") (define-syntax foo (syntax-rules () ((foo) (printf "foo!~n" ; eval-example.rkt #lang racket (require racket/runtime-path) (require "runtime.rkt") (provide eval-example) (define-runtime-path example "example.rkt") (define example-namespace (make-base-empty-namespace)) (parameterize ((current-namespace example-namespace)) (namespace-require example)) (define (eval-example code) (parameterize ((current-namespace example-namespace)) (eval code))) however this instantiates runtime.rkt twice: $ racket eval-example.rkt This is runtime.rkt This is runtime.rkt This is example.rkt which turns out to be bad (for example, if I define a struct in the runtime, I end up having a different struct types). I want there to be a single copy of the runtime.rkt module (much like if I had said (require "runtime.rkt") from two different modules). What I want to do is rather simple (I hope): define a custom language in a module such as example.rkt, and then be able to eval that language. Is there a way to do this? -- 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.
Re: [racket-users] How to eval a custom language from inside a module?
> > (define-runtime-path example "example.rkt") That works! Thanks! -- 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 to eval a custom language from inside a module?
Suppose I've defined a simple language: ; example.rkt #lang racket (provide foo) (define-syntax foo (syntax-rules () ((foo) (printf "foo!~n" Now I want to create an eval-example function which will evaluate forms in my language: > (eval-example '(foo)) foo! If I'm working interactively, this is easy enough: (define example-namespace (make-base-empty-namespace)) (parameterize ((current-namespace example-namespace)) (namespace-require "example.rkt")) (define (eval-example code) (parameterize ((current-namespace example-namespace)) (eval code))) How about providing eval-example from a module? ; eval-example.rkt #lang racket (provide eval-example) (define example-namespace (make-base-empty-namespace)) (parameterize ((current-namespace example-namespace)) (namespace-require "example.rkt")) (define (eval-example code) (parameterize ((current-namespace example-namespace)) (eval code))) The problem here is that namespace-require is a procedure and so resolves "example.rkt" at run time, not at compile time like require would do. Thus "example.rkt" is resolved relative to the current working directory of the running program, not relative to the directory containing eval-example.rkt as would happen using a require. How to do this? Thanks! Andrew -- 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] What algorithm does Racket use to test cyclical data structures for equality?
The Racket documentation for equal? says equality is recursively defined; if both v1 and v2 contain reference > cycles, they are equal when the infinite unfoldings of the values would be > equal. I didn't quite believe my ears! :-) So I tried it with two pairs (a b...) and four pairs (a b a b...) (let ((x (let ((ph (make-placeholder #f))) (let ((x0 (cons 'a (cons 'b ph (placeholder-set! ph x0) (make-reader-graph x0 (y (let ((ph (make-placeholder #f))) (let ((y0 (cons 'a (cons 'b (cons 'a (cons 'b ph)) (placeholder-set! ph y0) (make-reader-graph y0) (write x) (newline) (write y) (newline) (equal? x y)) => #0=(a b . #0#) #0=(a b a b . #0#) #t Wow! How does Racket do that? -- 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.