"I think that it's extraordinarily important that we in computer science keep fun in computing."
-- Alan J.Perlis
Dedication, SICP

youtube.com/watch?v=7oV7hiAsVT

Follow

"this is just beautiful." πŸ˜“

Β· Β· Web Β· 2 Β· 0 Β· 0

I totally agree with the speaker on the final slide: SICP is an absolute masterpiece.

Even though it's supposedly an introductory CS textbook, I learnt a lot by reading it after I had already been programming for over a decade.

In fact, I would have likely missed much of SICP's elegance if I hadn't been programming in imperative style for years.

Show thread

So, am I using functional programming on a daily basis now?

No. And probably never will.

But I still think that every serious engineer should be exposed to these concepts.

Show thread

@codewiz are the `auto` for "our types are too long to type" or "we are just lazy" ? πŸ˜‚

@Matthieu Answering your question requires introducing certain... concepts πŸ˜…

@Matthieu Ok, I must do it. It's too elegant. Too beautiful.

That auto in the parameter list is a C++20 shortcut syntax for templates:

template<typename T>
auto fib(T n) {
...
}

He says "C++20 concepts" in the slide because you could also throw in a concept right there:

auto fib(std::integral auto n) {
...
}

And this would _still_ be a template function, just not one that accidentally concatenates strings just because they had an operator+()

@Matthieu Now that I look at it a bit more, fib() being a template is kind of dumb, because immediately afterwards he forces the type to int for the nested lambda fib_iter.

So, even you passed a long long, it would get truncated to an int in the recursive step!

Going generic there would require naming the type, which brings back the full blown template syntax πŸ€¦β€β™‚οΈ

Isn't that elegant?

@codewiz the hell is he doing creating an std::function there? bonkers! @Matthieu

@namark @Matthieu He wanted to show that you could do a recursive lambda... It captures itself with [&] πŸ˜–

@codewiz -_- it doen't... you need to declare it separately then assign it to capture it. And it's the worst way to do recursive lambda, the guy needs to learn to scroll in stackoverflow, or some basic functional programming.
@Matthieu

@codewiz I just had to do it:
ix.io/2B03/cpp

It's like exactly the same trick he used with the a and b to optimize fibonacci, except in case of self reference you actually need that trick cause the lambda does not have a type name, while a and b are states and as such belong in the capture list more than the self reference. Sooo much angeeer!

@Matthieu

@codewiz the real question is: can you car/cdr an integer_sequence?

Sign in to participate in the conversation
Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!