Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you define a constant in PLT Scheme?

Tags:

scheme

racket

How do I declare that a symbol will always stand for a particular value and cannot be changed throughout the execution of the program?

like image 230
unj2 Avatar asked Dec 04 '22 15:12

unj2


1 Answers

As far as I know, this isn't possible in Scheme. And, for all intents and purposes, it's not strictly necessary. Just define the value at the toplevel like a regular variable and then don't change it. To help you remember, you can adopt a convention for naming these kinds of constants - I've seen books where toplevel variables are defined with *stars* around their name.

In other languages, there is a danger that some library will override the definition you've created. However, Scheme's lexical scoping coupled with PLT's module system ensure this will never happen.

like image 146
Kyle Cronin Avatar answered Jan 14 '23 17:01

Kyle Cronin