The Go lasagna master exercise (exercism download --track=go --exercise=lasagna-master) requires mutating a slice which seems to not be available in Go 1.18. I changed the go.mod file to go 1.23
(installed locally) and the func works fine. After I submit, the website also passes the test so I think the server hosting the tests is likely on a Go version that supports slice mutation.
-
Is that intended i.e. should the learner know that they need a newer version? Part of me thinks not since the last commit on the go.mod files says upgrade to Go 1.20 but the file still has go 1.18
. Screenshot below.
-
Is there a specific version we should be on? 1.20 (according to last commit on the file) is over a year old. It was released in 2023-02-01.
1 Like
I did a cheeky test by printing out a print statement and currently the version running in the back ground is go1.22.5
, which is pretty up to date consider 1.23 only came out recently (later aug).
So maybe the only thing need to change is some wording to let learners know.
1 Like
When I did that exercise, I don’t recall being required to mutate a slice. I seem to recall the test suite specifically set up to avoid mutating the input. The go.mod
version is the minimal version of Go needed for a particular exercise (1.18 being likely a default), but the test runner can run a more recent version of Go as seen by glaxxie’s comment.
1 Like
@glaxxie nice find! I have 1.23.0 locally so that seems close enough. Potentially a note in the HELP.md. Though this seems to me like the go.mod
version should just be updated (minimally) to the version supporting mutating slice arguments within a function.
@BNAndras It’s possible that the assignments have changed? I didn’t check the history on the readme. But the current readme for that functions assignment states:
Note: AddSecretIngredient
does not return anything - you should modify the list of your ingredients directly.
where the list mentioned above is the one of the function slice arguments.
I think having the different versions could cause issues like this. But that’s likely another conversation. As an interim and to avoid confusion from learners, I think updating the go.mod
version (minimally) to the version supporting mutating argument slices would be good.
Right, I thought we’re talking about ScaleRecipe
. For AddSecretIngredient
, the next sentence should read “The list with your friend’s ingredients should not be modified”. That can be done with the syllabus information to date. I did it two years ago with 1.18. At this point, I think we’d benefit from seeing your code for more context about this issue you’re having.
I am trying to reproduce now, but I can’t. It works with both 1.18 and 1.23 in go.mod
. I appreciate all the feedback. Seems like this is a non-issue and instead likely a mistake on my end. Though I can’t remember exactly what I did to trigger the mistake. Thanks!
That’s correct, there are two parameters. friendsList (NOT mutated like you noted) and myList (needs to be mutated since the method has no return type).
AddSecretIngredient(friendsList, myList)
My code ended up being the following which worked both on my local machine (retesting now and it seems to work fine with either 1.18 and 1.23) and on the exercism test servers (using 1.22.5)
func AddSecretIngredient(friendsList []string, myList []string) {
myList[len(myList)-1] = friendsList[len(friendsList)-1]
}