Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I declare a variable that cannot be changed?

Suppose I want to create a variable that cannot be changed after being initialized, for
example, here is the Java equivalent:

final int emp_id

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use the def keyword to bind a value to a symbol, and that value cannot change
afterward:

(def emp_id 1)
(set emp_id 2) # Output: compile error: cannot set constant

If you know your value will change later on, for example, and employee last name after marriage, then use the var keyword:

(var emp_last_name "Smith")
(set emp_last_name "Summer")

emp_last_name # Output: "Summer"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading