In: Computer Science
Either the iftcase macro in Emacs Lisp which can be used as follows :
(iftcase <exp>
((1 3 5) <exp1>)
((4) <exp2>)
(_ <exp3>))
Which will mean : first evaluate exp then evaluate exp1 if exp returns 1, 3, or 5; otherwise evaluate exp2 if exp returns 4; otherwise evaluate exp3
Emacs LISP is a programming language which is used to perform data string manipulation, It is also a scripting language developed by Emacs. It is one of the oldest language which is still in use for the artificial intelligence now'a days. It can read the entire file through Emacs buffer instead of reading file at a time.
If case in Emacs LISP:
A conditional statement "IF" can also be used in Emacs programming. This is used to solve conditional problems by applying certain conditions (conditions can be as per the requirement). The main idea behind the processing of conditional statement "IF" is like if the condition defined with in the "IF" statement is true then whatever is mentioned with in the "IF" should be evaluated otherwise not evaluated.
Syntax of conditional statement (IF):
If (condition){
// statement 1;
}else{
// statement 2;
}
Example: To check whether a number is even or odd, "IF" logic is given as:
If (x % 2 == 0){
"Even Number";
}else{
"Odd Number";
}
This is the easiest way to get the problem solution but in the case of multiple expressions it requires looping statements too. There are two looping statements are there in Emacs such as:
1. While loop: useful when set of code is repeated again and again.
(while (Expression)
// body...
(statement))
Like for Increament of counter through while loop:
(while (< count Number)
// body...
(set count(+1 count)))
2. Recursion: useful when function calling itself again and again.
The main problem while applying looping statement in the programming is:
The desired expansion for code:
Code given:
(iftcase <exp>
((1 3 5) <exp1>)
((4) <exp2>)
(_ <exp3>))
Code after expansion: This the code after expansion of the expression in IF statement.
(IF <exp>
((1) <exp1>
((3) <exp1>
((5) <exp1>)))
((4) <exp2>)
(<exp3>))