Comments (5)
I really don't know what I was thinking when I first did this exercise. I think that the tests should point the developer to a simpler situation of a package with a few methods. The data structure should be simpler, a hash or alist.
I think we'll find that the past me implemented things too strictly the same as Ruby/Clojure and they should be amended in some cases.
from common-lisp.
Going strictly by the readme, I came up with the following minimal implementation with some native testing:
TODO: convert existing tests to support.
(in-package #:cl-user)
(defpackage #:school
(:use #:common-lisp)
(:export #:school #:add #:grade-roster #:grade #:sorted))
(in-package #:school)
(defparameter *students*
()
"Student data")
(defun add (student-name student-grade)
(push (cons student-name student-grade) *students*))
(defun grade (grade)
(mapcar #'car (remove-if-not #'= *students* :key #'cdr)))
(let ((*students* ()))
(add "Jim" 2)
(assert (equal *students* '(("Jim" . 2))))
(assert (equal (grade 2) '("Jim"))))
(defun grade-roster ()
(sort (copy-list *students*)
(lambda (student1 student2)
(or (< (cdr student1) (cdr student2))
(string< (car student1) (car student2))))))
(let ((*students* '(("Alex" . 2)
("Zoe" . 2)
("Anna" . 1)
("Peter" . 2)
("Barb" . 1)
("Charlie" . 1))))
(assert (equal (grade-roster)
'(("Anna" . 1)
("Barb" . 1)
("Charlie" . 1)
("Alex" . 2)
("Peter" . 2)
("Zoe" . 2)))))
;;; Bonus points, basic.
(let ((*students* '(("Josie" . 1)
("Joseph" . 1)
("Jose" . 1)
("Joe" . 1))))
(in-package #:cl-user)
(multiple-value-bind (#:out err)
(ignore-errors
(push '("Chris" . 2)
(find-symbol "*students*"
(find-package 'school))))
(check-type err error)))
from common-lisp.
Just scanned it quick and I think it has the right 'shape'. Do you want to take a stab at re-writing the tests?
from common-lisp.
Yeah, I may be able to make more time for it this weekend.
from common-lisp.
After taking working on it a bit more I decided to follow your implementation more closely but smooth out some things. Still using CLOS and a hash in the example, but people should be able to implement it a couple of different ways, using a make-school
constructor and using a simple property list for output.
from common-lisp.
Related Issues (20)
- Out of sync practice exercises HOT 1
- Out of sync practice exercises HOT 1
- Using `roswell` to run tests. HOT 10
- Building a training set of tags for common-lisp HOT 20
- Typo in robot-simulator test. HOT 2
- Deprecate `beer-song` in favor of `bottle-song` HOT 3
- Out of sync practice exercises
- Out of sync practice exercises
- Implement `leap`? HOT 5
- Out of sync practice exercises HOT 1
- Out of sync practice exercises
- key-comparison maze of arrays unclear test of identity or internal structure HOT 3
- Out of sync practice exercises
- Out of sync practice exercises
- Out of sync practice exercises HOT 1
- Out of sync practice exercises HOT 1
- Out of sync practice exercises
- Confusing hint in Larry's Winning Checker
- Concept reducing typo element rather than sequence HOT 2
- Out of sync practice exercises
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from common-lisp.