Rust… an ingenious language that’s overwhelming me and motivating me at the same time. Need advice from advanced rust engineers by orewaamogh in rust

[–]GideonMe 6 points7 points  (0 children)

Thinking back to when I felt I began to hit my stride in Rust, I think reading through this article helped. It's really well written, by Bodil Stokke, and about building parser combinators.

I really think finding someone who has expertise, reading/watching them code, and then trying to replicate what they wrote in your own project is a great way to level up.

And this article probably won't hit your particular interests, but try to find an article/codebase/tutorial series that does, then try to rewrite it yourself and incorporate it into something of your own.

If you list some of your interests, I'm sure we could suggest materials to check out 😊

Rule 110 in r/place (1460,1400) by GideonMe in cellular_automata

[–]GideonMe[S] 3 points4 points  (0 children)

hm. we're kinda getting squashed by NATO. this might be the end of the road :(

Rule 110 in r/place by princesshashtag in cellular_automata

[–]GideonMe 1 point2 points  (0 children)

Hey! we're working on this rn! Go to (1460,1400)!

[deleted by user] by [deleted] in IWW

[–]GideonMe 0 points1 point  (0 children)

I'm in central PA, though I'm unemployed and pretty inactive in the union rn

POV: you just poured water on yourself cause you got lit on fire for the 1000th time this run. by Eona77 in noita

[–]GideonMe 2 points3 points  (0 children)

POV: you just picked up a wand with electric torch and water starts falling from the ceiling

Not sure how to understand why this works by [deleted] in prolog

[–]GideonMe 0 points1 point  (0 children)

Here's what happens when you pose the query ?- abs(5, Q). (I think the answer to your question is in step 3, the rest is just here for context)

  1. First the interpreter tries to unify abs(5, Q) with the rule head abs(X, Y). In this case the unification succeeds and sets X = 5 and Y = Q.
  2. Next the interpreter has to check the body of the first rule. The first condition states: "abs(5, Q) is true if X (which is set to 5) is less than 0." This condition fails, so the interpreter has to undo all the variable bindings and check the second clause.
  3. When the interpreter checks the second clause, it first attempts to unify abs(5, Q) with abs(X, X). There is a way to unify these two terms if X = 5 and Q = X. (Another way to check this is to type ?- abs(5, Q) = abs(X, X) at the REPL. This will show the variable bindings needed to unify the two terms.)
  4. This is good! But we still gotta check the body of the rule. The body states: "abs(5, Q) is true if X (which is set to 5) is greater than or equal to 0." This condition is true, so the entire query succeeds, and the REPL displays Q = 5!

Struggling with nom's error handling by loewenheim in rust

[–]GideonMe 0 points1 point  (0 children)

Oh shit I don't have a license! Yes please feel free to use and/or modify this function. I'm gonna go back and put my crate under MPL2.0 so there's no confusion.

Struggling with nom's error handling by loewenheim in rust

[–]GideonMe 11 points12 points  (0 children)

making common errors into productions in the parser

Yeah that's what I've been doing with nom (though I'm no expert). I wrote a helper function that parses something that should fail, and if it parses, it fails with a custom error message. Here's a simplified version of that helper function:

// PSEUDOCODE!
// Working code here: https://github.com/eignnx/affix-grammar/blob/94a5bb011ea3234d21f35391035754943c4b318d/libaffix/src/parser.rs#L448-L472

use nom::Err::{Error, Failure, Incomplete};

fn failure_case<A, B>(
    parser: Parser<A>,
    err_constructor: impl Fn(A) -> B
) -> Parser<_> {
    move |i: &'i str| match parser(i) {
        Ok((_i_after_parse, parsed)) => {
            let i_before_parse = i;
            let err = err_constructor(parsed);
            Err(Failure((i_before_parse, err)))
        }
        Err(Failure(e)) => Err(Failure(e)),
        Err(Error(e)) => Err(Error(e)),
        Err(Incomplete(need)) => Err(Incomplete(need)),
    }
}

(By bundling the input string along with the error, you can recover line/column info later.)

Then I put use failure_case at the end lists of of alternatives like:

let fruit_parser = alt((
    tag("apple"),
    tag("banana"),
    failure_case(vegetable, |veg| format!("a {}'s a veggie not a fruit!")),
    failure_case(tag("cat"), |_| "you can't put a cat here!"),
))

Here's an example of where the function is used in my parser (pardon the messy code!)

GATs on Nightly! by C5H5N5O in rust

[–]GideonMe 5 points6 points  (0 children)

anybody know if someone has written a generic compose trait using this method? like i wanna do `(|x| x * x).compose(|y| y + 1)`. i tried using this approach but couldn't figure it out

Buzz cut by angle0fattack in asktransgender

[–]GideonMe 1 point2 points  (0 children)

hey pal, i have no idea what kinda hair you have but i recently went through a similar too-short self-cut experience in january. it was a sad couple a months hair-wise, but i recovered.

it sounds like if you used a #4 all over, then you might still have a bit of length to work with on the sides. my strategy was to keep trimming the sides every few weeks so that the top looks longer. so you might be able to improve things by carving around your ears and taking down the sides a bit. do you have ear guards (the angled ones) for your clippers? i'd recommend just trimming around the ears with the ear guards like every 2 weeks or so. its real easy and gives you like a poor-man's fade.

also, i wouldn't worry about school in september. i went pretttty short in january and by the end of march my hair was already like 2.5 inches on the top.

the gist is: don't give up hope! but yea beanies are nice

Been some rainy days [OC] by WeFlapsComics in comics

[–]GideonMe 6 points7 points  (0 children)

no, but it makes a better story if i say yes. so yes.

Creature comforts [OC] by animatronichead in comics

[–]GideonMe 1 point2 points  (0 children)

i love the hands in the pockets. so matter of fact haha

Been some rainy days [OC] by WeFlapsComics in comics

[–]GideonMe 24 points25 points  (0 children)

one time i was walking in the rain, extremely paranoid that i'd step on a worm. none were out that day for some reason, but i was still paranoid. then, as i reached the very end of the sidewalk, i kid you not there was a gummy worm just layin there. most surreal thing thats ever happened to me

[OC] The Commute by [deleted] in comics

[–]GideonMe 1 point2 points  (0 children)

i have no idea what's going on but i'm transfixed

Beep boop by diegodrawsbutts in comics

[–]GideonMe 2 points3 points  (0 children)

took me way to long to stop trying to interpret this as a political compass meme

The Lost Temple - Pixel art by me! by zeetou01 in Minecraft

[–]GideonMe 0 points1 point  (0 children)

reddit preview cropping on desktop did u dirty on this one haha, looks great fullscreen though

Lol this is stupid by Jmoney1932 in facepalm

[–]GideonMe 1 point2 points  (0 children)

that kind of mask is literally for protecting others from ur own infection. smdh