julia icon indicating copy to clipboard operation
julia copied to clipboard

Added protein translation practice exercise

Open golanor opened this issue 2 years ago • 14 comments

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

golanor avatar Jan 25 '24 19:01 golanor

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

cmcaine avatar Jan 28 '24 21:01 cmcaine

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)

golanor avatar Jan 30 '24 10:01 golanor

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?

cmcaine avatar Jan 30 '24 12:01 cmcaine

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

golanor avatar Jan 30 '24 12:01 golanor

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.

cmcaine avatar Jan 30 '24 13:01 cmcaine

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

golanor avatar Feb 02 '24 06:02 golanor

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.

cmcaine avatar Feb 06 '24 12:02 cmcaine

Renamed and added the macro as a bonus question

golanor avatar Feb 07 '24 08:02 golanor

Can we merge this?

golanor avatar Feb 24 '24 17:02 golanor

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

cmcaine avatar Feb 25 '24 00:02 cmcaine

ping @cmcaine

golanor avatar Mar 07 '24 13:03 golanor

@cmcaine Can we merge?

golanor avatar Apr 03 '24 16:04 golanor

I comitted the suggested changes

golanor avatar Apr 19 '24 10:04 golanor

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

cmcaine avatar Apr 19 '24 11:04 cmcaine

This exercise was added in #746.

colinleach avatar Apr 18 '25 14:04 colinleach