mikeizbicki / cmc-csci181-languages

3 stars 4 forks source link

RASP Library question #29

Open danzhechen opened 3 weeks ago

danzhechen commented 3 weeks ago

Hi there,

I was exploring the rasplib.rasp file and I was a bit confused with this count function. The function states that

def count(seq,atom) {
    return round(
        length * aggregate(
            full_s, indicator(seq==atom)));
}

But I did not see any explanation on either indicator or round. I know we talked about it in the second class. I searched up their README but there was no information. Is there a way that I can quickly search it up and grab that piece of information?

RowanGray472 commented 3 weeks ago

Indicator converts bools into integers. In the case of the count function it's returning a 1 if the element in the sequence equals the provided atom, and a 0 otherwise.

Round is just a function that rounds to the nearest integer. Sometimes it does this strangely because of floating point spooky stuff.

Mike explained both of these in the READme for this section like this

Types can be cast to other types.

indicator(indices < 3);      # convert bool to int
round(indices / 2);          # convert float to int
danzhechen commented 3 weeks ago

Thank you so much for the reply! I found out that Mike talked about it in class. But if we want to grab that information for the author's library, like first time to interact with this, is this more a default knowledge or they marked it somewhere?

RowanGray472 commented 3 weeks ago

I honestly forgot what an indicator was and figured it out by just plugging in the code and seeing what happened. That seems like a decent approach for figuring out confusing RASP functions—of course it doesn't solve the bigger problem of learning how to solve new things we haven't seen yet.

I think Mike mentioned that none of this is going to be documented anywhere. I'm in the process of documenting some of the functions to help my understanding a bit—happy to post them on my git if I have time to finish them and the homework today, although we'll see lol.