Giter Club home page Giter Club logo

Comments (5)

verdammelt avatar verdammelt commented on September 25, 2024

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.

wobh avatar wobh commented on September 25, 2024

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.

verdammelt avatar verdammelt commented on September 25, 2024

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.

wobh avatar wobh commented on September 25, 2024

Yeah, I may be able to make more time for it this weekend.

from common-lisp.

wobh avatar wobh commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.