Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   VHDL (http://www.velocityreviews.com/forums/f18-vhdl.html)
-   -   operator vs. function (http://www.velocityreviews.com/forums/t952926-operator-vs-function.html)

 valtih1978 10-02-2012 10:56 AM

operator vs. function

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

 KJ 10-03-2012 12:39 AM

Re: operator vs. function

On Tuesday, October 2, 2012 6:56:22 AM UTC-4, valtih1978 wrote:
> 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

 rickman 10-03-2012 12:59 AM

Re: operator vs. function

On 10/2/2012 8:39 PM, KJ wrote:
> On Tuesday, October 2, 2012 6:56:22 AM UTC-4, valtih1978 wrote:
>> 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

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

 Andy 10-03-2012 04:58 PM

Re: operator vs. function

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

 valtih1978 10-04-2012 04:38 PM

Re: operator vs. function

On 3.10.2012 19:58, Andy wrote:
> 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?

 Andy 10-04-2012 10:58 PM

Re: operator vs. function

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

 Andy 10-08-2012 05:11 PM

Re: operator vs. function

On Tuesday, October 2, 2012 5:56:22 AM UTC-5, valtih1978 wrote:
> 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?

 valtih1978 10-08-2012 06:57 PM

Re: operator vs. function

On 8.10.2012 20:11, Andy wrote:
> On Tuesday, October 2, 2012 5:56:22 AM UTC-5, valtih1978 wrote:
>> 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?
>

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

 Andy 10-09-2012 01:06 PM

Re: operator vs. function

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

 valtih1978 10-11-2012 09:34 AM

Re: operator vs. function

On 9.10.2012 16:06, Andy wrote:
>
> 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?

All times are GMT. The time now is 06:25 AM.