37 karma · joined Feb 16, 2013 (13y ago) · 41 submissions
comment 13y ago · link · parent
Everything looks the same. Some time ago I read that Common Lisp had multiple return values. I was expecting something like Lua, where a function like this:
function fn() return 1, 2, 3 end
Is called like this:
a, b, c = fn()
But in Lisp, it's just the same old
(some-magic-words-here (other-things) (other-things))
Could I have some commas and equals signs to separate things at least? :-(
Then I heard various Lisps have classes, structs, objects and what not. Does it look like this?
{ name: value, name: value }
Or this?
class Name { Type name; Type name; }
No...
It looks like this:
(def-something ((something-here)) (something-else) (((something-else-2))))
If you are lucky you have a few :keywords or &keywords so your eyes have something to hang onto. Other than that, everything looks so... positional, and a closing parenthesis could mean anything from the end of a simple expression like (+ 1 1) or the end of the declarative part and the start of the executable part of a complex structure.
You don't even need to go that far to find these problems: just look at:
(let ((new-var-2 value) (new-var-2 value)) (some-code-here))
(if (condition) (runs-if-true) (runs-if-false))
You'd better use a very consistent indentation, because there is almost no visual separation between the "runs-if-true" and "runs-if-false"!
comment 13y ago · link · parent
((lambda (x y) (+ x y)) 3 4)
looks much harder to read than this:
(function(x, y) return x+y end)(3, 4).
In the Lua version, you can easily skim the code: here is a function (rather than a Greek letter), the parameters are inside parenthesis and separated by commas, the body comes next until the "end" keyword, it produces (returns) a value and then you pass the parameters (inside parenthesis and separated by commas again) to the function that was just created.
In the Scheme version, how am I supposed to know where this lambda ends other than counting parenthesis and having a lot of practice to recognize that (....... thing thing) is a function call where the function is more than a single name?
Similarly this:
(define (fn x) (lambda (a) (+ a x)))
IMHO looks much harder to read than this:
function fn(x) return function(a) return a+x end end
The second one is much clearer: "return function", you are returning a closure to the caller. The Scheme one makes me think: a function, another function, parenthesis, an expression, then it ends abruptly and I don't know what the hell the code supposed to do. Again, I CAN read that code in Scheme, but only after learning the core concepts in Lua.
comment 13y ago · link · parent
> Not sure what you mean with that. Braces, parenthesis, dots, semicolons, and IIRC you can use the arrow => without anything on its left side.
> The method is either defined on the type of the left, or added by an conversion from that type. That's it.
Unless it ends with a colon, right?
> Method calls with one argument can leave out dot and parentheses
That's somewhat simpler than I expected. I thought it was something Perl-like or Ruby-like (where obj.method + 1 is different from obj.method +1). There should be some way to get a reference to a method without calling it, that I still haven't learnt.
> If a method has a side effect, you define and call it with parentheses, otherwise you leave them out
Not sure I understand this. Is this the preferred coding style or something enforced by the compiler?
> I hope that helps a bit! Yes, it helped! Thanks!
comment 13y ago · link · parent
But I think I see what you are trying to say. You want the == operator to coerce its operands to the same type before comparing (like JavaScript's == operator), but Lua's == operator doesn't do that, it simply compares. And that's why other languages need an === operator and Lua does not.
(JavaScript, by the way is the inconsistent one in this regard: the == operator does coerce its operands, but if(something == true) doesn't do the same thing as if(something). Try it with an empty array)
comment 13y ago · link · parent
On the other hand, Scala gives me a completely different feeling: when reading the docs and samples, I often ask myself:
How can I mentally parse this?
It's nice that I can abbreviate some common constructs (when writing), but when reading code, how can I tell which concepts are being used? How do I look up these operators when they could come from anywhere (global, first operand, second operand, implicit conversion, etc.)
How do I know when parentheses, dots, curly braces, are mandatory or optional? Could the compiler misunderstand me in complex situations? Where does this construct really end if so many things are optional? At least F# uses indentation, so I know the compiler will warn me if I wrote something that is not quite right according to the precedence rules.
There are too many implicit things going on, how do I know which meaning of _ (underscore) is meant here?
comment 13y ago · link · parent
Other examples are inline (different from C++, makes use of weird combinations with static and extern) and tgmath (compiler magic inaccessible to user-defined functions until C11).
They also seem to __barely__ improve the language without ever being "cool" or "interesting".
At least C++ has some standard data structures...
PS: Even Python has binary literals, while they were deemed "not useful enough" for C.