4 ms·
Correct me if I'm wrong but doesn't Ruby have everything (maybe just most?) things be an expression. I always liked x = if condition something
by dopamean 10y ago
Correct me if I'm wrong but doesn't Ruby have everything (maybe just most?) things be an expression. I always liked
x = if condition
something
else
something_else
end
- stormbrew 10y agoEverything is an expression in Ruby, yes. Even `class` and `def` and `module`, for example. Though class, as a specific example, returns nil, so it's not terribly useful that it is one.
- junke 10y agoIn Lisp, "def..." macros, like defclass, defun, etc. return the symbol to which is bound the definition. Not essential, but useful at times. I tend to find Lisp is full of details like this.
- kazinator 10y agoWell, Common Lisp! In the Scheme language, many imperative forms have an unspecified result. For instance, see R7RS 4.1.6: "the result of the set! expression is unspecified". Also, a related misfeature is that function arguments can be evaluated in any order.
- junke 10y agoYes, sorry, Common was implied (not claiming it should always be, but here I wrote it without thinking about others). Scheme's unspecified results are annoying indeed.
- qwertyuiop924 10y agoYes, this is one of the things that I really want to punch the SSC for. Assignment should have a useful return value: even C, so often said to do The Wrong Thing, got that right. But for those of you who aren't scheme programmers, it gets worse: because when RnRS says that the result of something is "unspecified" many implementations take it literally. That's right: in many Schemes, `set!` returns the literal value #<unspecified>. I swear I'm not making this up. It's awful. To quote Jonathan Gabriel of Penny Arcade: "Baby, why you always gotta make me hit you?"