Dealing with end keyword in macros for array indices
Suppose I have an array of a composite type as follows: type myType a::Int b::Float end myArray=myType For obvious reasons, I would like to be able to use simple indexing to access the fields of composite types as follows: aVals=myArray[1:3].a The following macro can successfully accomplish this type of indexing, as long as I have a numeric iterable for the array: macro getArray(exp) iter=eval(exp.args.args) exp.args.args=:i; :[$(esc(exp)) for $(esc(:i)) in $iter] end How can I write a similar macro that is also capable of dealing with array indices with the end keyword, i.e.: aVals=#getArray myArray[1:end].a
The following macro solves not only the indexing problem but also sets the correct output type: macro getArray(exp) quote ftype=typeof($(esc(exp.args)).($(esc(exp.args)))); ftype[item.($(exp.args)) for item in $(esc(exp.args))] end end
Can I add numbers with the C/C++ preprocessor?
Meta Programming, whats it good for?
Using metamorphic code to reduce boilerplate
Typed metaprogramming languages [closed]
What to read as a good intro and quickstart to aspect-oriented programming and metaprogramming?
Examples of what D’s templates can be used for
Using Polymorphic Code for Legitimate Purposes?
A guide to Boo's metaprogramming and extensibility features?
JetBrains Meta Programming System
What does word “meta” mean? [closed]
Purdue Compiler Construction Tool Set (PCCTS) : website, tutorial, book?
Are there machine (and human) readable specification languages for algorithm collections and meta-libraries?
Can you nest C preprocessor directives?
Infix format for Nemerle macro
Graphically Modeling Metaprogramming
What exactly is metaprogramming?