[OT] What should be in a programming language?

Jason House jason.james.house at gmail.com
Mon Oct 26 11:30:02 PDT 2009


Yigal Chripun Wrote:

> Jason House Wrote:
> 
> > How is that different from a normal function definition that includes some compile-time calls? I agree that compile-time code should look and feel like normal code. It seems you use macro to switch to compile-time by default and runtime when explcitly marked? Having both defaults (compile time or run time) makes sense.
> > 
> 
> The way it's implemented in Nemerle, a macro is actually a class. 
> the above is not how it works. 
> the code inside a macro is regular run-time code. it is compiled into a lib and loaded by the compiler as a plugin. 
> the code is run at run-time but run-time here means run-time of the compiler since it's a plugin of the compiler. 
> in nemerle (like in FP) the last value in a function is what the function returns. so that macro *returns* an AST representation of what's inside. 
> you can use this operator to de/compose AST. 


Your examples in Nemerle or D-ish looked like they are returning strings. I'm still not seeing the magic of AST macros.


 
> > 
 
> > > OK, here's an example:
> > > 
> > > class Foo {
> > > int a;
> > > void bar();
> > > }
> > > 
> > > auto obj = new Foo;
> > > obj.a = 42; // obj contains a
> > > obj.bar();  // calls 'Foo.vtbl.bar
> > > 
> > > remember that 'Foo is the classinfo singelton for Foo
> > > 
> > > class Foo {
> > > static a;
> > > static void bar();
> > > }
> > > 
> > > Foo.a = 42; // 'Foo contains a
> > > Foo.bar(); // calls ''Foo.vtbl.bar
> > > 
> > > ''Foo is the classinfo singelton for 'Foo
> > > 
> > > we get the following chain ("-->" means instance of)
> > > obj --> Foo --> MetaFoo --> MetaClass --> Class
> > > 
> > > compared with C++/D/Java/etc:
> > > obj --> Foo --> Class
> > 
> > Ok. That makes sense. It can be simplified when statics are removed.
> > 
> 
> I don't understand this. How removal of statics simplifies this?

As I understood it 'Foo contains the static data and class info for Foo, and ''Foo contains class info for 'Foo. Without statics, ''Foo is unnecessary. I'm sure I've misinterpreted what you're saying ;)


> I think that having class shared functions/data should still be possible but implemented as above instead of static memory as in c++/D. 
> class Foo {
> static int value;
> }
> 
> this still works as in D but value is a member of the singleton object that represents Foo at runtime instead of stored in static memory.

The singleton object should be in static memory... I don't really see the distinction since the finer storage details don't affect the programmer.
 
> 
> those singletons need to be concurrency friendly unlike the static memory design that is definitely is not. 
> 
> btw, in dynamic languages like smalltalk/ruby those meta classes are mutable so you can for example add methods at run-time. I don't know if this should be allowed in a compiled language. 




More information about the Digitalmars-d mailing list