operator vs. function

V

valtih1978

What is the conceptual difference between function an operator? Do tools
treat differently or supposed to be treated differently?
 
K

KJ

What is the conceptual difference between function an operator? Do tools treat differently or supposed to be treated differently?

Tools are supposed to treat an operator and the equivalent function the same. I haven't run into any issues defining a function to use an operator but I also don't have a need to do this very often.

The biggest difference is that while you can come up with arbitrarily named functions with a whole bunch of parameters, the operators and the parameters for those operators are all pre-defined (i.e. +, -, 'and' 'or' ...)

Kevin Jennings
 
R

rickman

Tools are supposed to treat an operator and the equivalent function the same. I haven't run into any issues defining a function to use an operator but I also don't have a need to do this very often.

The biggest difference is that while you can come up with arbitrarily named functions with a whole bunch of parameters, the operators and the parameters for those operators are all pre-defined (i.e. +, -, 'and' 'or' ...)

Kevin Jennings

I didn't reply to the original post because I don't know the formal
definition of operator vs. function and the restrictions of each. But
I'm not sure that operators are limited to the ones defined in the
language. Is that correct that you can't add a new operator to VHDL,
but only define existing operators for new operands?

I've got the spec here somewhere, but I don't want to drag it out and
dig into it. This is not a fun document to review.

Rick
 
A

Andy

Additional operators cannot be defined by the user in VHDL. Existing operators can be redefined (overloaded) for additional data types, etc.

Off the top of my head, the only difference between an operator and an equivalent function are the infix vs postfix notation of the arguments.

A side effect of expression evaluation also provides a difference in the way operators and functions are executed. Operators in expressions can be executed in different orders based on rules defined in the standard. For instance, the expression: A+B+C can be evalutated in any order, but the expression: "+"(a, "+"(b, c)) must be evaluated in the order written. Note that synthesis may re-order the operations during optimization anyway.

Andy
 
V

valtih1978

Additional operators cannot be defined by the user in VHDL. Existing operators can be redefined (overloaded) for additional data types, etc.

Off the top of my head, the only difference between an operator and an equivalent function are the infix vs postfix notation of the arguments.

Why cannot we say that some build-in functions may be written in infix
notation? Lisp teachers say that there are many different notations in
mathematics, even wrapping the argument for square root, so Lisp puts
the end to this jumble and uses only one. And everything is function in
Lisp. But, do they mean that everything was a function and they have
just fixed a notation or choosing another notation changes a category of
your object? Is operator vs. function a syntactic category?

functional (Lisp) notation: f(a,b)
OOP method call notation: a.f(b)
operator (infix) notation: a f b
?

Scala guys, who merged OOP with functional paradigm, explained that
a.+(b) is essentially the same and can be written as a + b

To me, these three are the same thing. So, I do not understand why they
are called operations in one case and functions in another.
A side effect of expression evaluation also provides a difference in the way operators and functions are executed. Operators in expressions can be executed in different orders based on rules defined in the standard. For instance, the expression: A+B+C can be evalutated in any order, but the expression: "+"(a, "+"(b, c)) must be evaluated in the order written. Note that synthesis may re-order the operations during optimization anyway.

Andy

Do you compare A+B+C order against "+"(a, "+"(b, c)) intentionally to
mislead people from the A+(B+C) comparison to show that functions may
have parenthesis and thus are different? Actually, VHDL specifies the
order of operator evaluation as well as Scheme interpreter, that
normally evaluates operands in applicative order applies lazy evaluation
to "special forms". But, as everything in Lisp, they are still
functions. So, being a function or operator is not a syntactic category.
Am I right?
 
A

Andy

Operators do not have parentheses (unless invoked as a function call). Instead, expressions have parentheses, as defined by the VHDL LRM.

I was incorrect, as you pointed out; VDHL does dictate left-right association of operators of the same precedence, but with one exception: VHDL defines short circuiting of specific operators used on operands of types bit and boolean, whereby the right hand operand is not evaluated if a specific value is provided by the left hand operand (e.g. false AND anything is false, so anything is not evaluated). Therefore, strictly speaking, the expression (false and B and C) is not evaluated left to right, since the right hand operator two operands are not evaluated at all.

VHDL functions are not* short circuited (all operands are evalutated prior to calling the function).

*It is unclear what would happen if you invoked a short-circuiting operatoras a function call with the appropriate operand types to allow short-circuiting.

You asked this question in a VHDL group. I am not familiar with your definition of what constitutes the same syntactic category. To me, syntax includes how it is used/invoked, and is clearly different between operators and functions in VHDL.

Andy
 
A

Andy

What is the conceptual difference between function an operator? Do tools treat differently or supposed to be treated differently?

Is there a point to your questions or do you just want to argue?
 
V

valtih1978

Is there a point to your questions or do you just want to argue?

I have a question. By proposing a dilemma that does not consider this
option, you make a false dichotomy and is my time to ask: do you have a
point in your replies?
 
A

Andy

You asked about differences between functions and operators. I gave you some differences within the scope of VHDL (what this group is about). There are differences between them. They are not the same. I will leave it up to you to determine whether those differences meet your definition of significance.

This is a vhdl group. I doubt you will find here many experts on, or many people who care about, the esoteric qualities of programming languages in which you appear interested.

Have a good day,

Andy
 
V

valtih1978

You asked about differences between functions and operators. I gave you some differences within the scope of VHDL (what this group is about). There are differences between them. They are not the same. I will leave it up to you to determine whether those differences meet your definition of significance.

This is a vhdl group. I doubt you will find here many experts on, or many people who care about, the esoteric qualities of programming languages in which you appear interested.

Have a good day,

Andy

There are also differences between men and woman, I also gave a
difference between them. Does concentrating on VHDL excuses logic
faults? Do you mean I should eat all ... that you assent to provide just
only because it is VHDL-limited?

Why do you call those properties "esoteric" in other programming
languages? What are the "normal" properties of operator and function?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top