Racket modules in R6RS?

147 views
Skip to first unread message

John Carmack

unread,
Jun 11, 2015, 4:22:19 PM6/11/15
to Racket Users

How do you include a racket module in an R6RS program?

 

I have remote.rkt in the same directory as test.scm.

 

With R5RS I could do (#%require "remote.rkt"), but that doesn’t work, and I tried various things in the (import) statement without success.

 

Are there any plans for an R7RS lang in Racket?  I am trying to write code that runs in both DrRacket and Chibi scheme.

 

 

Matthew Flatt

unread,
Jun 11, 2015, 6:30:53 PM6/11/15
to John Carmack, Racket Users
At Thu, 11 Jun 2015 20:22:16 +0000, John Carmack wrote:
> How do you include a racket module in an R6RS program?
>
> I have remote.rkt in the same directory as test.scm.
>
> With R5RS I could do (#%require "remote.rkt"), but that doesn't work, and I
> tried various things in the (import) statement without success.

The `import` form in the R6RS implementation doesn't currently support
relative references to modules. It can only reference modules through
collection paths, so a module has to be "installed" to be accessible.

For example, if "remote.rkt" is placed in "my-utils" directory that
is linked as a package with (the trailing slash is important)

raco pkg install my-utils/

then

(import (my-utils remote))

accesses the module.


> Are there any plans for an R7RS lang in Racket?

I'm not aware of any plans.

Note that the R6RS implementation isn't built-in to Racket; it's just a
pile of libraries. I expect that R7RS could be implemented similarly in
its own package, but I am not aware of anyone working on that package,
so far.

Philip Blair

unread,
Jun 11, 2015, 6:51:57 PM6/11/15
to racket...@googlegroups.com, jo...@oculus.com, us...@racket-lang.org
I managed to get something working:

The Racket r5rs documentation states that the `#%require` form is provided from racket/base. Since typing `#%require` raises (as far as I've experienced) an "illegal character after '#' input: '%'" error, I had to fall back onto the standard `require` form:

remote.rkt:

#lang racket
(provide foo)

(define (foo x) (add1 x))


test.scm:

#!r6rs
(import (rnrs)
(only (racket base) require))
(require "remote.rkt")
(display (foo 2))


It's not an "r6rs-pure" solution, unfortunately, but, as mflatt said, there's no real way do this in pure r6rs. I don't know your use case, but this might work for you.

Matthias Felleisen

unread,
Jun 11, 2015, 8:05:20 PM6/11/15
to John Carmack, Racket Users

Let me rephrase Matthew. Racket is only related to Scheme. See http://racket-lang.org/new-name.html for an explanation of our move. Our understanding is that the Scheme community wants to move back to a world where the language is small while Racket wants to move to a world where programmers can easily create programs. -- Matthias





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

John Carmack

unread,
Jun 11, 2015, 8:48:48 PM6/11/15
to Matthias Felleisen, Racket Users

I appreciate the position, but I do think there is still value in being able to optionally carve off all the extra goodness and act like a more primitive Scheme to provide compatibility with various embedded options where full Racket isn’t practical.

 

DrRacket is a key element of my strategy here – a cross platform IDE with brace matching, syntax highlighting, and a debugger makes Scheme a reasonable choice for an extension language.  I think I can evangelize this in a way that wouldn’t be possible if users’ first experience was poking at code in Notepad.

 

If anyone wants to tell me “Racket is easy to embed in an Android app!” I would love to hear it, but I’m a little too intimidated to have a crack at it myself, versus Chibi or various other small Schemes that are just a few files of C code.

Neil Van Dyke

unread,
Jun 11, 2015, 9:34:01 PM6/11/15
to Racket Users
Has anyone tried to build Racket 6.x for the Android NDK (or whatever is
the current way to do native code)? That might be the fastest path,
rather than targeting Dalvik, Java, or JS.

Encouraging: I did find that Racket 6.x builds pretty easily as a
possibly-viably-sized OpenWrt package, which gives me some hope that
Android NDK might be low-hanging fruit as well. (Though Android apps
are more complicated than OpenWrt binaries are. Good news is that
Android devices do tend to have lots more RAM and CPU than OpenWrt ones.)

-rw-r--r-- 1 user user 5531012 May 11 17:57 racket_6.1.1-1_ar71xx.ipk
-rw-r--r-- 1 user user 5804296 May 17 06:35 racket_6.1.91.900-1_ar71xx.ipk

Neil V.

Matthias Felleisen

unread,
Jun 11, 2015, 9:34:03 PM6/11/15
to John Carmack, Racket Users

Short: What I am trying to say is that after R6RS, we moved on from Scheme. Don't expect us to support it, don't expect us to stand it its way. We are moving in an orthogonal direction. 

Long:  We appreciate "small kernel" language and we inherited this from Scheme. We do not appreciate it "keep the language small, even at the cost of not being able to support the construction of large projects easily."  Certain degrees of safety and security, certain partial abstraction layers, certain fundamental language mechanisms are essential to us. That, and the idea that batteries are included in a useful manner. 

We wish our implementation were smaller. One day we will have a small one. 

No, I can't tell you it's easy to embed Racket in an Android app but I am certain that if you call for help on this list, someone will help. Or perhaps several people. But it won't be tat small. Tony GJ, for example, had real trouble running Racket on a Linksys router a couple of years back and these things run Linux. Then again, phones are larger than routers ;-) 


-- Matthias

Matthew Flatt

unread,
Jun 11, 2015, 10:00:09 PM6/11/15
to Neil Van Dyke, Racket Users
Android via NDK is a supported platform. The "src/README" file has information on cross-compilation and specific hints for Android. I'm not in a position to double check just now, but it built the last time I tried a few months ago.

Embedding should be as easy as on any platform. I wouldn't classify it as "easy" in absolute terms, but it shouldn't be too difficult for a typical host application - maybe on par with making a portable Scheme program.

Neil Van Dyke

unread,
Jun 11, 2015, 10:12:48 PM6/11/15
to Racket Users
Matthew Flatt wrote on 06/11/2015 10:00 PM:
> Android via NDK is a supported platform.

Matthew, that's great. Thank you.

Anyone implemented `racket/gui` for Android with this, or otherwise
hooked up things so that the Racket program can drive a UI on Android?

Neil V.

Lehi Toskin

unread,
Jun 12, 2015, 3:39:17 AM6/12/15
to racket...@googlegroups.com, us...@racket-lang.org
Racket GUI programming on Android? This must be(come) a thing!
Reply all
Reply to author
Forward
0 new messages