The solution to the world's growing refugee crisis isn't shutting them all out, but it's not letting them all in either, according to Bill Gates.

"In the long run the way to avoid refugee problems is to help countries develop by having good health, education and governance," the Microsoft cofounder wrote in his fifth "Ask Me Anything" session on Reddit. "[F]ortunately the overall trend is good despite huge setbacks like Syria, South Sudan and Somalia."

But for the trend to keep heading in the same direction will require American involvement, not withdrawal under an "America First" banner.

"Overall like Warren Buffett I am optimistic about the long run," Gates wrote, noting that macro trends show that the world is getting better and better. However, "I am concerned in the short run that the huge benefits of how the US works with other countries may get lost. This includes the aid we give to Africa to help countries there get out of the poverty trap."

Despite having followed his career as a visionary software CEO with a career as a philanthropist, Gates sees government as a more important driver of change in the world than the charitable actions of ultra-rich individuals like him. "Philanthropy is small as a part of the overall economy so it can't do things like fund health care or education for everyone," he wrote. "Government and the private sector are the big players so philanthropy has to be more innovative and fund pilot programs to help the other sectors."

A few other highlights from the AMA session.

Artificial Intelligence: A Risk We Can Mitigate?

Gates is as excited as any technologist about the promise of artificial intelligence. "The big milestone is when computers can read and understand information like humans do," he wrote.

But he's concerned, too. Gates brought up the values alignment problem when it comes to AI: "One thing to make sure the people who create the first strong AI have the right values and ideally that it isn't just one group way out in front of others. I am glad to see this question being discussed. Google and others are taking it seriously." (Gates has emphasized the risk from AI in the past as well.)

Gates's Greatest Achievement, According to Gates

Global healthcare is a special passion of Gates's and the chief beneficiary of his work with the Gates Foundation. Asked what he considers his greatest achievement, he acknowledged the obvious -- "the chance to be part of the software revolution empowering people was the biggest thing I have gotten to do" but made it clear it's healthcare that has his attention these days. "Right now I am very focused on making sure we successfully eradicate polio -- that will be amazing if we do it -- as good as shipping even the best software product," he said. Elsewhere, he noted, "We need a vaccine for HIV, Malaria and TB and I hope we have them in the next 10-15 years."

How Trump Should Approach Climate Change

Asked about President Trump's views on climate change, Gates said, "I hope his administration will decide that funding R&D to invent the next generation of energy (clean, cheap, reliable) is a good deal for the US and for the world. Climate change requires cooperation between countries over a period of decades but we don't have much time to waste."

It All Depends on the Bun

And of course, Bill Gates weighed in on the weightiest question of all: whether a hot dog is a sandwich. "If you don't have a bun then it absolutely is not. If you slice the hot dog and put it on a normal piece of bread (like Burgermaster) then it is. When you use a hot dog bun then it is ambiguous."

So that settles that.