« first day (1591 days earlier)      last day (1905 days later) » 

9:11 AM
@Shepmaster I was late to the party! OP seems to be confused. I also wrote an answer, maybe that will help.
 
 
3 hours later…
12:22 PM
Why do functions and closures not implement Debug?
 
@DarthBoiethios What do you expect them to print?
 
The tokens (for example)
 
I would expect a pointer ;)
 
Not for debug: it is intended to be helpful
 
"implement Debug" => "not for debug"
...
 
12:24 PM
You misinterpreted my sentence: printing a (function) pointer is not useful for debuging purpose.
 
ah okay
 
What would you do with it?
 
hmm.. it helps to see if two function pointers are equal ;)
 
@hellow That's not the point of Debug, and you can already do that:
fn foo(dbg: impl Fn()) {
    println!("{:p}", &dbg)
}
Debug should write a visual information about the implementing thing
 
true
 
12:30 PM
You mean the body of the function ?
 
What do you mean by tokens? Function parameters? the body? the name?
 
So if you write (for example) "hello".contains(|c| c == 'h'), I'd expect this closure to be printed as |c| c == 'h'.
 
what if your function is 200 loc?
 
or dynamically solved ?
 
That's not an issue: Vec implements Debug even if it has millions of items.
@DenysSéguret What do you mean?
 
12:32 PM
but you can't just call an existing thing, you have to put the string in the code at compilation time
 
@DenysSéguret Yes, that's what does Debug
 
what if it's an extern function?
 
@hellow Are you sure that an extern function implements Fn?
 
no ^^
 
@DarthBoiethios the value of a function variable isn't necessarely known at compile time
 
12:35 PM
@DenysSéguret My idea was to write the tokens of the function definition
@hellow I just verified, it does not implement Fn
 
oh :( okay, nevermind then
 
what would you expect to see here ?
Did I totally misunderstand you ?
 
@DenysSéguret Either fn add(x: i32, y: i32) -> i32 { x + y } or fn sub(x: i32, y: i32) -> i32 { x - y } depending of your boolean value
 
Assuming a is dynamic, how would that work ?
 
In this situation, you coerce your function into a function pointer, so that's different, but whatever
@DenysSéguret Heh, like every other Debug implementation. Replace Op by another type, that works well. What is the issue?
 
12:46 PM
Let's say it otherwise. How would your Debug impl produce the body of any function without storing it for all of them ?
 
In your example, I could implement my own debug trait with a procedural macro very easily
@DenysSéguret But it would store it! How do you think that Debug works?
 
@DarthBoiethios do you forget, that Debug must be implemented/stored during compile time and not runtime?
 
Nope, I don't forget it. The tokens are known at compile-time.
 
is that always the case? :thinking:
 
By definition, yes
You compile from a source code
Every function or closure has its own type, so there is no issue
 
12:50 PM
So you mean you would call your derive thing on a specific type, and that it wouldn't be available in this specific case:
 
Each of those types would implement Debug on the fly
 
let op: fn(i32, i32) -> i32 = if a < 3 { add } else { sub };
    dbg!(op);
 
@DenysSéguret I don't understand your question. If there is a bound trait Fn: Debug in the std crate, each type that implement Fn would be debugable.
 
Which means having the body of any function as a string in the executable, right ?
 
@DenysSéguret Yep
I see what you mean. Performance issue. I didn't think of that
 
12:56 PM
I wonder if this could somehow be applied to just types defined as aliases of specific Fn
 
1:07 PM
Or only to the functions or closures used as Fn implementations.
 
@DarthBoiethios and pointer is what if not implement information ?
 
You mean that Debug should write the pointer? That's not useful and no debug implementation does that AFAIK.
 
Well, I don't know about Rust but in C pointer of function already help me de debug my mess
 
do you often have function pointer mess in rust (honest question) ?
 
you doesn't in C so I suppose even least in Rust ;)
 
1:19 PM
I never had such a case I would have needed Debug on a Fn. But my experience in rust is limited
In C I can easily imagine falling in such a case ^^
(it happens in js but in js you can easily log a function)
 
1:31 PM
By the way, speaking of GAT, isn't it require to have debug implement for "all" type of function ?
 
Uh, I don't think so...
(and that's not quite about GATs)
 
@DenysSéguret I'm writing a test framework, and the user can pass a closure sometimes: my_string.should().contain(|c| c.is_alphabetic()) for example. If the test fails, I'd like to write something like: my_string must have this property: |c| c.is_alphabetic()
I guess that I'll create a wrapper that take a closure and have a Debug implementation, and I'll replace each closure by the wrapper at compile-time.
 
maybe replace contain by a macro ?
should_contain!(my_string, |c| c.is_alphabetic())
 
@DarthBoiethios Methinks you are better off "augmenting" those test functions with a name (or whatever description you wish).
Macros can help with this.
 
BTW I should learn proc macros. macro_rules are too much limited
 
1:45 PM
My tests have an attribute, so I can do that in the procedural macro. I'll definitely do something like that, but that's not a priority for now.
@DenysSéguret They are so powerful <3
 
@DarthBoiethios which ones ?
 
Proc macros, of course
They push metaprogramation at a point I couldn't imagine that was possible
 
2:10 PM
> programation
 
That's how you recognize French people on l'internet
 
2:28 PM
I guess there are thousands of ways to recognize that Im French :P
 
You're still not holding a baguette, though
 
If you send croissants, I will love you (platonic).
 
Ahaha. Here's the title of the chat room to which I connect every day since 5 years:
 
@E_net4 You dont have them in Portugal?
@DenysSéguret I must wait 1 month to change :(
 
@DarthBoiethios there's no other countries with the same croissants. Even Italy which is superior in most things related to food doesn't have our croissants
 
2:40 PM
@DarthBoiethios I do, but not for free right now, nor of the finest quality. :x
 
@E_net4 If this comfort you: France is not what is was and in ~90% of the bakeries, the croissants are disgusting (at least in Paris).
> Even Italy which is superior in most things related to food
I cannot let you saying such a bullshit :/
 
@DarthBoiethios it's true everywhere and it's more like 95%. In Villeurbanne, where there must be at least 50 bakeries, only two completely make their croissants
 
Hmm.
 
(my stats have internet level precision)
 
On a scale of 1 to fake news, I gather.
 
2:48 PM
A little better. I spoke a lot with one of those two bakers, who has no problem modifying his croissant recipe on demand, which is how you recognize real croissant makers. Of course he knows the other ones in the area but we didn't speak about this recently.
 
@DenysSéguret Even those who do one's own croissants are not necesseraly doing them well...
 
the "at least 50 bakeries" is just totally random
@DarthBoiethios True but why bother making your croissants yourself if it's not to do them better ?
 
Shoot even I make croissants. Takes 3 days.
 
3:51 PM
Nice. Two answers at the exact same second?
 
 
5 hours later…
9:20 PM
@Shepmaster must be hard to live in USA
bad food everywhere
The last one I hear of was deep-fried butter
 
@Stargateur I thought you were talking about bad food
I think Scotland might have us beat on deep fried foods like that though.
 
I feel my diabete increase just by looking picture of this food
 
 
1 hour later…
10:46 PM
0
Q: println! outside of loop is an unreachable statement, how to use a println in a "reachable" way

James SmithHow can I print the frequencies HashSet after the loop terminates? Problem seems to be there is no guarantee the loop terminates. use std::collections::HashSet; use std::fs; fn main() { let f = fs::read_to_string("input.txt").expect("Unable to open file"); let mut total = 0; let mu...

seriously
 

« first day (1591 days earlier)      last day (1905 days later) »