Today compilers of computer programs analyze only the grammar of the language and ignore the semantics of each specific program. As a result, we get the source code with high level of redundancy. With the increasing size of the program this naturally leads to difficulties in its support. Major changes in the application source code become virtually impossible without causing of new bugs and regressions.
Imagine that you can formalize some aspects of the creation of computer programs. Not code itself, but the code generation process. Then the compiler will not just parse and compile the code, but partly will understand the meaning of your code and generate new code, depending on the surrounding context.
For example, you have a function
expects two required parameters:
(defn save-thing (thing db))
Somewhere later in the program you call this function without
(save-thing), but the compiler knows that
this function requires
these parameters in the current lexical scope and generates a
complete call, for example:
(save-thing user-thing environment.db)
Elsewhere the program and, respectively, in another context compiler
for the same original string
(save-thing) will generate
another call, for example:
(save-thing backup-thing (get-secondary-db))
If you provide all the parameters of the called function, the compiler will not think instead of you. It will just checks the compliance of the expected values to the passed parameters.
Which of the available symbols in the context of the call to be used
as a function missing parameter, can be determined in several ways.
The easiest way, by the name. We can look for symbol with the name
thing in the context of the call and use it in place of
thing. Very often, parameters required
by a function are defined with the same name in the outer scope, for
(defn process-thing (thing) (log thing) (save-thing))
Example of name matching shown above is the simplest mode that is used by MetaJS. You can find more information about semantic code transformations, examples of symbolic and entitative MetaJS to JavaScipt transformations in the metajs_semantic_code_transformations.pdf. Please look also at the high-level MetaJS language overview metajs_lisp.pdf.
Similarly, you can search for matches in the meta-information associated with function parameters and symbols available in the context of call. Such matching may be based on static typing or relations between symbols defined in logoses.
The compiler will execute the instructions exactly as before, but in addition to grammar instructions, it will also execute semantic instructions defined specifically for your program.
Imagine that you're explaining how does your program work to a grandmother, who knows nothing about programming — it's an old grammar compiler. Now imagine that you're explaining the same thing to a girl with a degree in computer science — it's a new semantic compiler. But you will have to explain in both cases.
Without your feedback we're going back! Please tell us what do you think and what do you need.
Suggest an idea via UserVoice.
Join our mailing list.
Send us an email at info at dogada.org.
Top news about Coect and MetaJS also published in the twitter account @d0gada.