SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
•


•


•
•   template<int n> struct Factorial
    {
      enum {
        RET = n *
              Factorial<n-1>::RET
•     }
    };
    template<> struct Factorial<0>
    {
      enum {
•       RET = 1
      }
    };
    ⋮
    int n = Factorial<5>::RET; // 120
•       •

•
    –       –
    –
        •
    –

•
    –
•       •
    –       –
•
    –   •
    –   •
    –       –
    –   •
•       •
    –
    –
•                                     •
    –   #define sqr(x) ((x)*(x))
        int n = sqr(2);
        // emits int n = ((2)*(2));       –
•                                             #define
                                      •
    –
                pow(x,n)
                                      •
•

                                      •

                                      •
class                         • MyMacro
MyMacro(AbstractAstMacro)
{
  override def Expand         • MyMacro 1 2
  (macro as MacroStatement)
  {
    // macro.Argument[n]      • MyMacro:
    // macro.Body                 print “test”
    yield/return
  }
}
class
MyMacro(AbstractAstMacro)
{
                              macro MyMacro (n as int):
  override def Expand
  (macro as MacroStatement)     // MyMacro.Argument[n]
  {                             // MyMacro.Body
    // macro.Argument[0]        yield/return
    // macro.Body
    yield/return
  }
}
k


•            •

    –
             •
•
    –    →
    –   →
             •
•
    –
    –
    –
•
macro dateNow:
  now = DateTime.Now
  return [|
     print $(now.ToLocalTime().ToString())
  |]
macro RepeatCStyle(c as int):       macro RepeatInline(c as int):
  return [|                           body = RepeatInline.Body
    for i in range($c):               yieldAll body for i in range(c)
      $(RepeatCStyle.Body)
  |]

                           RepeatXxx 3:
                             print “Go”

int ___temp14 = 0;                   Console.WriteLine("Go");
while (___temp14 < 3)                Console.WriteLine("Go");
{                                    Console.WriteLine("Go");
  int i = ___temp14;
  ___temp14++;
  Console.WriteLine("Go");
}
•
•
•
•
    –
[meta] def assert(condition as Expression):
  return [|
     if not $condition:
       raise AssertionFailedException( 
         $(condition.ToCodeString()))
  |]
•       •

        •

•
            –

        •
    –
public class 
TimestampAttribute(AbstractAstAttribute):
  public override def Apply(node as Node):
    c = node as ClassDefinition
    now = DateTime.Now
    m = [|
      public def GetTimestamp():
        return $(now.ToLocalTime().ToString())
    |]
    c.Members.Add(m) // a new member added to
                     // an existing class
•

•
    – [Timestamp]
      public class C:
        public def constructor():
          pass
•
    – c = C()
      print c.GetTimestamp()
j


•           •
    –           –
                    •       
    –
                –
•               –
            •
•                       
                –

                –
            •
•
    –
    –
•
    –
    –
    –
•
    –
Metaprogramming

Mais conteúdo relacionado

Mais procurados

A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
Paul Lam
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
vidyamittal
 

Mais procurados (20)

C++ ammar .s.q
C++  ammar .s.qC++  ammar .s.q
C++ ammar .s.q
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
High performance GPU computing with Ruby RubyConf 2017
High performance GPU computing with Ruby  RubyConf 2017High performance GPU computing with Ruby  RubyConf 2017
High performance GPU computing with Ruby RubyConf 2017
 
NumPy Refresher
NumPy RefresherNumPy Refresher
NumPy Refresher
 
Why learn new programming languages
Why learn new programming languagesWhy learn new programming languages
Why learn new programming languages
 
Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.
 
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
R-ggplot2 package Examples
R-ggplot2 package ExamplesR-ggplot2 package Examples
R-ggplot2 package Examples
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
 
Deep learning study 3
Deep learning study 3Deep learning study 3
Deep learning study 3
 
Coscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usageCoscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usage
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
 
AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)
 
Enter The Matrix
Enter The MatrixEnter The Matrix
Enter The Matrix
 

Destaque

OpenJDK-Zulu talk at JEEConf'14
OpenJDK-Zulu talk at JEEConf'14OpenJDK-Zulu talk at JEEConf'14
OpenJDK-Zulu talk at JEEConf'14
Ivan Krylov
 
AddConf. Дмитрий Сошников - Будущее ECMAScript
AddConf. Дмитрий Сошников  - Будущее ECMAScriptAddConf. Дмитрий Сошников  - Будущее ECMAScript
AddConf. Дмитрий Сошников - Будущее ECMAScript
Dmitry Soshnikov
 
Autosprite presentation at London Web Summit 2013
Autosprite presentation at London Web Summit 2013Autosprite presentation at London Web Summit 2013
Autosprite presentation at London Web Summit 2013
Autosprite
 
iterators-must-go
iterators-must-goiterators-must-go
iterators-must-go
Hiroshi Ono
 
RubyConf 2010 Keynote by Matz
RubyConf 2010 Keynote by MatzRubyConf 2010 Keynote by Matz
RubyConf 2010 Keynote by Matz
yukihiro_matz
 
В погоне за производительностью
В погоне за производительностьюВ погоне за производительностью
В погоне за производительностью
FDConf
 
Phd2013 lyamin Высокий пакетрейт на x86-64, берем планку 14.88Mpps
Phd2013 lyamin  Высокий пакетрейт на  x86-64, берем планку 14.88MppsPhd2013 lyamin  Высокий пакетрейт на  x86-64, берем планку 14.88Mpps
Phd2013 lyamin Высокий пакетрейт на x86-64, берем планку 14.88Mpps
Alexander Lyamin
 
Twisted Framework - сетевые приложения в Python
Twisted Framework - сетевые приложения в PythonTwisted Framework - сетевые приложения в Python
Twisted Framework - сетевые приложения в Python
Andrey Smirnov
 

Destaque (20)

OpenJDK-Zulu talk at JEEConf'14
OpenJDK-Zulu talk at JEEConf'14OpenJDK-Zulu talk at JEEConf'14
OpenJDK-Zulu talk at JEEConf'14
 
AddConf. Дмитрий Сошников - Будущее ECMAScript
AddConf. Дмитрий Сошников  - Будущее ECMAScriptAddConf. Дмитрий Сошников  - Будущее ECMAScript
AddConf. Дмитрий Сошников - Будущее ECMAScript
 
Autosprite presentation at London Web Summit 2013
Autosprite presentation at London Web Summit 2013Autosprite presentation at London Web Summit 2013
Autosprite presentation at London Web Summit 2013
 
Божена Пеннер (Mail.ru Group) Как за год набрать 8 тысяч плюсов
Божена Пеннер (Mail.ru Group) Как за год набрать 8 тысяч плюсовБожена Пеннер (Mail.ru Group) Как за год набрать 8 тысяч плюсов
Божена Пеннер (Mail.ru Group) Как за год набрать 8 тысяч плюсов
 
Любовь Соболева, Виктория Гонгина (Tech Media). Хабр и Geektimes.ru: полное п...
Любовь Соболева, Виктория Гонгина (Tech Media). Хабр и Geektimes.ru: полное п...Любовь Соболева, Виктория Гонгина (Tech Media). Хабр и Geektimes.ru: полное п...
Любовь Соболева, Виктория Гонгина (Tech Media). Хабр и Geektimes.ru: полное п...
 
Fake Flash Drives from TopKeen
Fake Flash Drives from TopKeenFake Flash Drives from TopKeen
Fake Flash Drives from TopKeen
 
Востребованность мер государственной поддержки инновационных предприятий в ро...
Востребованность мер государственной поддержки инновационных предприятий в ро...Востребованность мер государственной поддержки инновационных предприятий в ро...
Востребованность мер государственной поддержки инновационных предприятий в ро...
 
GC @ jmaghreb2014
GC @ jmaghreb2014GC @ jmaghreb2014
GC @ jmaghreb2014
 
Правильная работа с часовыми поясами в Rails приложении — DevConf 2015
Правильная работа с часовыми поясами в Rails приложении — DevConf 2015Правильная работа с часовыми поясами в Rails приложении — DevConf 2015
Правильная работа с часовыми поясами в Rails приложении — DevConf 2015
 
iterators-must-go
iterators-must-goiterators-must-go
iterators-must-go
 
Светлана Лузгина (ABBYY). Как прокачать корпоративную редакцию
Светлана Лузгина (ABBYY). Как прокачать корпоративную редакциюСветлана Лузгина (ABBYY). Как прокачать корпоративную редакцию
Светлана Лузгина (ABBYY). Как прокачать корпоративную редакцию
 
DIY Java Profiler
DIY Java ProfilerDIY Java Profiler
DIY Java Profiler
 
RubyConf 2010 Keynote by Matz
RubyConf 2010 Keynote by MatzRubyConf 2010 Keynote by Matz
RubyConf 2010 Keynote by Matz
 
Данил Декханов (Fu2RE). Мотивация писать на Хабр: снаружи и изнутри
Данил Декханов (Fu2RE). Мотивация писать на Хабр: снаружи и изнутриДанил Декханов (Fu2RE). Мотивация писать на Хабр: снаружи и изнутри
Данил Декханов (Fu2RE). Мотивация писать на Хабр: снаружи и изнутри
 
В погоне за производительностью
В погоне за производительностьюВ погоне за производительностью
В погоне за производительностью
 
Продвижение iOS приложений
Продвижение iOS приложенийПродвижение iOS приложений
Продвижение iOS приложений
 
Gepetto’s Army: Creating International Incidents with Twitter Bots
Gepetto’s Army: Creating International Incidents with Twitter BotsGepetto’s Army: Creating International Incidents with Twitter Bots
Gepetto’s Army: Creating International Incidents with Twitter Bots
 
Phd2013 lyamin Высокий пакетрейт на x86-64, берем планку 14.88Mpps
Phd2013 lyamin  Высокий пакетрейт на  x86-64, берем планку 14.88MppsPhd2013 lyamin  Высокий пакетрейт на  x86-64, берем планку 14.88Mpps
Phd2013 lyamin Высокий пакетрейт на x86-64, берем планку 14.88Mpps
 
Fork Yeah! The Rise and Development of illumos
Fork Yeah! The Rise and Development of illumosFork Yeah! The Rise and Development of illumos
Fork Yeah! The Rise and Development of illumos
 
Twisted Framework - сетевые приложения в Python
Twisted Framework - сетевые приложения в PythonTwisted Framework - сетевые приложения в Python
Twisted Framework - сетевые приложения в Python
 

Semelhante a Metaprogramming

スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
Taro Matsuzawa
 
Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C Survives
S Akai
 
SMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning ApproachSMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning Approach
Reza Rahimi
 
Framework for Extensible, Asynchronous Task Scheduling (FEATS) in Fortran
Framework for Extensible, Asynchronous Task Scheduling (FEATS) in FortranFramework for Extensible, Asynchronous Task Scheduling (FEATS) in Fortran
Framework for Extensible, Asynchronous Task Scheduling (FEATS) in Fortran
Patrick Diehl
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
 

Semelhante a Metaprogramming (20)

C++ process new
C++ process newC++ process new
C++ process new
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
 
Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C Survives
 
SMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning ApproachSMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning Approach
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojure
 
Framework for Extensible, Asynchronous Task Scheduling (FEATS) in Fortran
Framework for Extensible, Asynchronous Task Scheduling (FEATS) in FortranFramework for Extensible, Asynchronous Task Scheduling (FEATS) in Fortran
Framework for Extensible, Asynchronous Task Scheduling (FEATS) in Fortran
 
Java & OOP Core Concept
Java & OOP Core ConceptJava & OOP Core Concept
Java & OOP Core Concept
 
Getting started cpp full
Getting started cpp   fullGetting started cpp   full
Getting started cpp full
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012
 
Dart
DartDart
Dart
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
L4 functions
L4 functionsL4 functions
L4 functions
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
 
The Challenge of Bringing FEZ to PlayStation Platforms
The Challenge of Bringing FEZ to PlayStation PlatformsThe Challenge of Bringing FEZ to PlayStation Platforms
The Challenge of Bringing FEZ to PlayStation Platforms
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
 
Pythonで機械学習入門以前
Pythonで機械学習入門以前Pythonで機械学習入門以前
Pythonで機械学習入門以前
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 

Mais de Dmitri Nesteruk

Converting Managed Languages to C++
Converting Managed Languages to C++Converting Managed Languages to C++
Converting Managed Languages to C++
Dmitri Nesteruk
 
Dynamics CRM Data Integration
Dynamics CRM Data IntegrationDynamics CRM Data Integration
Dynamics CRM Data Integration
Dmitri Nesteruk
 
ReSharper Architecture & Extensions
ReSharper Architecture & ExtensionsReSharper Architecture & Extensions
ReSharper Architecture & Extensions
Dmitri Nesteruk
 

Mais de Dmitri Nesteruk (20)

Good Ideas in Programming Languages
Good Ideas in Programming LanguagesGood Ideas in Programming Languages
Good Ideas in Programming Languages
 
Design Pattern Observations
Design Pattern ObservationsDesign Pattern Observations
Design Pattern Observations
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NET
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
 
C# Tricks
C# TricksC# Tricks
C# Tricks
 
Introduction to Programming Bots
Introduction to Programming BotsIntroduction to Programming Bots
Introduction to Programming Bots
 
Converting Managed Languages to C++
Converting Managed Languages to C++Converting Managed Languages to C++
Converting Managed Languages to C++
 
Monte Carlo C++
Monte Carlo C++Monte Carlo C++
Monte Carlo C++
 
Tpl DataFlow
Tpl DataFlowTpl DataFlow
Tpl DataFlow
 
YouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue TrackerYouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue Tracker
 
Проект X2C
Проект X2CПроект X2C
Проект X2C
 
Domain Transformations
Domain TransformationsDomain Transformations
Domain Transformations
 
Victor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UIVictor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UI
 
Developer Efficiency
Developer EfficiencyDeveloper Efficiency
Developer Efficiency
 
Distributed Development
Distributed DevelopmentDistributed Development
Distributed Development
 
Dynamics CRM Data Integration
Dynamics CRM Data IntegrationDynamics CRM Data Integration
Dynamics CRM Data Integration
 
ReSharper Presentation for NUGs
ReSharper Presentation for NUGsReSharper Presentation for NUGs
ReSharper Presentation for NUGs
 
ReSharper Architecture & Extensions
ReSharper Architecture & ExtensionsReSharper Architecture & Extensions
ReSharper Architecture & Extensions
 
Web mining
Web miningWeb mining
Web mining
 
Data mapping tutorial
Data mapping tutorialData mapping tutorial
Data mapping tutorial
 

Último

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
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
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...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Metaprogramming

  • 1.
  • 3.
  • 4. template<int n> struct Factorial { enum { RET = n * Factorial<n-1>::RET • } }; template<> struct Factorial<0> { enum { • RET = 1 } }; ⋮ int n = Factorial<5>::RET; // 120
  • 5. • • – – – • – • –
  • 6. • – – • – • – • – – – • • • – –
  • 7. • – #define sqr(x) ((x)*(x)) int n = sqr(2); // emits int n = ((2)*(2)); – • #define • – pow(x,n) • • • •
  • 8.
  • 9. class • MyMacro MyMacro(AbstractAstMacro) { override def Expand • MyMacro 1 2 (macro as MacroStatement) { // macro.Argument[n] • MyMacro: // macro.Body print “test” yield/return } }
  • 10. class MyMacro(AbstractAstMacro) { macro MyMacro (n as int): override def Expand (macro as MacroStatement) // MyMacro.Argument[n] { // MyMacro.Body // macro.Argument[0] yield/return // macro.Body yield/return } }
  • 11. k • • – • • – → – → • • – – – •
  • 12.
  • 13. macro dateNow: now = DateTime.Now return [| print $(now.ToLocalTime().ToString()) |]
  • 14. macro RepeatCStyle(c as int): macro RepeatInline(c as int): return [| body = RepeatInline.Body for i in range($c): yieldAll body for i in range(c) $(RepeatCStyle.Body) |] RepeatXxx 3: print “Go” int ___temp14 = 0; Console.WriteLine("Go"); while (___temp14 < 3) Console.WriteLine("Go"); { Console.WriteLine("Go"); int i = ___temp14; ___temp14++; Console.WriteLine("Go"); }
  • 16. [meta] def assert(condition as Expression): return [| if not $condition: raise AssertionFailedException(  $(condition.ToCodeString())) |]
  • 17. • • • – • –
  • 18. public class  TimestampAttribute(AbstractAstAttribute): public override def Apply(node as Node): c = node as ClassDefinition now = DateTime.Now m = [| public def GetTimestamp(): return $(now.ToLocalTime().ToString()) |] c.Members.Add(m) // a new member added to // an existing class
  • 19. • • – [Timestamp] public class C: public def constructor(): pass • – c = C() print c.GetTimestamp()
  • 20.
  • 21. j • • – – •  – – • – • •  – – •
  • 22. – – • – – – • –