Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm thinking about creating my own pet programming language, and I have been wondering if similar language already exists.

The basic idea is that the language itself would be dynamically typed with strong metaprogramming capabilities (think Ruby). But instead of running it directly, it would be interpreted/expanded into another language, that would be statically typed, with static data structure and minimal dynamic dispatch (think C). This would then be compiled to machine code. The expansion could happen before running the program or during it's deployment, and all necessary libraries would be part of it, instead of each library being expanded separately.

Before I start working on it, I would like to know if anything like that already exists. So I can either inspire myself or drop it, because it would be useless work.

share|improve this question
    
Dynamic typing gives you flexibility, strong typing savety. The only purpose I can see so far is saving a declaration (which is not worth it in my opinion)? So what do I miss? –  Lord_Gestalter Jul 15 at 5:52
1  
@Lord_Gestalter The primary idea is to allow metaprogramming and code reflection/modification without incurring runtime performance hits. RPython is one example of something similar happening. –  Euphoric Jul 15 at 6:17
    
Simple: If the vision of your fancy new programming language is not inspiration enough in and of itself, then no answer will change that. –  Frank Jul 15 at 7:08
1  
Wouldn't compiling down to some statically-typed low level language defeat the perceived purpose of a dynamic language? Why not just make the language statically-typed at that point? E.g. Typed Racket. –  Doval Jul 15 at 12:07
1  
@SK-logic Ah, I see. Typed Racket does do some optimization based on typing, but I can see why it doesn't reach its full potential. Still, that's just a design choice from having to interoperate with untyped Racket code. I guess I'm just confused as to why anyone would go to all the trouble of whole program compilation and still make the language dynamic. You're losing all the late binding and monkeypatching that people like to use dynamic languages and yet you're not getting any of the benefits of static typing in exchange. –  Doval Jul 15 at 12:49

5 Answers 5

up vote 4 down vote accepted

You may want to look at Julia.

It's a modern, dynamically typed language with Lisp inspired meta programming. It also JIT compiles using LLVM. The standard library is written in Julia too and is compiled and cached on first use I.e. A form of install time AOT compilation. As the LLVM IR is statically typed, I think this has most of the features you were looking for although, as with many dynamic languages, REPL usage was an important consideration hence the JIT compilation.

One interesting paper I saw (section 5.2). The standard library has around 135k variables of which about 80k had a fixed, static type. The rest had to stay represented as the variant type Any.

Depending on why you're interested in dynamic to static, this may be of value when you look at how dynamic you make your language. Obviously, this has some bearing on performance although, in practice, Julia seems quite quick.

share|improve this answer
    
It seems Julia is closest to what I envisoned. But there still seems to be some fundamental differences. I will accept this answer for now. –  Euphoric Jul 16 at 5:52

Compile-time metaprogramming is a thing, if that's your doubt. The only question is whether you do it well (as in, convenient and comprehensible but still powerful enough to be useful). The compile-time code can by typed in any way you like (or not at all) but if at the end of compilation the program is fully statically typed you'd be hard-pressed to sell it as dynamic language for various social and technical reasons.

However, in this domain you need to carefully distinguish compile-time code and run-time code at all times. If the dynamic typing creeps outside of the metaprogramming and into the runtime logic, you're halfway down the road to hell that is trying to compile dynamic typing away.

RPython is usually presented as a subset of Python, but in reality it's very close to what you propose (just otherwise specialized for writing VMs). Arbitrary Python code is imported (which in Python entails running the code) and can use the full metaprogramming capabilities, then the resulting object graph (modules, class objects, function objects, constants) is analyzed, typed and compiled down to C. It's not without its share of problems though, some of which may be alleviated if the "source language" is designed for this work flow (e.g. permits type annotations).

share|improve this answer
    
I'm quite aware of all what you say. And RPython is one of my inspirations. I'm asking if language designed for this exist, not just project, that is trying to compile dynamic language. –  Euphoric Jul 15 at 6:13

Yes, there are versions of Lisp and Scheme that will compile to C (and have been for at least 25 years!) Specifically Gambit Scheme has had a C back end since the early 90's that will compile to C, from which you can build into binary code on pretty much any platform.

As scheme is a lisp it features a very strong ability to do meta programming. In fact you can in general rewrite the entire language if you want to. Lisps are in general also dynamically typed. So It could well be that scheme will do everything you want

And of course God write in Lisp: https://www.youtube.com/watch?v=5-OjTPj7K54

share|improve this answer
    
Can you say that the resulting C code has static types and data structures with minimal dynamic dispatch? –  Euphoric Jul 15 at 10:32
    
Honestly I don't know what the C looks like. Clearly it is valid C code and will compile and run. C is not all that strongly typed to begin with. –  Zachary K Jul 18 at 14:35

LLVM has a C backend, though it may or may not be in active development.

As C is more or less a platform-independent, just above assembly language language, making it the target of a compiler is not exactly the worst idea in the world, and a number of programming languages have done exactly that.

asm.js is a proof of concept. It's a low-level subset of Javascript that is specifically designed to be a compiler target.

See also http://en.wikipedia.org/wiki/Source-to-source_compiler

share|improve this answer
    
I'm asking from language design point. I don't really ask about implementation of compiler itself. Also, the C was just an example. –  Euphoric Jul 15 at 6:15
    
@Euphoric You should at least mention the transcompiler hint in case you should start your own thing –  Lord_Gestalter Jul 15 at 10:26

You can be pretty certain that nothing quite like that exists. The question is, though, how close would some other language have to be before it would convince you to give up?

Most languages are defined by a community of users. Users take up a language because of its features, capabilities and community and you can be sure no community would develop around a language that was defined simply by its implementation technology.

Many languages are created as pet projects or as academic works. If one exists you can be sure no-one here has ever heard of it, so no joy there either.

If we consider just languages that compile into a C back-end, there have been many. C++, Objective-C and Eiffel come immediately to mind, but there are many more.

If we broaden your target slightly from C back-end into statically-typed back-end then it includes the JVM and CLR. There are heaps of languages that compile to those targets, and both JVM amd CLR intermediate code can be compiled into assembly language (think Hotspot and JIT).

So depending on exactly how you delineate your question, the answer could range from none to lots and lots. Not an easy question to give a firm answer.

So finally I would observe that questions about 'name that specific product/language/technology' are not a good match for P.SE, as you would doubtless know. Perhaps you could consider that if you decide to continue with this project and are looking for more help.


Scheme is an example of a dynamically-typed language with good meta-programming which can be compiled into C and other statically typed back-ends. It has a strong community and my guess is you've already heard of it. Whether it is a close enough match to the proposal to make you abandon your project is not for me to say.

share|improve this answer
    
Wrong. As an implementation thing, Scheme48 did go that route. See also J.Pitrat's blog and several papers about meta-programming. –  Basile Starynkevitch Jul 15 at 10:39
    
@BasileStarynkevitch: There is nothing at these links to support your assertion. But see edit. –  david.pfx Jul 15 at 11:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.