Having 2 to 3 keywords for the exact same purpose seems like a nightmare. Do we need `def`, `fun`, and `function`? Just pick one and only one. On another note, the docs are not so good. They're really missing a few real life examples with unit tests.
The Chaos Programming Language
81–87 of 87 posts
Re: The Chaos Programming Language
#82Earlier quoted context omitted.
No, it only means that you can reassign the name `a` to a different value (i.e. it is a variable, not a constant). It would be mutable if it allowed something like this: > a = 5 > a.add(1) > print a 6 Note that numbers are immutable in most languages anyway. Arrays, hashmaps, and sometimes strings are the data types that are frequently mutable.
That's standard behavior for object oriented languages. A different example with functions: function add(x, y) { return x + y } a = 5 add(a, 1) print(a) A language printing 6 is pass by reference. A language printing 5 is pass by value. Both would print 6 for this code a = add(a, 1) print(a) However a language like Erlang would end with an error when trying to reassign a new value to a.
function add(x, y) {
x = x + y
return x
}Re: The Chaos Programming Language
#83Earlier quoted context omitted.
Everyone says strings in java are immutable, yet you can still re-assign to string variables. It really is up for debate.
Java strings are immutable. Java variables with a string type are not. It's really not up for debate. You can't mutate a string in Java (you can in Ruby), but you can mutate a string variable by reassigning it.
Re: The Chaos Programming Language
#84I'd rather have another "dot directory" like ~/.occultist than have some random package manager take over my entire /usr/local.
Re: The Chaos Programming Language
#85Earlier quoted context omitted.
I have never worked with Haskell but admire it from afar, and I'm honestly astonished that the REPL works this way. I would assume this would error at the compiler for a normal program, and that the REPL runtime would enforce the same constraints.
I guess an argument can be made that forcing a restart of the REPL is a pretty harsh punishment, but I would expect Haskell (of all languages) to at least require some kind of tabula rasa.
Re: The Chaos Programming Language
#86As far as I understand after reading the docs for 5 minutes, this section is the core original idea behind the language: https://chaos-lang.org/docs/11_decision_making > Decision making(a.k.a. control structures) in Chaos language is only achievable on function returns for the sake of zero cyclomatic complexity. This looks as original and language-defining as Rust's borrow checker. I really wish authors changed their…
Even ignoring that issue, even if the control flow statement is in the return, it still has a cyclomatic complexity of 2. I.e. function isEqual(x, y) { return x == y } still has a cyclomatic complexity of 2, you're just hiding it. The actual logic flow in terms of nodes is
``` if (x == y) { return true } else { return false } ```
It's entirely possible for a single line to have a cyclomatic complexity of more than 1. Ternaries, for example, would have a cyclomatic complexity of 3.
Re: The Chaos Programming Language
#87Earlier quoted context omitted.
I'm still not convinced it doesn't just sweep the complexity under the rug. Ultimately you still need to branch unless you only want the language to do pure mathematical computation or something like that. Only now every branch needs to be hidden in a function call.
I have a large Elixir project with less than 10 branches (if then else) and they were written by other developers. Conditional logic is done either in pattern matching in function definitions (and some guard) or case/cond or with/else. I guess case/cond can be implemented with the return mechanism of Chaos. Maybe it's going to feel weird, maybe not. There is no pattern matching and I got the feeling that's going to c…