Re: question on alternate function declaration syntax

From: Peter Davis (pediddle_at_pediddle.net)
Date: 12/14/04


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!"


Relevant Pages

  • Re: Controlling Javascript from server side
    ... but five different language implementations here. ... 'true' means that the request must be handled asynchronously. ... There is exactly *no* reason for such a thing here. ... | percent-endoded string). ...
    (comp.lang.javascript)
  • Re: Fix quilt merge error in acpi-cpufreq.c
    ... it is a pure cleanup. ... Language is not a "fit to one string" thing. ... YOU HAVE NEVER GIVEN A COHERENT REASON FOR FINDING IT USEFUL! ...
    (Linux-Kernel)
  • Re: (simple) question - function calls without ()
    ... reason for it. ... However setTimeout is being passed ... a string in this case and knows nothing about the ... not part of the actual language and so not in ECMAScript ...
    (comp.lang.javascript)
  • Re: Is C++ the "General Motors" of Programming Languages?
    ... On 22 Nov 2008 16:57:01 GMT, Bill Gunshannon wrote: ... I also see no reason why something like that needs to be a part of ... You can basicly define a string any way you want. ... I don't care if they come from the language, ...
    (comp.lang.misc)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... overall familiarity with the tested platform, language or topic. ... The decrement happens BEFORE the assignment (simple ... Question 16 is trivial if you discount the possibility that the break ... Nor is there any reason why you couldn't use structs to implement a ...
    (comp.programming)