Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding: `+`(1, `*`(2, 3)) and how to better code it

Tags:

r

What is this code: `+`(1, `*`(2, 3)) supposed to be doing in R? Can it be coded in a more typical way? How?

like image 242
Joe Smith Avatar asked Feb 23 '15 02:02

Joe Smith


People also ask

How can I improve my maths in programming?

A really great resource is a book called Competitive Programming 3 the book is great overall, and most importantly the Math chapter in it. The authors have really gathered a lot of Math-related problems and if you solve just a few you will definitely improve your Math and Problem Solving skills.

Does math make you a better programmer?

Being good at math is important for certain types of programming, like designing games and inventing complex algorithms. But for many other types of programming, such as developing business or web applications, you can become a successful programmer without having to study advanced math.

What does 1 mean in programming?

1. Generally is used to advice that an error ocurred in a function.

Is coding like math?

Coding is associated with math and engineering; college-level programming courses tend to require advanced math to enroll and they tend to be taught in computer science and engineering departments.


1 Answers

If you use operators with quotes (e.g. `+` or `*`), you are actually using the standard operators with the typical function syntax.

Let's say you want to calculate 1 + 2 using that way. You could do it this way:

`+`(1, 2) ## Please call the sum operator using 1 and 2 as arguments.

So, since the expression you have posted is `+`(1, `*`(2, 3)), it's basically the sum operator, for which the arguments are 1 and the result of the product operator, for which the arguments are 2 and 3.

Eventually, a typical way to do this is 1 + (2 * 3).

like image 148
codingEnthusiast Avatar answered Oct 20 '22 11:10

codingEnthusiast