-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Script to redeploy testlib.sml to all exercises on changes. #206
Conversation
The directory name `sml-bin` makes the most sense to me for these sml "scripts". Adding them to the makefile also makes it even easier to use these than it is when using "#! /usr/bin/env -S poly --script" as a shebang line. Consequently this should be portable to any Windows system that has GNU make installed, so it is probably better than the shebang. In the code I used the path library to help make things OS portable, but I haven't ever used SML on Windows, so it is untested for that enironment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still thinking about sml-bin
vs bin
. My first impulse says that the redeploy script could perfectly live inside bin
. Can you explain in more detail why you put it somewhere else?
I suggested some changes, let me know what you think.
I did not have time to have a closer look into the redeploy script (I locally checked that it seems to work though). Maybe I have time for this soon, but if you agree on my comment on usage of open
I would wait for you to change that before having a second look.
Makefile
Outdated
@@ -15,4 +15,7 @@ test-%: | |||
@cd ./exercises/practice/$(exercise) && cat test.sml | sed 's/$(exercise).sml/.meta\/example.sml/' | poly -q | |||
@echo | |||
|
|||
redeploy-testlib: | |||
poly --script sml-bin/redeploy-testlib.sml | |||
|
|||
.PHONY: test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redeploy-testlib
should be .PHONY
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, cool. I never knew what .PHONY
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read up on it. Yes, this makes perfect sense, and it is now done.
sml-bin/redeploy-testlib.sml
Outdated
|
||
val testLib = fileBytes "lib/testlib.sml"; | ||
in | ||
app (writeFileBytes testLib o testLibName practice) (dirList practice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a very short docstring explaining what the script does might be a good idea (maybe at the top of the file). Of course the filename essentially says it but I would still prefer a short docstring. Let me know if you think this would not be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment basically restating the name of the script seems pretty redundant to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I am fine with that, I was just a little bit worried if somebody else might wonder what exactly "redeploy" might mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, well, I often take for granted that English is my first language, aber meine Meinung nach sollen wir die Problemen sprachlicher Mehrdeutigkeit der Nicht-Muttersprachlichern beachten 🙃
So, maybe it is best for there to be some more direct comments in the script 😄
sml-bin/redeploy-testlib.sml
Outdated
, file = "testlib.sml" | ||
} | ||
|
||
fun dirList dirname = let |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the formatting more consistent with the other sml-files (e.g. testlib.sml)? E.g. always indent by two spaces and for example
fun foo =
let
val a = ...
in
do_something ...
end; (* Note: there is a semicolon. *)
instead of
fun foo = let
val a = ...
in
do_something ...
end;
I have the feeling that this is better. But feel free to criticize this :) .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I'll make some changes. I need to figure out how to set sml-mode to use 2 spaces. It's indentation is worse than indentation in most emacs major modes. There really shouldn't be semicolons at the end of function definitions like this. Semicolons are for sequencing typically imperative actions. I had them in the first version of this script, but I think we should avoid them except where they are meaningful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I don't think there is an issue with let being on the opening line of the function, but I don't mind changing it for consistency.
I write a lot of haskell at work, so I am addicted to commas to the left in records and lists ;p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I am fine with omitting the semicolons. I was used to them since in the Book "ML for the working programmer" the author uses them wherever they are allowed (not just in the REPL or for imperative actions). But he actually states somewhere that they are optional there. It seems to be a matter of taste. I followed the author in my code, since I was used to something similar in javascript: In js "most of the time" the semicolons are not relevant, but not always, and therefore the general advice for js is to put them everywhere (I know javascript is probably not the most well designed language :D).
So since testlib already omits them we should omit them everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, with JS including the semicolons makes sure everything works as intended. With SML, including semicolons can change the meaning of a program 🤯
sml-bin/redeploy-testlib.sml
Outdated
@@ -0,0 +1,45 @@ | |||
open OS.Path; | |||
open OS.FileSys; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not to use open
. Makes some things easier. E.g. when I want to know what access
does I first have to find out where it comes from (OS.Path
or OS.FileSys
, probably not difficult to guess but still easier if it is explicit). What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this was a "script", especially originally, I figured using open should be fine. I am not against using qualified names though. I will probably make more convenient names aliasing the structures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched everything to qualified names now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aliases are a good compromise :) .
@guygastineau this PR is related to issue #110. Not sure if you are aware of it. |
I hadn't seen #110. Thank you for referencing it for me. |
I had set it to 775 when it had a shebang and lived in `bin`. Trying to execute it will fail, so it shouldn't be executable.
Concerning not using |
I shouldn't have combined to actions but I did. I removed all unnecessary semicolons while refactoring to use qualified names. Sorry.
I'll set my editor for using 2 spaces in |
I also found and removed two more unnecessary semicolons.
@guygastineau sounds reasonable to me. But I wonder if In any case, it is interesting that "this" problem arises from the desire to support Unix and Windows. I am not very happy that this is the reason for the additional folder, but I see your point. So in the end I have some doubts but I would be OK with or without the additional folder. I have a slight preference to still put the script into 'bin' since although I understand your reasoning I think it still has a drawback. Others not knowing your reasoning (like me before reading your justification) might now struggle with the question where to put the next script. I must admit that I have no clue what others might expect over "bin" but at least I have seen non-executables there often. However this might be just the case since I often work with engineers and I for myself did not work in IT (until 4 years ago) and my educational background is far away from IT and Computer Science. But I have no strong opinion on that I just shared my thoughts in case anybody is interested. So I decide to stay neutral on this topic from now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guygastineau I think the README should refer to the policy mentioned in #110. When I first visited the repo it was not clear to me if every exercise should have its unique copy of testlib (with possible custom changes) or not. So it might be worth noting it more clearly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I had some time for the redeploy script. I like it. I am certainly no SML Guru but I tried to give some feedback which hopefully improves the script a tiny bit.
sml-bin/redeploy-testlib.sml
Outdated
val concept = relUnixPathToAbs "exercise/concept" | ||
val practice = relUnixPathToAbs"exercises/practice" | ||
val testLib = fileBytes "lib/testlib.sml" | ||
in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind writing List.app
instead of app
? I am usually explicit with these things (because I hate puzzling out what this is if I come back after some time of absence from some particular topic like SML). But it is a question, so feel free to stay with app
.
sml-bin/redeploy-testlib.sml
Outdated
val _ = | ||
let | ||
val concept = relUnixPathToAbs "exercise/concept" | ||
val practice = relUnixPathToAbs"exercises/practice" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space in relUnixPathToAbs"exercises/practice"
.
sml-bin/redeploy-testlib.sml
Outdated
|
||
val _ = | ||
let | ||
val concept = relUnixPathToAbs "exercise/concept" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
concept
is unused, so I would delete it.
sml-bin/redeploy-testlib.sml
Outdated
BinIO.closeOut out | ||
end | ||
|
||
fun relUnixPathToAbs x= Path.concat ((File.getDir ()), Path.fromUnixPath x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space in fun relUnixPathToAbs x=
.
sml-bin/redeploy-testlib.sml
Outdated
|
||
fun fileBytes path = | ||
let | ||
val in' = BinIO.openIn path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it some well-established convention to call this in'
? Looks a little bit awkward to me, especially since my IDE (vscode) and even github recognize the first two characters as a keyword. Would you mind calling it differently?
Actually I have checked that my emacs with SML mode does not have this issue, but even there I would prefer not to call it in'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered changing it in case it is confusing, but using '
as a prime
like identifier modification is pretty common in the ML family. For the record, I think the fact of general tooling being incapable of recognizing/capturing the expressiveness of a language is a poor reason to limit one's expressiveness when using the language. If I rename it I am likely to name it ins
which was a close second in my consideration. I suppose instream
isn't too long though. I don't know why I felt so averse to a longer name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that bad tooling is not the best reason for a change, but this was just for information. I have nothing against prime
in general but here it seems to be there only because using in
is not legal and I feel this is no good reason either. Most of the time when I encountered a "primed" variable, then there also was a related variable without a prime.
My question about conventions was more specifically about using the exact string in'
as a whole (not just something with a prime at the end).
So if you already considered it to be confusing why not change it to ins
(wouldn't be my choice, but I would be fine with it)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. Prime here is not really really semantically consistent, but rather it is a syntactic hack to get around not having my ideal
identifier. Sorry, I meant to make my last comment sound more positive about changing the name of the declaration. Oat likely I will call it instream
or inStream
. I am at work right now, so I won't get to it until later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The longer name of instream
would be preferable to any of the shorter names. You could still use the '
to indicate the additional information stated @guygastineau .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @kotp. Yes, you are right about instream
. I have pushed it now. '
didn't have any meaning in my usage which is why it was wrong. I was using a more or less semantic naming convention as a hack to get around the inconvenience of a keyword.
sml-bin/redeploy-testlib.sml
Outdated
fun testLibName base slug = | ||
Path.joinDirFile | ||
{ | ||
dir = (Path.concat (base,slug)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space in dir = (Path.concat (base,slug)),
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What space? I don't have a space between x
and []
in line 6, File.access (x,[])
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for consistency with testlib one could write f(x, y)
instead of f(x,y)
everywhere. But think it is not important. Consistency can also be a pain :D.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after comma,after all,is helpful in reading,so they say. I do not know why,in any instance,one would not use a space,every time,after a comma.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got used to it, because a lot of old SML doesn't use spaces in tuples. Of course, a lot of old SML tries to immitate c-style function calls by excluding a space between uncurried function names and their product argument; this convention really annoys me, so I don't need to stick with the other convention for a partial tradition either. I will change it if you all think it is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the difference of my eyes seeing the comma, and not seeing it. So white space in code, when not syntactically limited to white space breaking things when there can definitely benefit from having it.
@guygastineau I am done with my review. When my suggestions are addressed or at least discussed away^^ I will certainly approve this PR. I hope this saves some time for the real maintainers when they do their review. |
I wrote a brief note about keeping testlib.sml in sync for all exercises in the track, and I mentioned 'make redeploy-testlib' as the provided tool for handling this requirement. I did not elaborate on a policy, because we still don't really have one. Further work related to exercism#110 should result in a clear policy, and at that point the README.md might need some more updating.
Geeze, I accidentally started a review, so some of my comments over a few days got bunched up. I just hit submit review to get them to go out. Some of them might have been out of date. Anyway, I think we probably have this ready to go. |
@guygastineau I am fine with everything. I approve :) . Maybe somebody else can give a third opinion on the discussion on |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to allow the PR to be merged.
Note that I do also support bin
over sml-bin
, but I don't massively care.
I can change it to I am not sure that For track tools like I do sometimes have directories called What we are really talking about with What am I trying to say?
So, if everyone here thinks we should mix the files in I hope I have made my rationale clear. I look forward to your reactions. |
Co-authored-by: Victor Goff <[email protected]>
I am against mixing non-executable files in The Linux directory structure shows how general directory structure is for an arguably larger project. For example; using |
You've made a good argument for separating them. |
Hmm, I read over the LDS documentation again. I never see files in Still, I don't think that |
By the way, I don't know if you all care enough to debate potential names. Please do if you want to. I see no reason to rush through these contributions, but I would rather not let it languish needlessly either. I will give a couple days for you all to chime in, but provided silence I will go ahead and merge sometime on Tuesday with the current name. |
The |
Yeah, |
Initially, I thought it must be clear enough from the title/name of the script itself, but on further reflection, a documenting comment might help a non-native english speaker avoid the difficulties of ambiguity.
Thank you all for the thorough and thoughtful reviews. We are now using @rainij despite an admitted dearth of experience with SML you gave an excellent review. It is a testament to your abilities as an engineer, and I expect the advanced degree in mathematics plays some role in your meticulous contributions to the conversation. Thank you very much. |
It looks like we do need an SML maintainer or anyone else with write access here to merge the PR. |
This was merged a day earlier than I thought was indicated. But looks good @guygastineau . Just had time to do a last check based on the timeline information I had. |
Sorry @kotp , I meant I would leave it for a few days to wait for discussion about renaming |
I think this comment of mine is where our miscommunication started, @kotp although rereading your comment stating that |
It was just that you said "for a couple of days" and so I came back to do a final "after changes" review. It's all good. Would rather have it in, it is an improvement for sure. Just some things I know I have time to come back to, even if I find out that I knew no such thing. ;) |
Okay, so I decided it is better to factor this redeploy script out of #205 .
I also went ahead and refactored to use the
Makefile
for ease of use and hopefully for better portability across operating systems. GH inscluded my commit message below.The directory name
sml-bin
makes the most sense to me for these sml"scripts". Adding them to the makefile also makes it even easier to
use these than it is when using "#! /usr/bin/env -S poly --script" as
a shebang line. Consequently this should be portable to any Windows
system that has GNU make installed, so it is probably better than the
shebang. In the code I used the path library to help make things OS
portable, but I haven't ever used SML on Windows, so it is untested
for that enironment.