Re: question on alternate function declaration syntax
From: Peter Davis (pediddle_at_pediddle.net)
Date: 12/14/04
- Next message: WJ: "Tomcat 5.0.28 and MS-SQL Databases"
- Previous message: rcallan_at_seas.upenn.edu: "question on alternate function declaration syntax"
- In reply to: rcallan_at_seas.upenn.edu: "question on alternate function declaration syntax"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 13 Dec 2004 21:00:15 -0800
On 2004-12-13 20:25:48 -0800, rcallan@seas.upenn.edu 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 <pediddle@pediddle.net> "Furthermore, I believe bacon prevents hair loss!"
- Next message: WJ: "Tomcat 5.0.28 and MS-SQL Databases"
- Previous message: rcallan_at_seas.upenn.edu: "question on alternate function declaration syntax"
- In reply to: rcallan_at_seas.upenn.edu: "question on alternate function declaration syntax"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|