SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
MetaJS
Knowledge-oriented programming language

Dmytro Dogadailo
October, 2013
http://metajs.coect.net
Purpose
MetaJS is knowledge-oriented programming language. MetaJS compiler can generate source code,
intentionally missed by programmer. This approach leads to loosely coupled and highly dynamic
programs. MetaJS is a dialect of Lisp and provides many of the typical Lisp features including
powerful macro system. It compiles to Javascript without runtime dependencies.

Function
Typical usage scenario: signature of a library function is changed but all arguments for new version
of the function can be found in the call context. MetaJS can adapt all calls of such function to the
new signature automatically. A programmer starts to use less nouns (local variables and function
arguments) and more verbs (function calls). MetaJS compiler finds what does the programmer mean
from semantic model of the program and surrounding context.

Motivation
Today compilers 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.

Audience
The complexity of software and user's expectations increase much faster than programmer's
productivity. MetaJS attempts to close this gap and offers to small teams and individual
programmers a tool that allows to do more for less time. Semantic-aware compiler orthogonally
combines with traditional Lisp meta-programming and provides new experience for all
programmers who value own time.

Methodology
In addition to traditional macros that transform program at read- and compile-time MetaJS uses
semantic transformations that runs after read- and compile-macros. In MetaJS functions can have
required and optional parameters. When MetaJS compiler finds a function call without a required
parameter it attempts to “resolve” it to make the valid function call.
The compiler tries to find all symbols and compound forms that can be used instead of missed
function argument. The compiler replaces missed function argument only when it finds exactly one
valid substitution. When valid substitution is not found or found more than one, compiler reports an
error that programmer need to resolve manually. The same approach is used in the version control
systems. Most of time merges of different code branches are done automatically, but if there are a
merge conflict – programmer need to resolve it manually or use different merge algorithm.
MetaJS uses two classes of semantic transformation: symbolic and entitative. During symbolic
transformations compiler uses symbols available in the lexical scope of the function call instead of
missed argument of the function. To qualify a symbol for the substitution of the missed function
argument MetaJS tries to match name and meta information of the missed argument and each
symbol available in the lexical scope of incomplete function call. Name of the argument can be
matched with meta of context symbol and vise versa forming four possible types of combinations.
Let's see an example of symbolic transformation when name of missed function argument is
matched with meta type of context symbol. On the left is MetaJS code and on the right is JavaScript
code generated from MetaJS code. Result of semantic transformation is highlighted with red color.
You can check this and next examples right inside your browser on the http://metajs.coect.net/.
(defn get-user-timeline (username)
#"$username timeline")

var getUserTimeline = (function(username) {
return ("" + username + " timeline");
});

(let* (u:username "dogada")
(get-user-timeline))

(function(u) {
return getUserTimeline(u);
})("dogada");

Required argument username of the function get-user-timeline is missed in the function call.
MetaJS uses local variable u, because it's declared with meta type username. The code
u:username defines symbol u and declares that it is related to something called username. Meta
types are not need to be defined at all. Compiler uses meta types and entities to build semantic
model of the program.
Entities are defined with (entity) macro and used solely by compiler to understand relations
between symbols. Entities are not types in statically-typed languages sense and have no
corresponding JavaScript code. Entities are main building block of semantic model of the program.
Let's see an example of an entitative transformation. Such transformations always use an explicitly
defined entity to find a valid relation between symbols available in the lexical scope of function call
and missed function argument. Entities may define simple relation like property relation, for
example (has username). Custom relation able to emit any form instead of missed argument, for
example (rel username `(. ~sym 'session ~rel)), where sym is actual symbol matched to the entity
and rel is target itself.
(entity request
"Entity of demo web request."
(has username))
(defn get-user-timeline (user-id:username)
#"$user-id timeline")

var getUserTimeline = (function(userId) {
return ("" + userId + " timeline");
});

(let* (req:request {username: "dogada"})
(get-user-timeline))

(function(req) {
return getUserTimeline(req.username);
})({username: "dogada"});

Required argument user-id of the function get-user-timeline is missed in the function call. MetaJS
uses property username of local variable req, because it's declared with meta type request and
entity request declares relation between request and username entities and user-id argument
declared with meta type username.
You can find examples of all 8 types of semantic transformations used by MetaJS in the
http://metajs.coect.net/pdf/metajs_semantic_code_transformations.pdf.

Conclusion
MetaJS is implemented in MetaJS, so even if it's still in alpha stage it's quite feature complete
already. Famous Lisp macro system allows to add more features without need to change language
itself. Anyone can try it without leaving a browser on http://metajs.coect.net/ or install as NodeJs
module.
It's easy to predict that in large programs symbols and entities with same name may have different
meaning in different source files even inside single project. When you import external libraries, you
may expect even more name conflicts. MetaJS plans to solve this problem with namespaces and
using of fully qualified names of entities inside compiler. A programmer can import and alias
entities from other modules exactly like symbols are imported between namespaces.
Next obvious area of improvement is meta types inheritance and various checks of code validity
based on semantic model of program.
The final goal is to make a compiler that can learn programmer's style at least particularly. A
programmer concentrates own efforts on domain models design and architecture of the program. A
programmer tells to MetaJS compiler what to do and teach it to understand program's entities and
relations between symbols. Computer in real-time mode analyzes semantic model of the program,
compares it with the code that programmer types and provides immediate feedback rather than
shows blinking cursor.

Más contenido relacionado

Último

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Destacado

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Destacado (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

High-level MetaJS language overview

  • 1. MetaJS Knowledge-oriented programming language Dmytro Dogadailo October, 2013 http://metajs.coect.net
  • 2. Purpose MetaJS is knowledge-oriented programming language. MetaJS compiler can generate source code, intentionally missed by programmer. This approach leads to loosely coupled and highly dynamic programs. MetaJS is a dialect of Lisp and provides many of the typical Lisp features including powerful macro system. It compiles to Javascript without runtime dependencies. Function Typical usage scenario: signature of a library function is changed but all arguments for new version of the function can be found in the call context. MetaJS can adapt all calls of such function to the new signature automatically. A programmer starts to use less nouns (local variables and function arguments) and more verbs (function calls). MetaJS compiler finds what does the programmer mean from semantic model of the program and surrounding context. Motivation Today compilers 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. Audience The complexity of software and user's expectations increase much faster than programmer's productivity. MetaJS attempts to close this gap and offers to small teams and individual programmers a tool that allows to do more for less time. Semantic-aware compiler orthogonally combines with traditional Lisp meta-programming and provides new experience for all programmers who value own time. Methodology In addition to traditional macros that transform program at read- and compile-time MetaJS uses semantic transformations that runs after read- and compile-macros. In MetaJS functions can have required and optional parameters. When MetaJS compiler finds a function call without a required parameter it attempts to “resolve” it to make the valid function call. The compiler tries to find all symbols and compound forms that can be used instead of missed function argument. The compiler replaces missed function argument only when it finds exactly one valid substitution. When valid substitution is not found or found more than one, compiler reports an error that programmer need to resolve manually. The same approach is used in the version control systems. Most of time merges of different code branches are done automatically, but if there are a merge conflict – programmer need to resolve it manually or use different merge algorithm. MetaJS uses two classes of semantic transformation: symbolic and entitative. During symbolic transformations compiler uses symbols available in the lexical scope of the function call instead of missed argument of the function. To qualify a symbol for the substitution of the missed function argument MetaJS tries to match name and meta information of the missed argument and each symbol available in the lexical scope of incomplete function call. Name of the argument can be matched with meta of context symbol and vise versa forming four possible types of combinations.
  • 3. Let's see an example of symbolic transformation when name of missed function argument is matched with meta type of context symbol. On the left is MetaJS code and on the right is JavaScript code generated from MetaJS code. Result of semantic transformation is highlighted with red color. You can check this and next examples right inside your browser on the http://metajs.coect.net/. (defn get-user-timeline (username) #"$username timeline") var getUserTimeline = (function(username) { return ("" + username + " timeline"); }); (let* (u:username "dogada") (get-user-timeline)) (function(u) { return getUserTimeline(u); })("dogada"); Required argument username of the function get-user-timeline is missed in the function call. MetaJS uses local variable u, because it's declared with meta type username. The code u:username defines symbol u and declares that it is related to something called username. Meta types are not need to be defined at all. Compiler uses meta types and entities to build semantic model of the program. Entities are defined with (entity) macro and used solely by compiler to understand relations between symbols. Entities are not types in statically-typed languages sense and have no corresponding JavaScript code. Entities are main building block of semantic model of the program. Let's see an example of an entitative transformation. Such transformations always use an explicitly defined entity to find a valid relation between symbols available in the lexical scope of function call and missed function argument. Entities may define simple relation like property relation, for example (has username). Custom relation able to emit any form instead of missed argument, for example (rel username `(. ~sym 'session ~rel)), where sym is actual symbol matched to the entity and rel is target itself. (entity request "Entity of demo web request." (has username)) (defn get-user-timeline (user-id:username) #"$user-id timeline") var getUserTimeline = (function(userId) { return ("" + userId + " timeline"); }); (let* (req:request {username: "dogada"}) (get-user-timeline)) (function(req) { return getUserTimeline(req.username); })({username: "dogada"}); Required argument user-id of the function get-user-timeline is missed in the function call. MetaJS uses property username of local variable req, because it's declared with meta type request and entity request declares relation between request and username entities and user-id argument declared with meta type username.
  • 4. You can find examples of all 8 types of semantic transformations used by MetaJS in the http://metajs.coect.net/pdf/metajs_semantic_code_transformations.pdf. Conclusion MetaJS is implemented in MetaJS, so even if it's still in alpha stage it's quite feature complete already. Famous Lisp macro system allows to add more features without need to change language itself. Anyone can try it without leaving a browser on http://metajs.coect.net/ or install as NodeJs module. It's easy to predict that in large programs symbols and entities with same name may have different meaning in different source files even inside single project. When you import external libraries, you may expect even more name conflicts. MetaJS plans to solve this problem with namespaces and using of fully qualified names of entities inside compiler. A programmer can import and alias entities from other modules exactly like symbols are imported between namespaces. Next obvious area of improvement is meta types inheritance and various checks of code validity based on semantic model of program. The final goal is to make a compiler that can learn programmer's style at least particularly. A programmer concentrates own efforts on domain models design and architecture of the program. A programmer tells to MetaJS compiler what to do and teach it to understand program's entities and relations between symbols. Computer in real-time mode analyzes semantic model of the program, compares it with the code that programmer types and provides immediate feedback rather than shows blinking cursor.