3 ms·
(defun grade (student) (cond ((excellent-work student) :a+) ((okay-stuff student) (if (tried-hard student) :b :b-)) (t
by lispm 12y ago
(defun grade (student)
(cond ((excellent-work student) :a+)
((okay-stuff student) (if (tried-hard student) :b :b-))
(t :c)))
- illo 12y agoErlang, just for fun: grade(#student{work=Work, tried_hard=Tried}) -> grade1(Work, Tried). grade1(excellent_work, _) -> 'a+'; grade1(okay_stuff, yes) -> b; grade1(okay_stuff, _) -> 'b-'; grade1(_, _) -> c. Edit: formatting.
- JadeNB 12y agoOr, if we're going to go with Prolog-inspired syntax, then why not Prolog? grade(Student, Grade) :- worked(Student, Work), work_grade(Work, Student, Grade). work_grade('Excellent', _, 'A+'). work_grade('Okay', Student, 'B') :- tried_hard(Student). work_grade('Okay', _, 'B-'). work_grade(_, _, 'C'). I'm a bit rusty, and I don't have a Prolog interpreter to hand to test, so I might have got some syntax wrong.
- sfk 12y agoI'm always amazed that I hardly ever program in Lisp and yet these short snippets are more readable than any other language.
- dghf 12y agoYes, I've never understood why dostuff(x) is considered so much more readable than (dostuff x)