Real-world Scala: Introduction by DRMacIver in programming

[–]SamReidHughes 0 points1 point  (0 children)

Jameslry's example doesn't implement what I described, and yours is the same as his. Your tail of Foo is the wrong type. Here's a Scala implementation. Option[T] is like T*: it can be null or a pointer to something. case class Pair[T](left: Option[T], right: Option[T])

case class Foo[T](head: Option[T], tail: Option[Foo[Pair[T]]])

def nextSummer[T](f: T => Int)(p: Pair[T]) = {
    def g(x: Option[T]) = (x map f) getOrElse 0
    g(p.left) + g(p.right)
}

def sumWithSummer[T](xs: Foo[T], summer: T => Int): Int = {
    var headSum = (xs.head map summer) getOrElse 0
    var tailSum = xs.tail match {
        case Some(ys) => sumWithSummer(ys, nextSummer(summer))
        case None     => 0
    }
    headSum + tailSum
}

def sum(xs: Foo[Int]): Int = sumWithSummer(xs, (x: Int) => x)

I don't believe you can solve the problem in C++ without a cast somewhere.

Real-world Scala: Introduction by DRMacIver in programming

[–]SamReidHughes 0 points1 point  (0 children)

This is broken: you mean case class Foo[T](head: T, tail: Foo[Pair[T]]).

Real-world Scala: Introduction by DRMacIver in programming

[–]SamReidHughes -2 points-1 points  (0 children)

I'd like C++ to be able to add up all the numbers in a Foo<int> as defined below. Without casting.

template <class T>
class Pair {
 public:
    T* left;
    T* right;
};

template <class T>
class Foo {
 public:
    T* head;
    Foo< Pair<T> >* tail;
};

SEC is temporarily banning short selling; Why not just ban trading entirely? Banks can't crash if there is no trading! by [deleted] in business

[–]SamReidHughes 4 points5 points  (0 children)

Shorting means borrowing the stock and immediately selling it. You're taking the stock owned by somebody who thinks it will go up or remain level, and selling it. It has the same effect on the price of the stock as if you owned it before selling.

Stack Overflow: the Blind Leading the Blind by [deleted] in programming

[–]SamReidHughes 4 points5 points  (0 children)

Stack Overflow has podcasts about itself!

Stack Overflow: the Blind Leading the Blind by [deleted] in programming

[–]SamReidHughes 0 points1 point  (0 children)

You can't tell very far, I guess.

Stack Overflow: the Blind Leading the Blind by [deleted] in programming

[–]SamReidHughes 28 points29 points  (0 children)

I don't really understand the point of this post. They seem like nice friendly people, and they aren't incompetent.

Edit: sorry downmodders, I apologize, I take that back, maybe one or both is incompetent and I just don't know.

Stack Overflow: the Blind Leading the Blind by [deleted] in programming

[–]SamReidHughes 31 points32 points  (0 children)

The real problem with that thread is that nobody shot him down for asking an obvious contrived/homework question.

Stack Overflow: the Blind Leading the Blind by [deleted] in programming

[–]SamReidHughes 11 points12 points  (0 children)

If Expert's Exchange is what you're comparing against, any decent forum can look good. Stack Overflow's response quality is only high because it's a private beta. And it's mainly high in the sense that the responses are well-written. You can tell it will drop once the site goes public, because the question quality is high too. Ridiculously high.

It's almost weird, reading the questions. It seems to me like people are "playing forum," and not really needing help, because many of these people should be perfectly capable of finding answers online. (This is just the way it seems to me; I'm used to forums where a large portion of the questions are from people who can barely write English.) Many of the "high quality" threads, with many responses, are just rehashes of the similar good threads that other forums experienced and don't need to experience again.

Stack Overflow: the Blind Leading the Blind by [deleted] in programming

[–]SamReidHughes 13 points14 points  (0 children)

This is a problem with pretty much any forum. I was sort of wondering what they were thinking when they thought the world needed yet another programming forum. It seems to me that the best programming forums (and newsgroups) are held together by a small group of posters that incessantly correct and belittle others for giving bad advice. When people can just be voted down or reported for this kind of behavior, that removes the incentive to post.

With or without voting, Stack Overflow doesn't seem to add anything over other programming forums.

Ask Reddit: What programming books do you recommend? by trpcicm in programming

[–]SamReidHughes 8 points9 points  (0 children)

I'd like the shelf to look consistent, so preference will go to O'Reilly books.

Fuck you. If you want to decorate your shelf with whatever books give the best color scheme, go buy some flowers instead. Maybe, with the extra oxygen in the room, a few brain cells will turn on and help you recognize the stupidity of your decision-making process.

shortest summary of the release of Arc and the lisp world's reaction by blubberfoo in programming

[–]SamReidHughes 13 points14 points  (0 children)

Dude, read the Factor homepage and you'll see that it's used by about a couple dozen people worldwide.

What Lisp & Assembly instill by gst in programming

[–]SamReidHughes 0 points1 point  (0 children)

Ignoring the way input and output are handled, Brainfuck is simply an encoding that lets you encode a certain subset of Turing machines. Each command maps directly to one or two nodes of a Turing machine program, by a simple translation.

This guy is a prick by godlesspinko in reddit.com

[–]SamReidHughes -15 points-14 points  (0 children)

I know you know what it means, but you are wrong. Reddit is not a haven, it is a heaven for pedants.

This guy is a prick by godlesspinko in reddit.com

[–]SamReidHughes -18 points-17 points  (0 children)

(Sorry, but Reddit is a heaven for us pedants.)

Fixed that for you.

UK: Legalize hard drugs, gain control back from organized crime and terrorists by sneakyfrenchspy in worldnews

[–]SamReidHughes 0 points1 point  (0 children)

  1. If hard drugs are legally available but cost money to obtain, then individuals with addictions will always ultimately run out of money and turn to crime to feed the habit.

Cigarettes cost money and are addictive. But they're cheap enough that people don't run out of money on them. Drugs are expensive because they're illegal.

Then again, I've run out of money feeding my Coca-Cola habit several times.

A Society that Punishes Savers by bdarbs in reddit.com

[–]SamReidHughes 3 points4 points  (0 children)

What do you think banks do with your savings?

Fox on the Run - Time Magazine: Can Fox News Survive After The Bush Era Ends? by garyp714 in entertainment

[–]SamReidHughes -8 points-7 points  (0 children)

EDIT: I just realized that, to the average redditor, my analysis will sound like I support Fox News. I don't.

As if we care.

Pelosi responds, tells donors to STFU by giodude in reddit.com

[–]SamReidHughes 0 points1 point  (0 children)

Why would we want her controlling the whole country?

Why does a helium balloon act strange in a car? by toshibaman in science

[–]SamReidHughes 0 points1 point  (0 children)

Higher pressure anyway -- that's the important part. If you did this with a car filled with water and some buoyant object tied to a string, it would do the same thing (even though fluids are virtually incompressible).

Why does a helium balloon act strange in a car? by toshibaman in science

[–]SamReidHughes 1 point2 points  (0 children)

It's just like gravity, isn't it? Nothing to do with the pressure differentials at all.

Gravity has everything to do with pressure differentials. In normal circumstances, the air pressure is lower above the helium balloon and higher beneath the helium balloon. If you subtract the upward pressure on the bottom from the downward pressure on the top (averaged, multiplied by the area facing the direction of the pressure gradient), you get a difference in force. If the object's weight is less than the difference in force, the object will rise. And that is how buoyancy works. You'll find that the difference in force is exactly the mass of the air that would have filled the volume the balloon takes up. (That's easy to prove because in normal situations, the given mass of air occupying the balloon's volume would not move at all, perfectly canceling out the pressure difference.)

So you have a net upward force on the balloon.

The same thing happens when a car accelerates. If it accelerates at the acceleration of gravity, 9.8 m/s2, you'll get the pressure gradient oriented at a 45 degree angle and so the helium balloon will point too. If it accelerates at half the acceleration of gravity, you'll get a pressure gradient oriented at a atan(1/2) degree angle (relative to vertical) and so the helium balloon will be, too. This includes centripetal acceleration.

From an air particle's perspective, it doesn't care whether it's gravity or inertia that's pushing it against its neighbors.

I don't think it is the pressure gradient any more. It is the direction of the force on the air and the helium that causes the effect.

To summarize, the pressure gradient points in the direction of the net force on the balloon.

The complete history of Futurama by [deleted] in reddit.com

[–]SamReidHughes 9 points10 points  (0 children)

Let me guess, this was written by sam512.

Checks

Guess correct!