« first day (359 days earlier)      last day (3129 days later) » 

7:05 AM
@Andy maybe you are interested in the last link. Luc showed how to write the type for Output more explicitly
 
user1804599
7:56 AM
@JohanLarsson For the same reason functions are useful: to reduce duplicate code.
 
I feel like giving up today.
 
user1804599
:(
 
But I don't feel like writing C# either
 
@JohanLarsson Yeah, rightfold showed that to me yesterday
 
oh, I managed to miss it, maybe he used fancy words
I often stop reading when the fancy goes over a treshold :)
 
8:06 AM
in Lounge<C+plus>, 19 hours ago, by elyse
fn f<T>(n: T) -> <<<T as Add>::Output as Mul<T>>::Output as Sub<T>>::Output
        where T: Copy + Add, <T as Add>::Output: Mul<T>, <<T as Add>::Output as Mul<T>>::Output: Sub<T> {
    (n + n) * n - n
}
 
ah, yes, nice
 
user1804599
macro_rules! f {
    ($n:expr) => ({ let n = $n; (n + n) * n - n });
}
 
user1804599
much better :P
 
this was in the Lounge and it was just playful stuff, but he did mention it here too
 
user1804599
This is also great:
 
user1804599
8:07 AM
fn main() {
    let n = 1;
    let n = n + 1;
    println!("{}", n);
}
 
user1804599
fuck yeah shadowing
 
> macro_rules!
reads funny
 
yesterday, by elyse
<T as std::ops::Add>::Output
I still have to re-read all the stuff about lifetimes
 
user1804599
You have to program in Rust. :P
 
yeah
I need to finish preparing this stupid presentation today
 
user1804599
8:10 AM
Do it in Rust.
 
but during the week-end I plan to spend some time with it
 
I have no ideas for non-UI projects
Felt like writing a wysiwyg markdown editor yesterday
with buttons to click
 
user1804599
Write a terminal-based presentation tool in Rust.
 
user1804599
Like Emacs, but more specialised.
 
8:27 AM
9
Q: How to create a static string at compile time

maximiI want to create a long &'static str made of repeating sequences of chars, e.g. abcabcabc... Is there a way in Rust to do this via an expression, e.g. something like long_str = 1000 * "abc" in Python, or do I have to generate it in Python and copy/paste it in the Rust code?

gonna try to write a macro for ^
expecting failure :)
looks fun
 
@AndyProwl isize is a type that is both addable and multipliable, so it implements both Add and Mul. So you can’t just ask about isize::Output because that’s ambiguous: is that the Output from Mul or from Add? <isize as Add>::Output is the full-form, to disambiguate.
 
@LucDanton Yep, that makes sense
 
What may be unusual is the syntax, and it’s so to be unambiguous. That way you don’t repeat the template/typename fiasco. Plus it’s just syntax.
 
That's true
OTOH I'm wondering how practical generic functions can be when something as simple as (n + n) * (n - n) requires all that complexity
in Lounge<C+plus>, 19 hours ago, by elyse
fn f<T>(n: T) -> <<<T as Add>::Output as Mul<T>>::Output as Sub<T>>::Output
        where T: Copy + Add, <T as Add>::Output: Mul<T>, <<T as Add>::Output as Mul<T>>::Output: Sub<T> {
    (n + n) * n - n
}
 
@AndyProwl Any time someone whines about C++ templates, concepts and template errors that is what they are asking for.
You can probably simplify a lot of stuff if you’re fine with assuming T: Add<Output=T> and so on, too.
@AndyProwl There you go.
 
8:44 AM
@LucDanton Yeah, I figured
@LucDanton Ah, that looks better
 
Keep in mind that the std::ops::* traits are syntactical in nature. Rustlib is currently lacking (well, last time I checked at least) a numerical tower.
 
user1804599
trait Semiring: Add<Output=Self> + Mul<Output=Self> + Zero + One { }
trait Ring: Semiring + Sub<Output=Self> { }
impl Ring for i32 { }
 
user1804599
You could also do something like that.
 
user1804599
:P
 
Yep, std::num still only has Zero and One. Fairly sure there used to be a Num a long time ago but that was sent back to the drawing board (well-deservedly), plus one or two other schemes(hah) in the meantime.
> I think we're in agreement that this should be done out-of-tree. Once there's a fleshed out library, proposing an inclusion of it in the standard library via an RFC would make sense.
 
user1804599
8:48 AM
Zero and One are unstable.
 
The Highlander approach to library making.
 
@LucDanton That is very nice, I tried some permutations with Add<Output=X> but not that one.
 
btw you can probably trait Num: Copy+Add<Output=Self>+Sub<Output=Self>+Mul<Output=Self> {} with a blanket impl as a 'pretend' numerical trait in the meantime
or shop around for some, I’m sure there are reasonable libs out there
 
9:43 AM
So close, so far away.
Profit, no idea if it is any good
@elyse flame away
first macro ever in any language
 
user1804599
why a macro
 
user1804599
that can be a function just fine
 
user1804599
Also the inner curly braces are redundant.
 
user1804599
{x} is equivalent to x for some expression x.
 
ah, yes
remained from a copy paste, +1
@elyse for this
 
user1804599
9:47 AM
It doesn't create the string at compile-time.
 
user1804599
I think you have to write a compiler plugin for that.
 
user1804599
Macros are simple AST splicing.
 
10:14 AM
I was really surprised when the macro compiled
ast splicing or not
 
 
4 hours later…
2:04 PM
Is there a way to do debugging/stepping?
 
 
1 hour later…
3:14 PM
impl is just for implementing traits right?
 
 
3 hours later…
6:33 PM
@JohanLarsson No. It’s also used for what corresponds to member functions.
 
7:02 PM
why is it better to write member functions as impl compared to OO-style?
 
I don’t know. Is it?
 
I'll look for a style guide.
 
I don’t think style enters into it.
 
ok
What are you working on?
 
Nothing
 
 
1 hour later…
8:15 PM
I think I get what you mean now for some reason I thought this was legal:
struct Foo {
    fn bar(){
    }
}
 
Yup. The struct and enum parts govern the data, the impl blocks cover the functions.
 
I'm an OO-tard :)
 
9:11 PM
hmm, missing C#'s yield return for a thing
 
 
1 hour later…
10:40 PM
 
yep, saw it
 
does it mean c++ has yield return?
 
those are so full of elyse-speak :)
what kind of refactoring are you doing in the kitchen?
 
10:50 PM
Just a new one.
Removal of a small wall. Replacing floor with tiles (because the wooden floor does not cover all the ground under current cupboards...).
Then, break out old kitchen (from former owners, we moved in 15 years ago) and finally get our own :)
But, let's stay on topic lest the mods fall upon us with their wrath.
 
doing it yourself?
 
Nah
 
@sehe meh
 
:D
 
How big is the kitchen? <- phrased to avoid lame stars :)
I refactored my kitchen a couple of years ago, will post some pics with things that turned out nice from a functional pow. But not tonight.
 
11:31 PM
@JohanLarsson Oh so tempted to star, just to be obnoxious...
 
would not be a problem
how are things?
 

« first day (359 days earlier)      last day (3129 days later) »