Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

random function in DrRacket

Tags:

scheme

racket

I am currently using DrRacket on Mac OS X and choose the language "R5RS", but when I enter

(random 100)

I get the error message:

reference to undefined identifier: random

What's the problem here? Is it caused by a missing package?

like image 387
JasonLi Avatar asked Feb 29 '12 13:02

JasonLi


2 Answers

As dyoo points out, the function random is not defined in R5RS. If you want to use "foreign" functions in the R5RS language in DrRacket, you can use #%require to import them.

In this case search for random in the Racket documentation. Notice that random is part of the module racket/base. Now write:

(#%require (only racket/base random))
(random 10)

Using only ensure that you only import the function random and any other non-R5RS construct present in racket/base.

like image 65
soegaard Avatar answered Sep 20 '22 10:09

soegaard


Is ‘random‘ a function provided by R5RS? I look for it in the index of the spec, but I don't see it there. R5RS is a minimal language mode, and when Racket is in R5RS mode, it really restricts itself.

Racket does have a native random function. If you are using ‘#lang racket‘, it's automatically available. Is there a reason you're using the R5RS language mode?

like image 38
dyoo Avatar answered Sep 19 '22 10:09

dyoo