(define-struct student (first last major))
(define student1 (make-student "John" "Smith" 'CS))
(define student2 (make-student"Jane" "Jones" 'Math))
(define student3 (make-student "Jim" "Black" 'CS))
#;(define (same-major? s1 s2)
(symbol=? (student-major s1)
(student-major s2)))
when I type these in, I get the answer I expect.
;;(same-major? student1 student2) -> FALSE
;;(same-mejor? student1 student3) -> True
But when I want to find out if the students have the same first name, it tells me that they expect a symbol as a 1st argument, but given John.
(define (same-first? s1 s2)
(symbol=? (student-first s1)
(student-first s2)))
What am I doing wrong?
'CSand'Mathare symbols, “John”, “Jane” and “Jim” are not (they’re strings). As the error message is telling you, the arguments tosymbol=?need to be symbols.To compare strings for equality, you can use
string=?or justequal?(which works with strings, symbols and pretty much everything else).