Langosfun
Langosfun

Reputation: 73

Math functions in Racket

I'm new in Racket programming. How can I use built in math functions? Example factorial? In first line I inserted #lang racket/base but it not imported math functions. When I use factorial function I have error: factorial: unbound identifier in: factorial

Thank you for help me.

Upvotes: 3

Views: 535

Answers (1)

Leif Andersen
Leif Andersen

Reputation: 22332

The racket/base language is fairly bare bones, and doesn't provide many math functions. The racket language is a bit bigger, although still doesn't have factorial in particular. However, the math library does have factorial. So you can always require it on top of whatever language you use. As such, you will end up with a program like:

#lang racket
(require math)

(factorial 5) ; => 120

Upvotes: 4

Related Questions