operator vs. function

Discussion in 'VHDL' started by valtih1978, Oct 2, 2012.

  1. valtih1978

    valtih1978 Guest

    What is the conceptual difference between function an operator? Do tools
    treat differently or supposed to be treated differently?
     
    valtih1978, Oct 2, 2012
    #1
    1. Advertising

  2. valtih1978

    KJ Guest

    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
     
    KJ, Oct 3, 2012
    #2
    1. Advertising

  3. valtih1978

    rickman Guest

    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
     
    rickman, Oct 3, 2012
    #3
  4. valtih1978

    Andy Guest

    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
     
    Andy, Oct 3, 2012
    #4
  5. valtih1978

    valtih1978 Guest

    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?
     
    valtih1978, Oct 4, 2012
    #5
  6. valtih1978

    Andy Guest

    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, Oct 4, 2012
    #6
  7. valtih1978

    Andy Guest

    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?
     
    Andy, Oct 8, 2012
    #7
  8. valtih1978

    valtih1978 Guest

    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
    point in your replies?
     
    valtih1978, Oct 8, 2012
    #8
  9. valtih1978

    Andy Guest

    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
     
    Andy, Oct 9, 2012
    #9
  10. valtih1978

    valtih1978 Guest

    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?
     
    valtih1978, Oct 11, 2012
    #10
  11. valtih1978

    Andy Guest

    Yep, you just want to argue...

    bye.
     
    Andy, Oct 11, 2012
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jakob Bieling

    Q: operator void* or operator bool?

    Jakob Bieling, Mar 5, 2004, in forum: C++
    Replies:
    2
    Views:
    620
    Rob Williscroft
    Mar 5, 2004
  2. =?ISO-8859-1?Q?Mattias_Br=E4ndstr=F6m?=

    operator==, member function or free function

    =?ISO-8859-1?Q?Mattias_Br=E4ndstr=F6m?=, Apr 7, 2005, in forum: C++
    Replies:
    6
    Views:
    2,343
    Donovan Rebbechi
    Apr 7, 2005
  3. Replies:
    1
    Views:
    411
  4. Replies:
    2
    Views:
    722
    Marcus Kwok
    Mar 14, 2007
  5. alex
    Replies:
    3
    Views:
    556
    Richard Cornford
    Dec 28, 2006
Loading...

Share This Page