Does the functionality of Grouping operator () in JavaScript differ from Haskell or other programming languages?

Grouping operator ( ) in JavaScript

The grouping operator ( ) controls the precedence of evaluation in expressions.

does Not differ from Haskell or other programming languages. (there is a minor exception as a byproduct of their main purpose in Lis…


This content originally appeared on DEV Community and was authored by Ken Okabe

Grouping operator ( ) in JavaScript

The grouping operator ( ) controls the precedence of evaluation in expressions.

does Not differ from Haskell or other programming languages. (there is a minor exception as a byproduct of their main purpose in Lisp/Clojure)

In other words, grouping operator ( ) in every language shares the common functionality to compose Dependency graph

In mathematics, computer science and digital electronics, a dependency graph is a directed graph representing dependencies of several objects towards each other. It is possible to derive an evaluation order or the absence of an evaluation order that respects the given dependencies from the dependency graph.

and the functionality of Grouping operator ( ) itself is not affected by a evaluation strategy

Perhaps we can share the code below:

  • f() * (g() + h())

to discuss the topic here, but not limited to the example.

Haskell

In the code in Haskell where the evaluation strategy is Lazy / Call-by-need

https://en.wikipedia.org/wiki/Lazy_evaluation

In this code, according to the call-by-need, the evaluation order of f g h is

h(1) -> f(1) -> g(1)

In this code, according to the call-by-need, the evaluation order of f g h is

f(1) -> g(1) -> h(1)

JavaScript

//function definition  
const f = a => a + 1;  
const g = a => a + 2; 
const h = a => a + 3; 

//calling functions 
console.log( 
(f(1) * g(1)) + h(1) 
); //10 
console.log( 
f(1) * (g(1) + h(1))   
); //14 

In this code, according to the eager-evaluation the evaluation order of f g h is

f(1) -> g(1) -> h(1)

in both cases.

Either way, the regardless the evaluation strategies, since the dependency graph composed with Groping operator() and + * stays identical, the final evaluated value is also identical.


This content originally appeared on DEV Community and was authored by Ken Okabe


Print Share Comment Cite Upload Translate Updates
APA

Ken Okabe | Sciencx (2021-09-30T20:27:34+00:00) Does the functionality of Grouping operator () in JavaScript differ from Haskell or other programming languages?. Retrieved from https://www.scien.cx/2021/09/30/does-the-functionality-of-grouping-operator-in-javascript-differ-from-haskell-or-other-programming-languages/

MLA
" » Does the functionality of Grouping operator () in JavaScript differ from Haskell or other programming languages?." Ken Okabe | Sciencx - Thursday September 30, 2021, https://www.scien.cx/2021/09/30/does-the-functionality-of-grouping-operator-in-javascript-differ-from-haskell-or-other-programming-languages/
HARVARD
Ken Okabe | Sciencx Thursday September 30, 2021 » Does the functionality of Grouping operator () in JavaScript differ from Haskell or other programming languages?., viewed ,<https://www.scien.cx/2021/09/30/does-the-functionality-of-grouping-operator-in-javascript-differ-from-haskell-or-other-programming-languages/>
VANCOUVER
Ken Okabe | Sciencx - » Does the functionality of Grouping operator () in JavaScript differ from Haskell or other programming languages?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/30/does-the-functionality-of-grouping-operator-in-javascript-differ-from-haskell-or-other-programming-languages/
CHICAGO
" » Does the functionality of Grouping operator () in JavaScript differ from Haskell or other programming languages?." Ken Okabe | Sciencx - Accessed . https://www.scien.cx/2021/09/30/does-the-functionality-of-grouping-operator-in-javascript-differ-from-haskell-or-other-programming-languages/
IEEE
" » Does the functionality of Grouping operator () in JavaScript differ from Haskell or other programming languages?." Ken Okabe | Sciencx [Online]. Available: https://www.scien.cx/2021/09/30/does-the-functionality-of-grouping-operator-in-javascript-differ-from-haskell-or-other-programming-languages/. [Accessed: ]
rf:citation
» Does the functionality of Grouping operator () in JavaScript differ from Haskell or other programming languages? | Ken Okabe | Sciencx | https://www.scien.cx/2021/09/30/does-the-functionality-of-grouping-operator-in-javascript-differ-from-haskell-or-other-programming-languages/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.