exercism / julia

Exercism exercises in Julia.
https://exercism.org/tracks/julia
MIT License
66 stars 69 forks source link

Added protein translation practice exercise #693

Open golanor opened 7 months ago

golanor commented 7 months ago

Here is a suggestion for the protein-translation exercise in Julia using string macros. Let me know what you think.

cmcaine commented 7 months ago

Hi, thanks for your interest. Please rebase and make the tests pass, then ping reviewers again.

golanor commented 7 months ago

Hi @cmcaine , There seems to be an issue with some versions of Julia when running this test. Do you suggest I change the test so that it would always pass, or should we try fixing the runner so there won't be a difference? It works for 1, and for the nightly (and 1.10 on my machine)

cmcaine commented 7 months ago

Julia 1.6 is the current LTS release, so I think we should still support it. The bug is probably because the macros are being expanded at different times on different releases, which might have been done deliberately or not.

We could fix that with eval (@test_throws TranslationError eval(:(@macroexpand rna"foo"))), but I think we should require the user to write a function that the string macro is then expected to call. I think this is usually the better option, and is definitely the better option in this case where it is very plausible that a user would want to find the translations of strings that are not known at compile time.

How does that sound to you?

golanor commented 7 months ago

I made the changes, but then the string macro is a bit redundant, isn't it?

cmcaine commented 7 months ago

The macro serves the same purpose as other string macros:

  1. Mostly a convenient/pretty shorthand
  2. Also a way to ensure a computation can happen at compile-time (good for e.g. Regex so that the moderately expensive PCRE regex compilation step can be done at the same time as the Julia compilation step).

What do you want the student to learn from the exercise?

I suggest changing all instances of rna"..." in the tests to rna_translator("...") and adding a couple of tests of the macro at the end.

Reason: the function interface is easier to test and understand for the student.

Alternatively, we could remove the macro version entirely.

golanor commented 7 months ago

I wanted to teach both macro writing and creating an exception. I'll settle for only learning how to create a new exception.

cmcaine commented 7 months ago

Feel free to put the string macro back in as a bonus question, if you like. The rot13 practice exercise has an example of this.

golanor commented 7 months ago

Renamed and added the macro as a bonus question

golanor commented 6 months ago

Can we merge this?

cmcaine commented 6 months ago

Sorry, I missed the updates. I'll try to take a look this week. Please ping me again if I don't.

golanor commented 6 months ago

ping @cmcaine

golanor commented 5 months ago

@cmcaine Can we merge?

golanor commented 5 months ago

I comitted the suggested changes

cmcaine commented 5 months ago

Cool. The example.jl will need to be changed to throw Argument error.