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: (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: Ada Interfaces and the Liskov Substitution Principle
    ... Because syntactically banned assignments are indistinguishable from legal ... There are many aspects on which you could parameterize String and ... This is exactly the reason why I want to keep them all in one class. ... It means that the language is unable to express assignments in its own ...
    (comp.lang.ada)
  • 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)
  • Re: Islam was spread by the sword? What about Christianity?
    ... >No wonder Jews and Muslims both feel threatened by the Christian ... Here's the Pope making an address to academics in which he specifically ... And we see threats of violence - not reason - demands that the Pope ... language) is to go along with the emotive backlash reaction that the ...
    (uk.religion.christian)