## I'm from china and I'm working on a new programming language "Zero"

First appologize for my poor English.:)So,I just write more codes.

I'v found a new way of reusing codes:

Question:
there are three properties: Prop1ï¼ŒProp2ï¼ŒProp3.they all have a member named "Value".

Prop1.Value:=1; //Prop1 is defined as integer type.
Prop2.Value:=2.345; //Prop2 is defined as float type.
Prop3.Value:=â€™abcâ€™; //Prop3 is defined as string type.

How to write a function return all these propX's value?
We can write like this:

function GetPropertyValueofProp1: Integer;
begin
Resultï¼š=Prop1.Value;
end.

function GetPropertyValueofProp2: double;
begin
Result=Prop2.Value;
end.

function GetPropertyValueofProp3: string;
begin
Result=Prop3.Value;
end.

these three functions are very similar,can we write one function to deal with it?

In my new programming language "Zero",it is OK!
We can write a function like this:

function GetPropertyValue(Î¨prop): Î¨type;
begin
result:= Î¨prop.Value;
end

So strange!Can it work?How to use it?Can the compiler of the language deal with it?

Zero language has an IDE named "Amoeba".Through the syntax of the function analysis, Amoeba knows:
1 Î¨prop contains a member named "Value".
2 Î¨type is a type.
3 The type of Î¨prop.Value is same as Î¨type.

so,when we write the function in IDE:

var m1: Integer;
m1:=GetPropertyValue (____);

There is a blank we should fill.Amoeba's Code assist will give the message:
[ Prop1 ]

It means there is only one selection we can fill.Why?

Because m1 is integer type,and each side of ":=" has the same type,"Amoeba" knows it.

if the code is like this:

var m1;
m1:=GetPropertyValue (____);

Amoeba's Code assist will give the message:
[Prop1,Prop2,Prop3]

Why?because Amoeba don't know m1's type.So there are 3 selections.
The most intresting thing is,when we fill the blank with "Prop2",
What will happen?

Now m1 has a "float" type!

Let's explain the new way of reusing codes,the rule is:

If we found similar codes,write it directly,if something is
undeterminedï¼Œrepresent it with Î¨.The Amoeba IDE always knows what do you want.I know STL can do something similar,but Amoeba is more powerful and friendly for users.

## Comment viewing options

### Look into existing macro systems

I would suggest looking into macro systems.

Textual macros like in m4.

Abstract syntax macros like templates in C++, Scheme hygenic macros, Common Lisp macros.

Typed metaprogramming like in MetaOcaml.

More generally, metaprogramming and reflection

search also by yourself on the suggested words and others

It's not a macro system based on text processing.

My idea is:

If we write the codes directly,represent something with Î¨,IDE can know what we want.

What I write is what I think.

### Erm, parametric polymorphism?

I fail to see how this is anything more interesting than an incredibly simplistic application of type parameters, with a weirdo restriction of only having one possible symbol, Î¨.

I fail to see the point.

Is it just me, or is there a sudden influx of users who really don't know what LtU is for?

### ... so what you're really

[edit: ...assuming I had properly posted this as a reply to the above comment]
... so what you're really saying is "LURK MOAR."

A more charitable reply might be:

Why don't you Google for "System F", "parametric polymorphism", or "universal quantification." These are nicely covered in Pierce's book.

### translation to english, maybe

Not really a translation, but a "trot" - I think I get this guy. What he's saying makes a lot of sense. The first replies people have posted seem to me to miss his point completely.

Recipe for a programming system:

Start by whipping up some very simple statically typed language - like C or Pascal. Make a compiler for that, presumably with support for separate compilation of components.

Next, make an IDE for that. You can interactively write a module of some program in this language and the IDE will manage that as part of a library of parts. It will help you combine lots of modules to compile and link a complete program.

The IDE parses and somewhat analyzes code as you enter it. It can complete identifier names. It can detect (in this simple base langauge) static type errors.

That's all very familiar. But now:

We're going to add some limited programmability to the IDE in the form of templates. A template is written in a syntactic superset of the base language that includes a notation for abstraction over all identifiers. He uses the notation of a "PSI" prefix. Instead of declaring "int x;" you could declare "PSI-some-type x;". Or "int PSI-some-var;".

One key thing is that templates are instantiated as needed by the IDE, interactively, rather than "at compile time". The IDE will do some inference to decide which templates to expand and exactly how (with what parameters for "PSI-" terms) -- but because the process is interactive the inference algorithm can be simple-minded and just ask the user to resolve ambiguities.

So, there are really two program texts, here. The one the actual, bottom of the world compiler deals with is in some, let's say, C-like language. A real simple-minded language.

The upper language is that first language, plus "polymorphic" templates, plus user-supplied hints to disambiguate the type inference for an otherwise simple-minded type inference engine.

The IDE is critical to this idea to make it *easy* for users to know when hints are needed (and to simplify the work of providing those hints).

It's a very good idea. In a twisted way it reminds of "Subtext" - the computer is *there* so why isn't it helping more with the automatable parts of writing a program? Why are we still using dumb text editors, for the most part?

It's different from subtext in that the "PSI-"-style templating and the implied kind of "interactive type inference" is original (except that somebody, somewhere has probably tried something somewhat similar before :-)

-t

update: p.s.: it's a very subversive idea, too, in that it suggests a completely different approach to problem that ever-more-sophisticated type-theory-inspired systems are coming up with. A much simpler and yet plausibly more powerful approach.

### The distinction you make

The distinction you make between automated processing by the IDE and automated processing by the compiler is ultimately one of staged compilation of source-code. It isn't as though you can get by without de-facto standardizing the IDE pre-processing if you desire any degree of backwards compatibility. Upon doing so, all you have is staged compilation... it doesn't matter whether it is occurring in the IDE or the compiler.

The idea of interactive programmer-guided compilation and optimization is a technique I've been interested in for a long time... though I'd prefer it not occur at the level of syntax. Combined with databases that remember suggestions and success and failure at optimization techniques, expert systems that can process data into heuristic rules for effectively compiling a project can support or take over over for the programmer in the guided compilation. This would allow one to squeeze the same optimizations and compilation-proofs etc. into much less time (making feasible proof-carrying assembly and intermediate representations) after just a few edit-compile-test cycles, and one could dedicate that extra time to better optimizations.

Anyhow, what I'm saying is that 'interactive compilation' is a decent idea for languages, especially those with higher-level specifications and compilers written in logic programming languages, but it need not be the job of the IDE except insofar as the IDE would need to represent the interaction to the programmer (e.g. graphical views of search-spaces, topographical display of minimal and maximal places searched thus far, representation of past success or failure in prior compilations that might not be fully valid after changes to the code but are still useful, etc.).

### very pleasure!

I'v studied on this subject for ten years.but now i think i really find a way to my target.
At first,my idea is how to reuse codes.I never think OOP find the right way.A Class or a object is not bricks of reusing.The relationship "is-a" is not realy "is-a" concept in human's mind.
... ...
Sorry,My english is too poor to express my whole idea especially those delicate concepts.

### it's not only a theory about "type".

We can write anything like this:

****Î¨1*****Î¨2**Î¨3*****

Î¨1,Î¨2 and Î¨3 maybe everything,a type,a variableï¼Œan object,an operator... ...

if you can get my idea,you will find that all abstractions can be written like that.

### another example of Zero language

I said that Î¨1,Î¨2 and Î¨3 maybe everything,a type,a variableï¼Œan object,an operator... ...

function get(Î¨3: array of Î¨2;Î¨5: Operator): Î¨4;
var i:Integer;
begin
Result:=Î¨3[0];
for i:=1 to length(Î¨3)-1 do begin
Result:=Result Î¨5 Î¨3[i];
end;
end;

we can use the function do:
var m1: array[0..Î¨1-1] of Integer;
var total: Integer;
total:=get(m1,+); //total=m1[0]+m1[1]+...+m1[Î¨1-1]
total:=get(m1,*); //total=m1[0]*m1[1]*...*m1[Î¨1-1]

var m1: array[0..Î¨1-1] of float;
var total: float;
total:=get(m1,+); //total=m1[0]+m1[1]+...+m1[Î¨1-1]
total:=get(m1,*); //total=m1[0]*m1[1]*...*m1[Î¨1-1]