I am new to elisp
and am trying to write a simple program using an if
statement.
The point is to read in a year of school and return either 1
, 2
, 3
, 4
, or 0
for the strings "freshman"
, "sophomore"
, "junior"
, "senior"
respectively (defaulting to 0
when no match is made. My code is as follows:
(defun yearCode(name)
(if ( = name "freshman") 1
(if ( = name "sophomore") 2
(if ( = name "junior") 3
(if ( = name "senior") 4
(0))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; main function ;;;
;;; input: year ;;;
;;; output: code corresponding to year ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun main (year)
(interactive "sEnter your academic year: ") ; read year
(message "%d" (yearCode year))) ; display its code
;;; Tests...
(main "junior")
(yearCode "junior")
I honestly know nothing about elisp so I am having trouble even having the first part compile. Can anyone help me construct an if
statement correctly?
EDIT: I was testing in the wrong buffer -_- code worked using if statements.