-
Notifications
You must be signed in to change notification settings - Fork 206
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
feat: Implement print method #3576
feat: Implement print method #3576
Conversation
@TomAFrench @vezenovm review please |
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.
Looks good. Could you also add a couple print tests to nargo_cli/tests/execution_success/strings
?
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.
If we add a print
function, I think we should reimplement println
in terms of that so that we only have 1 primitive instead of two. println
could be rewritten as
unconstrained pub fn println<T>(input: T) {
print(input);
print("\n");
}
Would
be a quicker alternative than 2 calls? |
438c4e1
to
f15ca48
Compare
Possibly, I'm not quite sure. Feel free to go with whichever approach is easier / more straightforward. |
I think this would be preferable to avoid multiple foreign calls being performed. |
Pending a reply on the previous point, I have another suggestion: @TomAFrench Let me know if this is the right idea |
2784290
to
575b2c0
Compare
@grasshopper47 format strings should be able to be printed. If I had to guess what was happening, when you switched println to print, we're missing an explicit check for |
Format strings ARE printable, just someplace else, and duplicating that in For tuples, my guess is that we'll need to switch the params around, the bool being first, maybe. |
575b2c0
to
129fbed
Compare
You should be able to run them all with |
I've been trying to run the tests locally to see why 2 of the checks are failing, but I'm unable to do so, see previous comment. Currently I'm blocked on this. I've tried: #[oracle(print)]
unconstrained fn print_oracle<T>(_input: T)
unconstrained pub fn print<T>(input: T) {
print_oracle(input);
}
unconstrained pub fn println<T>(input: T) {
print(f"{input}
"); This will not work when passing 2nd thing I've tried: #[oracle(print)]
unconstrained fn print_oracle<T>(_input: T, _with_newline: bool) {}
unconstrained pub fn print<T>(input: T) {
print_oracle(input, false);
}
unconstrained pub fn println<T>(input: T) {
print_oracle(input, true);
} This works fine, except for the failing checks. If there's no help further possible on this, then I suggest we revert to unconstrained pub fn println<T>(input: T) {
print(input);
print("\n");
} and call it a day |
@grasshopper47 it runs past that point for me locally. Do you have |
Clang install did the trick, many thanks! |
@jfecher Something wonky about this branch, I remade the PR. It contains all the changes requested here. |
# Description ## Problem\* Resolves **#3575 Resolves **#2912 (duplicate) Continuation of #3576 ## Summary\* Refactors `println_oracle` method into `print` with boolean indicator, allowing `print` to coexist with `println` under the same `ForeignCall` string symbol. Updates appropriate tests, and logging.md documentation. Add a subchapter to `03_string.md` documentation for the `fmtstr` type ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [x] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: jfecher <[email protected]>
Description
Problem*
Resolves #3575
Summary*
Adds
print
method alongsideprintln
to ease printing in special use-cases, such as elements of slices.Updates appropriate tests, and
logging.md
documentation.Add a subchapter to
03_string.md
documentation for thefmtstr
typeAdditional Context
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.