Created
August 29, 2019 09:24
-
-
Save infinisil/29aa5341646a13bd65b8a2f245b26f07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with import <nixpkgs/lib>; | |
let | |
printf' = | |
result: # String | |
format: # [ Char ] | |
builtins.trace "printf' \"${result}\" \"${builtins.toJSON format}\"" ( | |
if length format == 0 then result else | |
if head format == "%" then | |
let | |
type = head (tail format); | |
rest = tail (tail format); | |
in | |
if type == "s" then | |
string: printf' (result + string) rest | |
else if type == "d" then | |
number: printf' (result + toString number) rest | |
else if type == "%" then | |
printf' (result + "%") rest | |
else throw "Invalid format string" | |
else | |
printf' (result + head format) (tail format)); | |
printf = format: printf' "" (stringToCharacters format); | |
in | |
printf "%%%ste%dst" "hi" 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment