question on alternate function declaration syntax

Discussion in 'Java' started by rcallan@seas.upenn.edu, Dec 14, 2004.

  1. Guest

    I've always wondered why there is no language (to my knowledge) where a
    function could be declared and used like this:

    declaration:
    int[] find(int numOfRoots)RootsOf(String eqn){...}


    invocation:
    int[] solns= find(2)RootsOf("x^2");

    If no spaces are allowed, this syntax seems unambiguous, and I can't
    think of a reason why it would cause problems (besides it being
    unwanted or not useful:))

    Is there a reason why this isn't allowed? Would it even be useful?
    Thanks,
    Rob Callan
     
    , Dec 14, 2004
    #1
    1. Advertising

  2. Peter Davis Guest

    On 2004-12-13 20:25:48 -0800, said:

    > declaration:
    > int[] find(int numOfRoots)RootsOf(String eqn){...}
    >
    > invocation:
    > int[] solns= find(2)RootsOf("x^2");
    >
    > If no spaces are allowed, this syntax seems unambiguous, and I can't
    > think of a reason why it would cause problems (besides it being
    > unwanted or not useful:))


    Firstly, most people wouldn't like to have no spaces at all, and some
    language grammars are written in a way that having no spaces between
    tokens is simply impossible.

    >
    > Is there a reason why this isn't allowed? Would it even be useful?


    Functional languages do already support this style. For example, in Haskell,

    find :: Int -> (String -> [Int]) -> String -> [Int]
    find n f s = take n (f s)

    This is a function that takes three arguments: the number of items to
    find (2), another function that maps a string to a list of ints, and
    then the string to apply to the function. So to call:

    find (2) RootsOf ("x^2")

    is just passing three arguments to the "find" function. RootsOf would
    be defined however you like, and you could easily apply other functions
    to "find" other than RootsOf.

    So yes, there most certainly is a use for meta-functions like you
    describe, but their use is completely undefined in Java since methods
    are not first-class values. (The java.lang.reflect.Method class gains
    you something, but it's hardly a substitute for a real functional
    language.) Check out Haskell or OCaml if you want to learn more.

    HTH

    --
    Peter Davis <>
    "Furthermore, I believe bacon prevents hair loss!"
     
    Peter Davis, Dec 14, 2004
    #2
    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. Ovidesvideo
    Replies:
    4
    Views:
    550
    Andrey Tarasevich
    Dec 10, 2004
  2. Replies:
    4
    Views:
    1,132
    Richard Tobin
    Dec 12, 2006
  3. Bolin
    Replies:
    4
    Views:
    420
  4. Chris
    Replies:
    2
    Views:
    797
    Chris
    Mar 4, 2007
  5. Replies:
    10
    Views:
    366
    Sean O'Halpin
    Jul 17, 2006
Loading...

Share This Page