patternMinor
Factor script to change case of all filenames in a directory
Viewed 0 times
scriptcasedirectoryallfactorfilenameschange
Problem
In the absence of a full-fledged tutorial, I am teaching myself to program in the Factor language by writing a bunch of functions that I will eventually use in command-line scripts.
One common operation I like to perform is to change the case of names of files contained in a given directory to uppercase or lowercase. I wrote the following code to perform this operation in Factor:
I have tried to factor as much code as possible into a reusable vocabulary. I look forward to suggestions for improvement.
One common operation I like to perform is to change the case of names of files contained in a given directory to uppercase or lowercase. I wrote the following code to perform this operation in Factor:
USING: fry kernel io.directories sequences unicode.case ;
IN: util.directories
: move-each-directory-file>lower ( pathname -- )
[ dup >lower ] move-each-directory-file ;
: move-each-directory-file>upper ( pathname -- )
[ dup >upper ] move-each-directory-file ;
: each-directory-file ( pathname quot -- )
'[ [ @ ] each ] with-directory-files ; inline
: move-each-directory-file ( pathname quot -- )
'[ @ move-file ] each-directory-file ; inlineI have tried to factor as much code as possible into a reusable vocabulary. I look forward to suggestions for improvement.
Solution
Comments! Comments are good, especially to people who are just learning Factor right now. Admittedly, for Factor, it's pretty readable -- I finally got it, after staring a while and doing lots of Googling -- but comments are always nice.
I can't find anything about the
It looks good, though. After figuring out how Factor works, it's pretty readable (for Factor), and actually makes me want to use the language more. Plus, as far as I can tell, you're following the official coding style to the letter. Well done.
I can't find anything about the
: name>something ( etc -- etc ) word syntax online -- namely, the >something part. Because of that, I'm just gonna assume that it's good syntax and move on. Alright, I finally found it! And yes, that's good syntax -- you're supposed to use a>b for functions converting a to b, and that's exactly what you do. It might be better called directory-file-names>upper/>lower, but that's just personal preference.It looks good, though. After figuring out how Factor works, it's pretty readable (for Factor), and actually makes me want to use the language more. Plus, as far as I can tell, you're following the official coding style to the letter. Well done.
Context
StackExchange Code Review Q#1493, answer score: 4
Revisions (0)
No revisions yet.