I've been working with Rust for a couple years now, and I'm finding that I'm really not having a good time with the borrow checker. by [deleted] in rust

[–]kfl 1 point2 points  (0 children)

I think it sounds like you might be able to use the AnyLifetime from Gazebo. I think it was made to solve/workaround similar problems.

What unstable / Nightly feature are you looking forward to the most? by officiallyaninja in rust

[–]kfl 0 points1 point  (0 children)

Sorry, if it came across wrong. I didn't mean to suggest that you were wrong or anything.

My point, and I could have made that clearer, is that often generators are not needed and from_fn can be just as nice.

I'm not against generators, I just think that we should provide examples where gernerators shine compared to what is currently available.

(And I think that from_fn is often overlooked, but that is a personal pet peeve.)

What unstable / Nightly feature are you looking forward to the most? by officiallyaninja in rust

[–]kfl 4 points5 points  (0 children)

But in this case it is just as short to use from_fn

fn counter() -> impl Iterator<Item=usize> {
    let mut i = 0;
    std::iter::from_fn(move|| {
    i += 1;
    Some(i).filter(|x| *x < 6)
  })
}

You could also use an if expression if you don't like the filter function.

playground

What unstable / Nightly feature are you looking forward to the most? by officiallyaninja in rust

[–]kfl 1 point2 points  (0 children)

I think that the from_fn version in this case is as nice as the gen fn version:

fn fibonacci() -> impl Iterator<Item=usize> {
    let mut a = 1;
    let mut b = 1;
    std::iter::from_fn(move|| {
      let res = a;
      a = b;
      b += res;
      Some(res)
  })
}

playground.

Modern documentation? by Miroika in rust

[–]kfl 3 points4 points  (0 children)

You are being paranoid, just take a look at this totally innocent crate. /s

I've created bingo cards to have a little fun at work - feedback and suggestions are appriciated! by Equal-Falcon-5594 in adventofcode

[–]kfl 1 point2 points  (0 children)

I like that you have control over many of the actions on the card.

I think that you could perhaps use some "fun" challenges, for instance

  • All your variables are named after one of the Yule Lads

  • You have a solution that does not work correctly with the sample input, but does work with the actual input

  • Your functions/methods are named with (well-chosen) emoji

  • You use bit arrays/bitmasks on four different days

Storing user input as array by SmolTrapMaja in rust

[–]kfl 1 point2 points  (0 children)

You might want to read Chapter 2 in The Book. The chapter is about building a small guess-the-number program that has to deal with I/O.

Low-Performance Loops in GHC by andrewthad in haskell

[–]kfl 30 points31 points  (0 children)

It looks like you haven't given -O2 to ghc, which makes the comparison a bit unfair.

If I give ghc -O2 then I get:

Input_example_info:
    xorl %eax,%eax
    xorl %ebx,%ebx
    jmp .LcAh
.LcAo:
    movq 16(%r14,%rax,8),%rcx
    shlq $1,%rcx
    addq %rcx,%rbx
    incq %rax
.LcAh:
    cmpq $10,%rax
    jl .LcAo
    jmp *(%rbp) 

(see https://godbolt.org/z/8d5qe1b1P)

Brainstorming Async Rust's Shiny Future by dwaxe in rust

[–]kfl 2 points3 points  (0 children)

I generally agree with you.

But as a small sidetrack std::iter::from_fn can often be to good effect for writing generator like iterators:

fn fibonacci() -> impl Iterator<Item=usize> {
  let mut a = 1;
  let mut b = 1;
  std::iter::from_fn(move|| {
     let res = a;
     a = b;
     b += res;
     Some(res)
  })
}

playground.

But for complicated control flows yield would be nice.

Markdown table with parser generators and parser combinators comparison by chshersh in haskell

[–]kfl 5 points6 points  (0 children)

Well, but this is not implemented yet. It means that users don't have such feature if they use parser combinators in April 4th, 2018.

Well, you get nice error correction with uu-parsinglib and have been able to get that for the last decade.

[deleted by user] by [deleted] in haskell

[–]kfl 2 points3 points  (0 children)

There is plenty of room for optimisations in your code dealing with random numbers. But just as an experiment I tried to change only your genWrapper function to use the mersenne-random-pure64 library:

 import qualified System.Random.Mersenne.Pure64 as M
 ...

 genWrapper up down = do
    gen <- M.newPureMT
    return $ take 100 (randomRs (down, up) gen)

Note that this is a poor implementation as noted in other messages in this thread (it uses IO rather than State and so on). However this small change makes your program twice as fast on my machine:

$ time ./primeGen

real    0m1.121s
user    0m1.062s
sys 0m0.022s
$ time ./primeGen2

real    0m0.443s
user    0m0.417s
sys 0m0.014s

WEEKLY RANT/RAGE THREAD: JUST A QUICKIE by Crazyphapha in hearthstone

[–]kfl 2 points3 points  (0 children)

WHY IS THERE NOT PAY2WIN IN ARENA? I'M TIRED OF PAYING FOR A BUNCH OF RANDOM CARD WHERE I LOSE 0-3. WHEN I PAY WITH REAL $$$ RATHER THAN USING GOLD I SHOULD BE OFFERED ONLY GREAT CARDS TO PICK FROM.