-
Notifications
You must be signed in to change notification settings - Fork 34
Implement format string #93
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
Conversation
The formatting follows the following style:
andika("") // nothing
andika() // newline (historical reasons)
andika("hello") // hello
andika("mimi ni {0} niko hapa {1} kama {0}", "Nuru", "github")
// mimi ni Nuru niko hapa github kama Nuru
andika("{0}") // error
andika("", "") // error
The errors are still generic with no helpful information.
This is not an issue with this pr only but deeper so future problem.
This is potentially solves NuruProgramming#81
and successor to NuruProgramming#82
Signed-off-by: Gekko Wrld <gekkowrld@gmail.com>
|
Here are my thoughts:
My advice would be to add string formatting to the string object itself, I've included examples in Go and Python:
|
When you want to write something like '{}', previously it was an error,
now you can escape using '\{'.
The closing one may be escaped but its not mandatory. e.g
`andika("\{}")` and `andika("\{\}")` will produce the same result.
Signed-off-by: Gekko Wrld <gekkowrld@gmail.com>
True but not many programs will be affected.
Fixed in comit f49a4b7
This is an invalid syntax, Go (the golps lsp atleast) throws a warning and go itself prints "%!(EXTRA string=)".
Python does have that only on Go doesn't have string Look at the '%' formatting here https://github.com/golang/go/blob/master/src/fmt/print.go |
So the equivalent in Nuru would be to do it on the String object, and not the built-in |
|
Consider a case where someone wants to format a string and assign it to a variable, how would one achieve that with your implementation? |
Yes, so something like This will mean that the andika() function can be used as before. |
We could have added another function for formatting e.g unda() and then by default call it for formatting and print the resulting string, like your example in golang |
Yep, but probably a different name (don't wanna confuse people with unda).
Exactly
This will add unnecessary complexity. Let's go with modifying the String object. If you agree, kindly close this PR and make a new one. |
What other name conveys that it will be formatting without confusion? |
Not sure 😅 |
|
I'll just use unda until a better name is found. |
Strings now can be formatted using the `"Jina langu ni {0}".badilisha('Nuru')`.
Sucessor to <NuruProgramming#93>
Instead of using a function, just do it on the string level.
Signed-off-by: Gekko Wrld <gekkowrld@gmail.com>
|
Look at: #94 |



The formatting follows the following style:
andika("") // nothing
andika() // newline (historical reasons)
andika("hello") // hello
andika("mimi ni {0} niko hapa {1} kama {0}", "Nuru", "github")
// mimi ni Nuru niko hapa github kama Nuru
andika("{0}") // error
andika("", "") // error
The errors are still generic with no helpful information.
This is not an issue with this pr only but deeper so future problem.
This is potentially solves #81
and successor to #82
Actually does "Should have string manipulation instead" #82 (comment)