Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elisp #574

Merged
merged 7 commits into from
Oct 18, 2024
Merged

Elisp #574

merged 7 commits into from
Oct 18, 2024

Conversation

MGadhvi
Copy link
Contributor

@MGadhvi MGadhvi commented Oct 7, 2024

READ ME BEFORE SUBMITTING A PR

Please do not submit a PR with your solution to the Gilded Rose Kata. This repo is intended to be used as a starting point for the kata.

  • I acknowledge that this PR is not a solution to the Gilded Rose Kata, but an improvement to the template.
  • I acknowledge that I have read CONTRIBUTING.md

Please provide your PR description below this line

Amended elisp code. Please see latest commit for more details

- Initial test modified to be similar to Clojure version
- update-quality modified to read from make-item directly. Helper methods removed
@codecop codecop mentioned this pull request Oct 8, 2024
2 tasks
@codecop
Copy link
Collaborator

codecop commented Oct 8, 2024

First review was in #572 . Work in progress

Copy link
Collaborator

@codecop codecop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See review comments

(list :name name :sell-in sell-in :quality quality))

(defun update-quality (item)
(let* ((quality (plist-get item :quality))
Copy link
Collaborator

@codecop codecop Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 3 lets are already a simplification/improvement of the original code. Is it possible to access the value from the struct each time? replace quality with (plist-get item :quality) everywhere?

"Create an item with NAME, SELL-IN, and QUALITY."
(list :name name :sell-in sell-in :quality quality))

(defun update-quality (item)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update quality takes a list of items at least and iterates them.

(let* ((quality (plist-get item :quality))
(sell-in (plist-get item :sell-in))
(name (plist-get item :name)))
(cond
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a solution, not the original problem. The code is already a nice switch statement. The original has deeply nested IFs. All languages should be as similar as possible to avoid confusion for participants. Please see https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/clojure/src/gilded/core.clj

- Test can be run interactively using the command ~ert~ or with ~(ert-run-tests-interactively t)~

* Todo
- Add TestText fixture
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes a TextTestFixture main method would be nice but is not strictly necessary.

- removed the cond statement and replaced with nested ifs
- removed the let statement. Data is now accesses directly
- update-quality now takes a list of items
@MGadhvi
Copy link
Contributor Author

MGadhvi commented Oct 8, 2024

Thank you. Code has been amended. Please see latest commit

@codecop
Copy link
Collaborator

codecop commented Oct 9, 2024

Thank you we are moving forward. There is still one thing. Your Gilded Rose update-quality code. Let me try to elaborate. The original code, e.g. https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/clojure/src/gilded/core.clj is bad on purpose. We need a port that looks very similar. Your code is something like that

if AgedBrie ...
else if Backstage Pass ...
else if Sulfuras ...
else ...

Also you use min/max. The original code is different:

if not AgedBrie and not BackstagePass ...
if not Sulfuras ...
if not AgedBrie and not BackstagePass ...

And inside it has duplication for the checks >= 0 and <= 50. Further the code needs to check for the exact strings "Backstage passes to a TAFKAL80ETC concert" and "Sulfuras, Hand of Ragnaros"

@MGadhvi
Copy link
Contributor Author

MGadhvi commented Oct 10, 2024

Thank you. I appreciate the support and guidance

- logic of if statments changed to if not
- removed min/max
- Strings for Sulfuras and Backstage pass made to exactly match specification
- Code structure is based more on the clojure version
@MGadhvi
Copy link
Contributor Author

MGadhvi commented Oct 11, 2024

Changes have been made. This has really pushed me to learn elisp better. Please let me know if anything else is needed

Copy link
Collaborator

@codecop codecop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks much better. I have two questions to elisp?


(defun update-quality (items)
(dolist (item items)
(if (and (not (string= (plist-get (car item) :name) "Aged Brie"))
Copy link
Collaborator

@codecop codecop Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not now elisp. Is (car item) necessary when you already do (dolist (item items)) so item is an item which we access with plist-get, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I thought car was needed to get the name as the first element of an item. I'll remove it and run my tests against the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecop you were right. The car is not needed


(when (> (plist-get (car item) :quality) 0)
(when (not (string= (plist-get (car item) :name) "Sulfuras, Hand of Ragnaros"))
(setf (plist-get (car item) :quality) (1- (plist-get (car item) :quality)))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is (1- .) a function which decrements by one? Has to be

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is:

1- is a built-in function in ‘C source code’.

(1- NUMBER)

Return NUMBER minus one.  NUMBER may be a number or a marker.
Markers are converted to integers.

  Other relevant functions are documented in the number group.
  This function does not change global state, including the match
    data.
  This function has a ‘byte-compile’ property ‘byte-compile-one-arg’.
    See the manual for details.

Removed unnecessary car from update-quality
@codecop codecop merged commit 142a489 into emilybache:main Oct 18, 2024
@codecop
Copy link
Collaborator

codecop commented Oct 18, 2024

Thank you and well done seeing it done.

@MGadhvi
Copy link
Contributor Author

MGadhvi commented Oct 18, 2024

Thank you and well done seeing it done.

Thank you for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants