;_MINI PROJECT-BMI CALCULATOR (princ "WELCOME TO BMI CALCULATOR")(terpri)(terpri) ;_BMI CALCULATION FORMULA (defun bmi(ht wt) (*(/ wt (* ht ht))10)) ;_INPUT DETAILS (princ "Enter your Name : ")(terpri) (princ "Enter your Age : ")(terpri) (princ "Enter your Gender(f-female m-male) : ")(terpri) (princ "Enter your Height in (m) : ")(terpri) (princ "Enter your Weight in (kg) : ")(terpri) (setq name(read)) (setq age(read)) (setq gender(read)) (setq ht(read)) (setq wt(read)) (terpri) (princ "--------------------------------------------------------------------------------------------------") ;_DISPLAY BMI SCORE (terpri)(format t "Hello ~D! " name)(terpri) (terpri)(format t "--> You have a BMI Score of ~5f~%" (bmi ht wt) )(terpri) ;_BMI CATEGORY DISPLAY (cond (( < (bmi ht wt) 18.6) (princ "--> You are underweight") (terpri) (princ " Consider gaining weight to bring your BMI to between 19 and 25.") ) (( < (bmi ht wt) 25) (princ "--> You are perfectly healthy :)") (terpri) (princ " With a BMI within a healthy range of between 19 and 25.") ) (( < (bmi ht wt) 30) (princ "--> You are overweight") (terpri) (princ " Speak to a doctor about setting yourself a new target BMI between 19 and 25.") ) (( < (bmi ht wt) 40) (princ "--> You are obese") (terpri) (princ " You need to lower your BMI to between 19 and 25 or else you may be at risks.") ) (( > (bmi ht wt) 40) (princ "--> You are severely obese") (terpri) (princ " You need to lower your BMI to between 19 and 25 or else you may be at risks.") ) ) (terpri) (terpri) ;_DISPLAY WEIGHT FOR THIS HEIGHT (cond (( = ht 4.10) (princ "For this height, a weight range of 36.4-44.9 kg is a normal BMI.") ) (( = ht 4.11) (princ "For this height, a weight range of 39.0-47.6 kg is a normal BMI.") ) (( = ht 5.0) (princ "For this height, a weight range of 40.8-49.9 kg is a normal BMI.") ) (( = ht 5.1) (princ "For this height, a weight range of 43.1-52.6 kg is a normal BMI.") ) (( = ht 5.2) (princ "For this height, a weight range of 44.9-54.9 kg is a normal BMI.") ) (( = ht 5.3) (princ "For this height, a weight range of 47.2-57.6 kg is a normal BMI.") ) (( = ht 5.4) (princ "For this height, a weight range of 49.0-59.9 kg is a normal BMI.") ) (( = ht 5.5) (princ "For this height, a weight range of 51.2-62.6 kg is a normal BMI.") ) (( = ht 5.6) (princ "For this height, a weight range of 53.0-64.8 kg is a normal BMI.") ) (( = ht 5.7) (princ "For this height, a weight range of 55.3-64.8 kg is a normal BMI.") ) (( = ht 5.8) (princ "For this height, a weight range of 57.1-69.8 kg is a normal BMI.") ) (( = ht 5.9) (princ "For this height, a weight range of 59.4-72.6 kg is a normal BMI.") ) (( = ht 5.10) (princ "For this height, a weight range of 61.2-74.8 kg is a normal BMI.") ) ) (terpri) (terpri) (princ "--------------------------------------------------------------------------------------------------")
Write, Run & Share Common Lisp code online using OneCompiler's Common Lisp online compiler for free. It's one of the robust, feature-rich online compilers for Common Lisp language, running the latest Common Lisp version 5.3. Getting started with the OneCompiler's Common Lisp editor is easy and fast. The editor shows sample boilerplate code when you choose language as Common Lisp and start coding.
OneCompiler's Common Lisp online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Common Lisp program which takes name as input and prints hello message with your name.
(setq name (read))
(princ "Hello ")
(write name)
Common Lisp is a generic language suitable for a wide range of industry applications. It is often referred as Programmable programming language because of it's high extensibility, machine independence, extensive control structures, dynamic updation of programs etc.
Common LISP was invented by John McCarthy in 1958 and was first implemenyted by Steve Russell on an IBM 704 computer.
defvar
keyword and these variables will be in effect until a new value is assigned.(defvar x 10)
(write x)
let
and prog
are used to declare local variables.(let ((var1 value1) (var2 value2).. (varn valuen))<expressions>)
setq
(setq a 10)
This is the simplest looping mechanism in LISP. This allows the execute the set of statements repeatedly until a return statement is encountered.
(loop (s-expressions))
For loop is used to iterate a set of statements based on a condition.
(loop for loop-variable in <a list>
do (action)
)
Do is also used to iterate a set of statements and then check the condition
(do ((var1 val1 updated-val1)
(var2 val2 updated-val2)
(var3 val3 updated-val3)
...)
(test return-value)
(s-expressions)
)
Dotimes is used to iterate for fixed number of iterations.
(dotimes (n val)
statements