ml

15 views
Skip to first unread message

Shireesha PS

unread,
Oct 2, 2017, 9:22:59 AM10/2/17
to Rust Bangalore Community
Is meta language and meta programming same

Saifi

unread,
Oct 2, 2017, 12:12:00 PM10/2/17
to rus...@googlegroups.com
Shireesha, they are not the same !

A 'meta language' is a form of language used for the description or analysis of another language.

Let's say you work in a language 'L' and like a concept 'C' which is present in some other language.

To implement the concept 'C', you'd need to work in a meta language 'meta-L', in order to extend the language 'L'

As part of the standard parsing process in language 'L', you'd need access to the Abstract Syntax Tree (AST), in order to incorporate the expression transforms from meta-L to L.

A good discussion about this is available in the 'Meta-Lua' wiki
http://lua-users.org/wiki/MetaLua

Taking the discussion further, in many languages it is possible to treat the program as data !
This is the blue print for meta programming in LISP.

Yet, in other languages like C++, template meta programming amounts to the entire code being evaluated at compile time.
https://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming

Back to Rust, take a look at the following code

let x: Vec<u32> = vec![1, 2, 3];

vec is a macro in this case, which may be mapped to this

let x: Vec<u32> = {
let mut temp_vec = Vec::new();
temp_vec.push(1);
temp_vec.push(2);
temp_vec.push(3);
temp_vec
};

So, if we take a look at 'libcollections', it looks like this

macro_rules! vec {
( $( $x:expr ),* ) => {
{
let mut temp_vec = Vec::new();
$(
temp_vec.push($x);
)*
temp_vec
}
};
}

i'd say that 'hygenic Macros' is a useful form of meta programming in Rust !

warm regards
Saifi.

Shireesha PS

unread,
Oct 29, 2017, 7:55:21 AM10/29/17
to Rust Bangalore Community
Thanks for detailed explaination
Reply all
Reply to author
Forward
0 new messages