SlideShare a Scribd company logo
 
Ruby Macros
 
 
“ print 'hello'” :(print 'hello')‏ proc{ print 'hello' }
RedParse.new(“print 'hello'”).parse :(print 'hello')‏ RedParse::CallNode[nil, "print", [RedParse::StringNode["hello",  {:@line=>1, :@close=>"'", :@open=>"'", :@char=>"amp;quot;"}]], nil, nil,  {:@line=>1, :@not_real_parens=>true, :@offset=>0, :@lvalue=>nil}]
str=:(“hello”)‏ :(print ^str)‏
macro simple(a,b)  :(^a+^b)  end def simple_user p simple(1,2)‏ end
if $Debug macro assert(cond)‏ if RedParse::OpNode===cond and /[=!]=/===cond.op left,op,right=*cond :(fail 'expected '+^left.unparse({})+"(==#{^left}) to be "+ ^op+" "+^right.unparse({})+"(==#{^right})" unless ^cond)  else :(fail "expected #{:(^^cond)}, but was not true" unless ^cond)‏ end end else macro assert(cond)‏ end end
def test_assert a=1  b=2 assert a  #ok assert a!=b  #ok assert(a==b) #oops, fails. msg="expected a(==1) to be == b(==2)" assert(nil) #oops, fails. msg="expected nil, but was not true" #ok, that message didn't make a lot of sense... end
Syntax trees are represented by trees of nested Nodes. All  Nodes descend from Array, and their subnodes can be  addressed by numeric index, just like normal Arrays.  However, many subnodes want to have names as well,  thus most (but not all) array slots within the various Node  classes have names. The general rule is that Node slots  may contain a Node, a VarNameToken, a plain Array, a  String, or nil. However, many cases are more specific  than that.
VarNameToken<RubyLexer::Token  #represents variables and constants (ident: String)‏ Node<Array  #abstract ancestor of all nodes (except VarNameToken)‏ +RescueNode  #a rescue clause in a def of begin statement |  (exceptions: Array[Value*], varname: VarNameToken|nil, action: Value)‏ +WhenNode  #a when clause in a case statement |  (when: Value|Array[Value+]  then: Value|nil )‏ +ElsifNode  #an elsif clause in an if statement |  (elsif: Value, then: Value|nil)‏ +ValueNode  #abstract, a node which has a value (an expression)‏ |+ListOpNode  #abstract, ancestor for nodes which are lists of |||  #things separated by some op ||+SequenceNode  #a sequence of statements |||  (Array[Value*])‏ ||+ConstantNode  #a constant expression of the form A::B::C or the like ||  #first expression can be anything ||  (Array[String|Value|nil,String+])‏ |+RawOpNode  #ancestor of all operators (but not . :: ; , ?..:)‏ |||  (left: Value, op: String, right: Value)‏ ||+OpNode  #ancestor of some operators |||+RangeNode  #a range literal node |||+KeywordOpNode #abstract, ancestor of keyword operators ||||+LogicalNode  #and or && || expressions ||||+WhileOpNode  #while as an operator ||||+UntilOpNode  #until as an operator ||||+IfOpNode  #if as an operator ||||+UnlessOpNode #unless as an operator |||+NotEqualNode  #!= expressions
|||+MatchNode  #=~ expressions |||+NotMatchNode  #!~ expressions |+LiteralNode  #literal symbols, integers ||  (val: Numeric|Symbol|StringNode)‏ |+StringNode  #literal strings |||  (Array[(String|Value)+])‏ ||+HereDocNode  #here documents |+StringCatNode  #adjacent strings are catenated (&quot;foo&quot; &quot;bar&quot; == &quot;foobar&quot;)‏ ||  (Array[StringNode+])‏ |+NopNode  #an expression with no tokens at all in it ||  (no attributes)‏ |+VarLikeNode  #nil,false,true,__FILE__,__LINE__,self ||  (name: String)‏ |+UnOpNode  #unary operators ||  (op: String, val: Value)‏ ||+UnaryStarNode  #unary star (splat)‏ |||+DanglingStarNode  #unary star with no argument |||||  (no attributes)‏ ||||+DanglingCommaNode  #comma with no rhs ||  (no attributes)‏ |+ParenedNode  #ugly, parenthesized expressions and begin..end ||  (body: Value)  -OR-  (parentheses)‏ ||  (body: Value|nil, rescues: Array[RescueNode*], ||  else: Value|nil, ensure: Value|nil)  (begin...end and rescue as operator)‏ |+AssignNode  #assignment (including eg +=)‏ ||  (left:AssigneeList|LValue, op:String ,right:Array[Value*]|Value)‏
|+AssigneeList  #abstract, comma-delimited list of assignables |||  (Array[LValue*])‏ ||+NestedAssign  #nested lhs, in parentheses ||+MultiAssign  #regular top-level lhs ||+BlockParams  #block formal parameter list |+CallSiteNode  #abstract, method calls |||  (receiver: Value|nil, name: String,  |||  params: nil|Array[Value+,UnaryStarNode?,UnAmpNode?], |||  block_params: BlockParams, block: Value)‏ ||+CallNode  #normal method calls ||+KWCallNode  #keywords that look (more or less) like methods  ||  #(BEGIN END yield return break continue next)‏ |+ArrayLiteralNode #[..] ||  (Array[Value*])‏ |+IfNode  #if..end and unless..end ||  (if: Value, then: Value|nil, elsifs: Array[ElsifNode+]|Nil, else: Value|nil)‏ |+LoopNode  #while..end and until..end ||  (while: Value, do: Value:nil)‏ |+CaseNode  #case..end ||  (case: Value|nil, whens: Array[WhenNode*], else: Value|nil)‏ |+ForNode  #for..end ||  (for: LValue, in: Value, do: Value|nil)‏ |+HashLiteralNode #{..} ||  (Array[Value*]) (size must be even)‏ |+TernaryNode  # ? .. : ||  (if: Value, then: Value, else: Value)‏
|+MethodNode  #def..end ||  (receiver:Value|nil, name:String, ||  params:Array[VarNameToken*,AssignNode*,UnaryStarNode?,UnAmpNode?]|nil, ||  body: Value|nil, rescues: Array[RescueNode+]|nil, else: Value|nil, ensure: Value|nil)‏ |+AliasNode  #alias foo bar ||  (to: String|VarNameToken|StringNode, from: String|VarNameToken|StringNode)‏ |+UndefNode  #undef foo ||  (Array[String|StringNode+])‏ |+NamespaceNode #abstract ||+ModuleNode  #module..end |||  (name: VarNameToken|ConstantNode, body: Value|nil)‏ ||+ClassNode  #class..end |||  (name: VarNameToken|ConstantNode, parent: Value|nil, body: Value|nil)‏ ||+MetaClassNode  #class<<x..end ||  (val: Value, body: Value|nil)‏ |+BracketsGetNode #a[b] |  (receiver: Value, params: Array[Value+,UnaryStarNode?]|nil)‏ | ErrorNode  #mixed in to nodes with a syntax error +MisparsedNode  #mismatched braces or begin..end or the like
Drawbacks: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Practical scalaz
Practical scalazPractical scalaz
Practical scalaz
oxbow_lakes
 
The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184
Mahmoud Samir Fayed
 
week-7x
week-7xweek-7x
Scalaz
ScalazScalaz
Scalaz
mpilquist
 
ProgrammingwithGOLang
ProgrammingwithGOLangProgrammingwithGOLang
ProgrammingwithGOLang
Shishir Dwivedi
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189
Mahmoud Samir Fayed
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
Werner Hofstra
 
Ruby Basics by Rafiq
Ruby Basics by RafiqRuby Basics by Rafiq
Ruby Basics by Rafiq
Rafiqdeen
 
The Ring programming language version 1.5.4 book - Part 24 of 185
The Ring programming language version 1.5.4 book - Part 24 of 185The Ring programming language version 1.5.4 book - Part 24 of 185
The Ring programming language version 1.5.4 book - Part 24 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 15 of 88
The Ring programming language version 1.3 book - Part 15 of 88The Ring programming language version 1.3 book - Part 15 of 88
The Ring programming language version 1.3 book - Part 15 of 88
Mahmoud Samir Fayed
 
LeetCode April Coding Challenge
LeetCode April Coding ChallengeLeetCode April Coding Challenge
LeetCode April Coding Challenge
Sunil Yadav
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Sunil Yadav
 
Oscon 2010 Specs talk
Oscon 2010 Specs talkOscon 2010 Specs talk
Oscon 2010 Specs talk
Eric Torreborre
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30
Mahmoud Samir Fayed
 
Swift rocks! #1
Swift rocks! #1Swift rocks! #1
Swift rocks! #1
Hackraft
 
The Ring programming language version 1.7 book - Part 27 of 196
The Ring programming language version 1.7 book - Part 27 of 196The Ring programming language version 1.7 book - Part 27 of 196
The Ring programming language version 1.7 book - Part 27 of 196
Mahmoud Samir Fayed
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
Dr .Ahmed Tawwab
 
Fp intro scala
Fp intro scalaFp intro scala
Fp intro scala
Sergey Lobin
 
TRICK
TRICKTRICK
TRICK
Jimmy Ngu
 

What's hot (19)

Practical scalaz
Practical scalazPractical scalaz
Practical scalaz
 
The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184
 
week-7x
week-7xweek-7x
week-7x
 
Scalaz
ScalazScalaz
Scalaz
 
ProgrammingwithGOLang
ProgrammingwithGOLangProgrammingwithGOLang
ProgrammingwithGOLang
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
Ruby Basics by Rafiq
Ruby Basics by RafiqRuby Basics by Rafiq
Ruby Basics by Rafiq
 
The Ring programming language version 1.5.4 book - Part 24 of 185
The Ring programming language version 1.5.4 book - Part 24 of 185The Ring programming language version 1.5.4 book - Part 24 of 185
The Ring programming language version 1.5.4 book - Part 24 of 185
 
The Ring programming language version 1.3 book - Part 15 of 88
The Ring programming language version 1.3 book - Part 15 of 88The Ring programming language version 1.3 book - Part 15 of 88
The Ring programming language version 1.3 book - Part 15 of 88
 
LeetCode April Coding Challenge
LeetCode April Coding ChallengeLeetCode April Coding Challenge
LeetCode April Coding Challenge
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
Oscon 2010 Specs talk
Oscon 2010 Specs talkOscon 2010 Specs talk
Oscon 2010 Specs talk
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30
 
Swift rocks! #1
Swift rocks! #1Swift rocks! #1
Swift rocks! #1
 
The Ring programming language version 1.7 book - Part 27 of 196
The Ring programming language version 1.7 book - Part 27 of 196The Ring programming language version 1.7 book - Part 27 of 196
The Ring programming language version 1.7 book - Part 27 of 196
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
 
Fp intro scala
Fp intro scalaFp intro scala
Fp intro scala
 
TRICK
TRICKTRICK
TRICK
 

Similar to Rubymacros

Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
Emil Vladev
 
Arrays
ArraysArrays
Arrays
AnaraAlam
 
Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011
Tudor Girba
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
adrianoalmeida7
 
check the modifed code now you will get all operations done.termin.pdf
check the modifed code now you will get all operations done.termin.pdfcheck the modifed code now you will get all operations done.termin.pdf
check the modifed code now you will get all operations done.termin.pdf
angelfragranc
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
lichtkind
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kirill Rozov
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and tests
intive
 
#include iostream using namespace std; class Array { priva.pdf
#include iostream using namespace std; class Array { priva.pdf#include iostream using namespace std; class Array { priva.pdf
#include iostream using namespace std; class Array { priva.pdf
ANSAPPARELS
 
Nik Graf - Get started with Reason and ReasonReact
Nik Graf - Get started with Reason and ReasonReactNik Graf - Get started with Reason and ReasonReact
Nik Graf - Get started with Reason and ReasonReact
OdessaJS Conf
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
Jason Yeo Jie Shun
 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
erockendude
 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
erockendude
 
Analysis of algorithms
Analysis of algorithms Analysis of algorithms
Analysis of algorithms
MUSAIDRIS15
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
Kevlin Henney
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
Nishant Munjal
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
Kazunobu Tasaka
 
Get started with Reason
Get started with ReasonGet started with Reason
Get started with Reason
Nikolaus Graf
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
zone
 
Javascript
JavascriptJavascript
Javascript
guest03a6e6
 

Similar to Rubymacros (20)

Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Arrays
ArraysArrays
Arrays
 
Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
 
check the modifed code now you will get all operations done.termin.pdf
check the modifed code now you will get all operations done.termin.pdfcheck the modifed code now you will get all operations done.termin.pdf
check the modifed code now you will get all operations done.termin.pdf
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and tests
 
#include iostream using namespace std; class Array { priva.pdf
#include iostream using namespace std; class Array { priva.pdf#include iostream using namespace std; class Array { priva.pdf
#include iostream using namespace std; class Array { priva.pdf
 
Nik Graf - Get started with Reason and ReasonReact
Nik Graf - Get started with Reason and ReasonReactNik Graf - Get started with Reason and ReasonReact
Nik Graf - Get started with Reason and ReasonReact
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
 
Analysis of algorithms
Analysis of algorithms Analysis of algorithms
Analysis of algorithms
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
 
Get started with Reason
Get started with ReasonGet started with Reason
Get started with Reason
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
Javascript
JavascriptJavascript
Javascript
 

Recently uploaded

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 

Recently uploaded (20)

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 

Rubymacros

  • 1.  
  • 3.  
  • 4.  
  • 5. “ print 'hello'” :(print 'hello')‏ proc{ print 'hello' }
  • 6. RedParse.new(“print 'hello'”).parse :(print 'hello')‏ RedParse::CallNode[nil, &quot;print&quot;, [RedParse::StringNode[&quot;hello&quot;, {:@line=>1, :@close=>&quot;'&quot;, :@open=>&quot;'&quot;, :@char=>&quot;amp;quot;&quot;}]], nil, nil, {:@line=>1, :@not_real_parens=>true, :@offset=>0, :@lvalue=>nil}]
  • 8. macro simple(a,b) :(^a+^b) end def simple_user p simple(1,2)‏ end
  • 9. if $Debug macro assert(cond)‏ if RedParse::OpNode===cond and /[=!]=/===cond.op left,op,right=*cond :(fail 'expected '+^left.unparse({})+&quot;(==#{^left}) to be &quot;+ ^op+&quot; &quot;+^right.unparse({})+&quot;(==#{^right})&quot; unless ^cond) else :(fail &quot;expected #{:(^^cond)}, but was not true&quot; unless ^cond)‏ end end else macro assert(cond)‏ end end
  • 10. def test_assert a=1 b=2 assert a #ok assert a!=b #ok assert(a==b) #oops, fails. msg=&quot;expected a(==1) to be == b(==2)&quot; assert(nil) #oops, fails. msg=&quot;expected nil, but was not true&quot; #ok, that message didn't make a lot of sense... end
  • 11. Syntax trees are represented by trees of nested Nodes. All Nodes descend from Array, and their subnodes can be addressed by numeric index, just like normal Arrays. However, many subnodes want to have names as well, thus most (but not all) array slots within the various Node classes have names. The general rule is that Node slots may contain a Node, a VarNameToken, a plain Array, a String, or nil. However, many cases are more specific than that.
  • 12. VarNameToken<RubyLexer::Token #represents variables and constants (ident: String)‏ Node<Array #abstract ancestor of all nodes (except VarNameToken)‏ +RescueNode #a rescue clause in a def of begin statement | (exceptions: Array[Value*], varname: VarNameToken|nil, action: Value)‏ +WhenNode #a when clause in a case statement | (when: Value|Array[Value+] then: Value|nil )‏ +ElsifNode #an elsif clause in an if statement | (elsif: Value, then: Value|nil)‏ +ValueNode #abstract, a node which has a value (an expression)‏ |+ListOpNode #abstract, ancestor for nodes which are lists of ||| #things separated by some op ||+SequenceNode #a sequence of statements ||| (Array[Value*])‏ ||+ConstantNode #a constant expression of the form A::B::C or the like || #first expression can be anything || (Array[String|Value|nil,String+])‏ |+RawOpNode #ancestor of all operators (but not . :: ; , ?..:)‏ ||| (left: Value, op: String, right: Value)‏ ||+OpNode #ancestor of some operators |||+RangeNode #a range literal node |||+KeywordOpNode #abstract, ancestor of keyword operators ||||+LogicalNode #and or && || expressions ||||+WhileOpNode #while as an operator ||||+UntilOpNode #until as an operator ||||+IfOpNode #if as an operator ||||+UnlessOpNode #unless as an operator |||+NotEqualNode #!= expressions
  • 13. |||+MatchNode #=~ expressions |||+NotMatchNode #!~ expressions |+LiteralNode #literal symbols, integers || (val: Numeric|Symbol|StringNode)‏ |+StringNode #literal strings ||| (Array[(String|Value)+])‏ ||+HereDocNode #here documents |+StringCatNode #adjacent strings are catenated (&quot;foo&quot; &quot;bar&quot; == &quot;foobar&quot;)‏ || (Array[StringNode+])‏ |+NopNode #an expression with no tokens at all in it || (no attributes)‏ |+VarLikeNode #nil,false,true,__FILE__,__LINE__,self || (name: String)‏ |+UnOpNode #unary operators || (op: String, val: Value)‏ ||+UnaryStarNode #unary star (splat)‏ |||+DanglingStarNode #unary star with no argument ||||| (no attributes)‏ ||||+DanglingCommaNode #comma with no rhs || (no attributes)‏ |+ParenedNode #ugly, parenthesized expressions and begin..end || (body: Value) -OR- (parentheses)‏ || (body: Value|nil, rescues: Array[RescueNode*], || else: Value|nil, ensure: Value|nil) (begin...end and rescue as operator)‏ |+AssignNode #assignment (including eg +=)‏ || (left:AssigneeList|LValue, op:String ,right:Array[Value*]|Value)‏
  • 14. |+AssigneeList #abstract, comma-delimited list of assignables ||| (Array[LValue*])‏ ||+NestedAssign #nested lhs, in parentheses ||+MultiAssign #regular top-level lhs ||+BlockParams #block formal parameter list |+CallSiteNode #abstract, method calls ||| (receiver: Value|nil, name: String, ||| params: nil|Array[Value+,UnaryStarNode?,UnAmpNode?], ||| block_params: BlockParams, block: Value)‏ ||+CallNode #normal method calls ||+KWCallNode #keywords that look (more or less) like methods || #(BEGIN END yield return break continue next)‏ |+ArrayLiteralNode #[..] || (Array[Value*])‏ |+IfNode #if..end and unless..end || (if: Value, then: Value|nil, elsifs: Array[ElsifNode+]|Nil, else: Value|nil)‏ |+LoopNode #while..end and until..end || (while: Value, do: Value:nil)‏ |+CaseNode #case..end || (case: Value|nil, whens: Array[WhenNode*], else: Value|nil)‏ |+ForNode #for..end || (for: LValue, in: Value, do: Value|nil)‏ |+HashLiteralNode #{..} || (Array[Value*]) (size must be even)‏ |+TernaryNode # ? .. : || (if: Value, then: Value, else: Value)‏
  • 15. |+MethodNode #def..end || (receiver:Value|nil, name:String, || params:Array[VarNameToken*,AssignNode*,UnaryStarNode?,UnAmpNode?]|nil, || body: Value|nil, rescues: Array[RescueNode+]|nil, else: Value|nil, ensure: Value|nil)‏ |+AliasNode #alias foo bar || (to: String|VarNameToken|StringNode, from: String|VarNameToken|StringNode)‏ |+UndefNode #undef foo || (Array[String|StringNode+])‏ |+NamespaceNode #abstract ||+ModuleNode #module..end ||| (name: VarNameToken|ConstantNode, body: Value|nil)‏ ||+ClassNode #class..end ||| (name: VarNameToken|ConstantNode, parent: Value|nil, body: Value|nil)‏ ||+MetaClassNode #class<<x..end || (val: Value, body: Value|nil)‏ |+BracketsGetNode #a[b] | (receiver: Value, params: Array[Value+,UnaryStarNode?]|nil)‏ | ErrorNode #mixed in to nodes with a syntax error +MisparsedNode #mismatched braces or begin..end or the like
  • 16.