Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 376
Langosfun Avatar asked Sep 02 '26 10:09

Langosfun


1 Answers

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
like image 92
Leif Andersen Avatar answered Sep 05 '26 16:09

Leif Andersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!