point<~(y=value)
instead of other languages' point.y = value
?I believe that syntax should be designed to make things simple for developers, not for the designers of languages or for compilers.
point<~(y=value)
instead of other languages' point.y = value
?I believe that syntax should be designed to make things simple for developers, not for the designers of languages or for compilers.
"point.y = value" is typically a statement for a single update of a mutable record.
I'm not sure how you'd extend the latter to support the features of the former. The meaning is completely different. Different things should look different.
iex(1)> point = %{x: 1, y: 2, z: 3}
%{x: 1, y: 2, z: 3}
Of course this doesn't work iex(2)> point.x = 4
** (CompileError) iex:2: cannot invoke remote function point.x/0 inside match
This is how we do it, verbosely iex(3)> Map.put(point, :x, 4)
%{x: 4, y: 2, z: 3}
Or with a syntax shortcut iex(4)> %{point | x: 4}
%{x: 4, y: 2, z: 3}
A better syntax shortcut would be the usual iex(nope)> point.x = 4
%{x: 4, y: 2, z: 3}
which everybody would understand no matter the language of origin. I imagine that it would require quite an overhaul of the internals of the compiler, but the compiler should bend to us, not us to the compiler. This is my point about obscure language syntaxes. 2.3.0 :001 > s = "abc"
=> "abc"
2.3.0 :002 > s.gsub("b", "B")
=> "aBc"
2.3.0 :003 > s
=> "abc"
2.3.0 :004 > s.gsub!("b", "B")
=> "aBc"
2.3.0 :005 > s
=> "aBc"
I guess that if an immutable language shows some mutable syntax we can expect it to be a short form. Actually Elixir has at least a mutable short form: iex(1)> s = "abc"
"abc"
iex(2)> String.replace(s, "b", "B")
"aBc"
iex(3)> s
"abc"
The next line would be an error in Erlang and other languages because we can't mutate an already assigned variable there, but Elixir allows rebinding iex(4)> s = String.replace(s, "b", "B")
"aBc"
iex(5)> s
"aBc"Your proposed syntax also doesn't have any obvious way to do a bulk update, and I'm not sure what syntax you're proposing for that.
I maintain that it's more important for things to look like how they act, rather than look familiar -- especially if the familiar appearance does something functionally different -- https://stackoverflow.com/a/522168
point.copy(y=value) let point2 = { point1 with y = value }
https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...EDIT This is inherited from OCaml - https://v1.realworldocaml.org/v1/en/html/records.html#functi...
--Niklaus Wirth (Good Ideas,Through the Looking Glass)
>Thus, x = y does not mean the same thing as y = x.
Unless it does, or should.
The specfic argument you're arguing here is on that is just a simple syntax. You don't like = for assignment, but I do. You like = for comparison, but I like ==... To be fair === is dumb.
You're arguing that point<~(y=value) makes sense, and I'm still not seeing it.
Pascal: Is X equal to Y?
C: Change X, making it equal to Y.
Mathematics: X is equal to Y.
Those are all valuable in programming. Normally programmers get the mathematical meaning via a feature such as __assume or __builtin_expect or assert. It can be used for optimization. When the constraint is violated, various bad things can happen. The code can run slower, halt with an error message, or behave in an undefined way.
Every new generation of programmers starts off expecting the mathematical meaning. I don't know of any programming language which uses it. Ideally that would be fixed, but the change might be difficult for the current generation of programmers.
Note that the Pascal meaning can be fairly compatible with the other meanings. The solution is simply to be aware of context. On a line by itself, X=Y makes no sense as an equality test. Within the controlling part of an "if" or loop, assignment need not be supported. That does the job. Alternately, the meaning could change by having a keyword in front for assignment ("let" is popular) and/or for the assertion. So we could distinguish all three meanings with syntax like "if X=Y", "let X=Y", and "assume X=Y".
Most lines of code are written as true statements. If you understand how a computer actually works at the register level you'd see that
x=5; has a result. And it's not 5. It's TRUE. I'm not asking if x equals 5, I'm saying HEY YOU, X IS EQUAL TO 5. I'm telling the computer this is now the truth. 5 is moved into the x RAM location and the result is true, because the CPU is doing what I told it.
You're just wrapped up in your semantic view. There is nothing wrong with = for assignment and == for evaluation. Someone would complain if it was the other way around, so just accept this is the standard - or make your own language that "does things right". But.... Just because it isn't the way you like it, doesn't make it wrong.
eq is often the wrong one to use: two instances of the same number can fail to be eq.
Obviously someone please correct me if I'm wrong.