Is This Style?

Update: I need an English compiler that can warn me after so many moronic errors. I forgot about the expr ? expr : expr form in C/C++. That can be thrown around injudiciously. That kind of makes the snippets below pointless. I guess the jist was that you can place any kind kind of expression as an argument for another. I'll leave the rest of the original post so people can see what coding all night does to someone's brain.

I've been playing around with Lisp lately, and I just wrote some code in which I wished C++ was a bit more malleable. Here's the simplified C++ code fragment:

if(string.isEmpty())
	msg = "Empty";
else
	msg = string;

I would never of thought of the above code as being bad if I had never touched Lisp, but the msg = is pointless. This is how the above would have been done with Lisp's syntax:

(setf msg (if (is-empty string)
              "Empty"
              string))

There's something about being able to throw if statements and anything else wherever I need a value. That's pleasing.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

You're looking for...

msg = string.isEmpty() ? "Empty" : string;

Ad's by Google