SlideShare a Scribd company logo
1 of 19
Download to read offline
Semantic code
transformations
in MetaJS
Dmytro V. Dogadailo
www.coect.net
October, 2013
1 What is MetaJS?
1. Write on Lisp.
2. Compile to pure JavaScript.
3. Can generate missed parts of code.
4. New approach to literate programming.
5. Try in the browser: http://metajs.coect.net/
If a tree falls in a forest
and no one is around to hear it,
does it make a sound?

http://en.wikipedia.org/wiki/If_a_tree_falls_in_a_forest
(def user)
If a symbol has name “user”
and no declared type,
does it have properties of
the entity “user”?
2 Symbolic transformations
1. Name → Name
2. Name → Meta
3. Meta

→ Name

4. Meta

→ Meta
2.1 Name → Name
In the bellow example required argument username of the function get-user-timeline is missed in the function
call. To fix this function call MetaJS uses local variable username because it's have same name as missed
function argument and it's the only possible name resolution.
On the right is JavaScript code generated from MetaJS code. Resolved name highlighted with red colour. 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* (username "dogada")
(get-user-timeline))

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

If there are several possible ways of missed symbol resolution, MetaJS will not guess and will issue a warning
to the programmer. Programmer adds missed argument manually or refactors code into smaller blocks. 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.
2.2 Name → Meta
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.
(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");
2.3 Meta → Name
Required argument user-id of the function get-user-timeline is missed in the function call. MetaJS uses local
variable username, because the function argument user-id is declared with meta type username.
(defn get-user-timeline (user-id:username)
#"$user-id timeline")

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

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

(function(username) {
return getUserTimeline(username);
})("dogada");
2.4 Meta → Meta
Required argument user-id of the function get-user-id-timeline is missed in the function call. MetaJS uses local
variable u, because it and the function argument user-id is declared with same meta type username.
(defn get-user-timeline (user-id:username)
#"$user-id timeline")

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

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

(function(u) {
return getUserTimeline(u);
})("dogada");
3 Entitative transformations
1. Name → Entity → Name
2. Meta

→ Entity → Name

3. Name → Entity → Meta
4. Meta

→ Entity → Meta
3.1 Name → Entity → Name
Required argument username of the function get-user-timeline is missed in the function call. MetaJS uses
property username of local variable request, because name of the property is identical to the name of the missed
argument and there are no other possible candidates. MetaJS assumes that local variable request has property
username, because local variable request implicitly associated with entity request.
(entity request
"Entity of demo web request."
(has username))
var getUserTimeline = (function(username) {
(defn get-user-timeline (username)
#"$username timeline")
(let* (request {username: "dogada"})
(get-user-timeline))

return ("" + username + " timeline");
});
(function(request) {
return getUserTimeline(request.username);
})({username: "dogada"});

Entities are macros and aren't translated to JavaScript code. Compiler uses entities to understand how to use
symbols (variables and function arguments) associated with entities. Such association can be implicit (when
symbol and entity have same name) and explict (for example, req:request). Entities are not classical types.
Entities explains to the compiler meaning of the words used in your code.
3.2 Meta → Entity → Name
Required argument user-id of the function get-user-timeline is missed in the function call. MetaJS uses property
username of local variable request, because entity request declares relation between request and username
entities and name of the property is identical to the meta type (entity) of the missed argument.
(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* (request {username: "dogada"})
(get-user-timeline))

(function(request) {
return getUserTimeline(request.username);
})({username: "dogada"});
3.3 Name → Entity → Meta
Required argument username 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 (entity) request and entity request
declares relation between request and username entities.
(entity request
"Entity of demo web request."
(has username))
(defn get-user-timeline (username)
#"$username timeline")

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

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

(function(req) {
return getUserTimeline(req.username);
})({username: "dogada"});
3.4 Meta → Entity → Meta
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 (entity) request and entity request declares
relation between request and username entities and user-id argument also declared as username.
(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"});
How deep
does
the rabbit hole
go?
4 Complex transformations
• For transformation of single function call can be used several symbolic and entitative transformation.
• MetaJS resolves only required function arguments that is missed in the function call.
• For each missed symbol MetaJS checks all eight possible semantic transformations.
• If there is only one valid semantic transformation, it's applied and missed symbol becomes resolved.
• If there is more than one valid semantic transformations, the compiler reports an error instead.
• MetaJS can dive any depth of the entities graph and build chains like request.session.user.username.
• At the moment lookup depth is limited to 1 (each entitative transformation can use one entity only).
• Because Law of Demeter (LoD) or principle of least knowledge.
In the example bellow 2 arguments of get-user-timeline are missed. Symbolic transformation is used for
resolving limit, entitative transformation with custom code generator – for username.
(entity request

var getUserTimeline = (function(username, limit) {

"Abstract web request with session."

return ("" + username + " timeline: " +

(has [session url])

limit + "");

(rel [username] `(. ~sym 'session ~rel)))
(defn get-user-timeline (username limit)
#"$username timeline: $limit")

});
(function(req, limit) {
return getUserTimeline(req.session.username,
limit);

(let* (req:request {session: {username: "me"}}

})({session: {username: "me"}}, 10);

limit 10)
(get-user-timeline))

See more examples: https://github.com/dogada/metajs/blob/master/test/logos.mjs
There are only two
hard things
in Computer Science:
cache invalidation
and
naming things.
Phil Karlton
5 Meaning of words
• Meaning of same name may vary in different source files.
• What does it mean user?
• Answer depends on context.
• Exactly as in real life, when word can have several meaning.
• The solution are namespaces: db.user, twitter.user, app.user, etc.
• Usage of names must be consistent only inside own namespace.
• When you import several namespaces that share same name, use aliases or fully qualified names.
• Exactly as with modules/packages of code.
• By default entities are defined in global namespace.
• And this is the only option now.
• Symbols and entities of your program in fact is a dictionary for the compiler.
• You teach compiler.
• Compiler understands you better.

More Related Content

What's hot

Building High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 FirestarterBuilding High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 FirestarterMithun T. Dhar
 
Serializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara HacopianSerializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara HacopianSmartLogic
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Madrid gug - sacando partido a las transformaciones ast de groovy
Madrid gug - sacando partido a las transformaciones ast de groovyMadrid gug - sacando partido a las transformaciones ast de groovy
Madrid gug - sacando partido a las transformaciones ast de groovyIván López Martín
 
엘라스틱서치 적합성 이해하기 20160630
엘라스틱서치 적합성 이해하기 20160630엘라스틱서치 적합성 이해하기 20160630
엘라스틱서치 적합성 이해하기 20160630Yong Joon Moon
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Protocol Oriented JSON Parsing in Swift
Protocol Oriented JSON Parsing in SwiftProtocol Oriented JSON Parsing in Swift
Protocol Oriented JSON Parsing in SwiftJason Larsen
 
G3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsG3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsIván López Martín
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationJacopo Mangiavacchi
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Abu Saleh
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightMichael Pustovit
 
Building High Performance Web Applications and Sites
Building High Performance Web Applications and SitesBuilding High Performance Web Applications and Sites
Building High Performance Web Applications and Sitesgoodfriday
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionKent Huang
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)Yurii Kotov
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperGiordano Scalzo
 

What's hot (19)

Building High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 FirestarterBuilding High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 Firestarter
 
Serializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara HacopianSerializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara Hacopian
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Madrid gug - sacando partido a las transformaciones ast de groovy
Madrid gug - sacando partido a las transformaciones ast de groovyMadrid gug - sacando partido a las transformaciones ast de groovy
Madrid gug - sacando partido a las transformaciones ast de groovy
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
엘라스틱서치 적합성 이해하기 20160630
엘라스틱서치 적합성 이해하기 20160630엘라스틱서치 적합성 이해하기 20160630
엘라스틱서치 적합성 이해하기 20160630
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Protocol Oriented JSON Parsing in Swift
Protocol Oriented JSON Parsing in SwiftProtocol Oriented JSON Parsing in Swift
Protocol Oriented JSON Parsing in Swift
 
G3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsG3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy Annotations
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 light
 
Building High Performance Web Applications and Sites
Building High Performance Web Applications and SitesBuilding High Performance Web Applications and Sites
Building High Performance Web Applications and Sites
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapper
 

Similar to Semantic code transformations in MetaJS

Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)James Titcumb
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1Jano Suchal
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaMartijn Blankestijn
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003R696
 
Cleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsDebora Gomez Bertoli
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on PlayframeworkKnoldus Inc.
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Collaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI CookbookCollaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI CookbookKen Lin
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
Architecture Components In Real Life Season 2
Architecture Components In Real Life Season 2Architecture Components In Real Life Season 2
Architecture Components In Real Life Season 2Somkiat Khitwongwattana
 
NET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptxNET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptxpetabridge
 
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKKey Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKMax Pronko
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLJohn David Duncan
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeVMware Tanzu
 

Similar to Semantic code transformations in MetaJS (20)

Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
Django Good Practices
Django Good PracticesDjango Good Practices
Django Good Practices
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Cleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture components
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
 
Django - sql alchemy - jquery
Django - sql alchemy - jqueryDjango - sql alchemy - jquery
Django - sql alchemy - jquery
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Collaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI CookbookCollaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI Cookbook
 
AkJS Meetup - ES6++
AkJS Meetup -  ES6++AkJS Meetup -  ES6++
AkJS Meetup - ES6++
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Architecture Components In Real Life Season 2
Architecture Components In Real Life Season 2Architecture Components In Real Life Season 2
Architecture Components In Real Life Season 2
 
NET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptxNET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptx
 
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKKey Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache Geode
 

Recently uploaded

Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
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
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 

Recently uploaded (20)

Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
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...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 

Semantic code transformations in MetaJS

  • 1. Semantic code transformations in MetaJS Dmytro V. Dogadailo www.coect.net October, 2013
  • 2. 1 What is MetaJS? 1. Write on Lisp. 2. Compile to pure JavaScript. 3. Can generate missed parts of code. 4. New approach to literate programming. 5. Try in the browser: http://metajs.coect.net/
  • 3. If a tree falls in a forest and no one is around to hear it, does it make a sound? http://en.wikipedia.org/wiki/If_a_tree_falls_in_a_forest
  • 4. (def user) If a symbol has name “user” and no declared type, does it have properties of the entity “user”?
  • 5. 2 Symbolic transformations 1. Name → Name 2. Name → Meta 3. Meta → Name 4. Meta → Meta
  • 6. 2.1 Name → Name In the bellow example required argument username of the function get-user-timeline is missed in the function call. To fix this function call MetaJS uses local variable username because it's have same name as missed function argument and it's the only possible name resolution. On the right is JavaScript code generated from MetaJS code. Resolved name highlighted with red colour. 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* (username "dogada") (get-user-timeline)) (function(username) { return getUserTimeline(username); })("dogada"); If there are several possible ways of missed symbol resolution, MetaJS will not guess and will issue a warning to the programmer. Programmer adds missed argument manually or refactors code into smaller blocks. 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.
  • 7. 2.2 Name → Meta 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. (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");
  • 8. 2.3 Meta → Name Required argument user-id of the function get-user-timeline is missed in the function call. MetaJS uses local variable username, because the function argument user-id is declared with meta type username. (defn get-user-timeline (user-id:username) #"$user-id timeline") var getUserTimeline = (function(userId) { return ("" + userId + " timeline"); }); (let* (username "dogada") (get-user-timeline)) (function(username) { return getUserTimeline(username); })("dogada");
  • 9. 2.4 Meta → Meta Required argument user-id of the function get-user-id-timeline is missed in the function call. MetaJS uses local variable u, because it and the function argument user-id is declared with same meta type username. (defn get-user-timeline (user-id:username) #"$user-id timeline") var getUserTimeline = (function(userId) { return ("" + userId + " timeline"); }); (let* (u:username "dogada") (get-user-timeline)) (function(u) { return getUserTimeline(u); })("dogada");
  • 10. 3 Entitative transformations 1. Name → Entity → Name 2. Meta → Entity → Name 3. Name → Entity → Meta 4. Meta → Entity → Meta
  • 11. 3.1 Name → Entity → Name Required argument username of the function get-user-timeline is missed in the function call. MetaJS uses property username of local variable request, because name of the property is identical to the name of the missed argument and there are no other possible candidates. MetaJS assumes that local variable request has property username, because local variable request implicitly associated with entity request. (entity request "Entity of demo web request." (has username)) var getUserTimeline = (function(username) { (defn get-user-timeline (username) #"$username timeline") (let* (request {username: "dogada"}) (get-user-timeline)) return ("" + username + " timeline"); }); (function(request) { return getUserTimeline(request.username); })({username: "dogada"}); Entities are macros and aren't translated to JavaScript code. Compiler uses entities to understand how to use symbols (variables and function arguments) associated with entities. Such association can be implicit (when symbol and entity have same name) and explict (for example, req:request). Entities are not classical types. Entities explains to the compiler meaning of the words used in your code.
  • 12. 3.2 Meta → Entity → Name Required argument user-id of the function get-user-timeline is missed in the function call. MetaJS uses property username of local variable request, because entity request declares relation between request and username entities and name of the property is identical to the meta type (entity) of the missed argument. (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* (request {username: "dogada"}) (get-user-timeline)) (function(request) { return getUserTimeline(request.username); })({username: "dogada"});
  • 13. 3.3 Name → Entity → Meta Required argument username 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 (entity) request and entity request declares relation between request and username entities. (entity request "Entity of demo web request." (has username)) (defn get-user-timeline (username) #"$username timeline") var getUserTimeline = (function(username) { return ("" + username + " timeline"); }); (let* (req:request {username: "dogada"}) (get-user-timeline)) (function(req) { return getUserTimeline(req.username); })({username: "dogada"});
  • 14. 3.4 Meta → Entity → Meta 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 (entity) request and entity request declares relation between request and username entities and user-id argument also declared as username. (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"});
  • 16. 4 Complex transformations • For transformation of single function call can be used several symbolic and entitative transformation. • MetaJS resolves only required function arguments that is missed in the function call. • For each missed symbol MetaJS checks all eight possible semantic transformations. • If there is only one valid semantic transformation, it's applied and missed symbol becomes resolved. • If there is more than one valid semantic transformations, the compiler reports an error instead. • MetaJS can dive any depth of the entities graph and build chains like request.session.user.username. • At the moment lookup depth is limited to 1 (each entitative transformation can use one entity only). • Because Law of Demeter (LoD) or principle of least knowledge.
  • 17. In the example bellow 2 arguments of get-user-timeline are missed. Symbolic transformation is used for resolving limit, entitative transformation with custom code generator – for username. (entity request var getUserTimeline = (function(username, limit) { "Abstract web request with session." return ("" + username + " timeline: " + (has [session url]) limit + ""); (rel [username] `(. ~sym 'session ~rel))) (defn get-user-timeline (username limit) #"$username timeline: $limit") }); (function(req, limit) { return getUserTimeline(req.session.username, limit); (let* (req:request {session: {username: "me"}} })({session: {username: "me"}}, 10); limit 10) (get-user-timeline)) See more examples: https://github.com/dogada/metajs/blob/master/test/logos.mjs
  • 18. There are only two hard things in Computer Science: cache invalidation and naming things. Phil Karlton
  • 19. 5 Meaning of words • Meaning of same name may vary in different source files. • What does it mean user? • Answer depends on context. • Exactly as in real life, when word can have several meaning. • The solution are namespaces: db.user, twitter.user, app.user, etc. • Usage of names must be consistent only inside own namespace. • When you import several namespaces that share same name, use aliases or fully qualified names. • Exactly as with modules/packages of code. • By default entities are defined in global namespace. • And this is the only option now. • Symbols and entities of your program in fact is a dictionary for the compiler. • You teach compiler. • Compiler understands you better.