- PREFACE
This is a distilled overview of the Lojban language.
Major concepts of the language are introduced by saying as much with as little as possible.
That is to say:
- For each concept the most crucial aspects are presented
SystemTime::now().duration_since(UNIX_EPOCH | |
+ Duration::from_secs(process.start_time)) | |
.unwrap_or(Duration::from_secs(0)) | |
.as_secs() |
/// Precompute a method's arguments before the call so that borrowck sees | |
/// them the same way that trans does. | |
macro_rules! unborrow { | |
// this rule fires when we have parsed all the arguments | |
// fall through to output stage | |
(@parse () -> ($names:tt $lets:tt) $($thru:tt)*) => { | |
unborrow!(@out $names $lets $($thru)*) | |
}; | |
// parse an argument and continue parsing | |
// this is the key rule, assigning a name for the argument and generating the let statement |
macro_rules! trn { | |
(@parse () -> (($a:expr) ($b:expr) ($c:expr))) => { | |
if $a { $b } else { $c } | |
}; | |
(@parse (? $head:tt $($tail:tt)*) -> ($a:tt () ())) => { | |
trn!(@parse ($($tail)*) -> ($a ($head) ())) | |
}; | |
(@parse (: $head:tt $($tail:tt)*) -> ($a:tt $b:tt ())) => { | |
trn!(@parse ($($tail)*) -> ($a $b ($head))) |
/// strategy: | |
/// - first copy the list of exprs -- the copy will just be used as a counter | |
/// - then, starting with all the exprs in a "left" list and an empty "right" list: | |
/// - move one expr at a time from "left" to "right", and decrement the counter _twice_ | |
/// - when the counter is zero, the halving is complete | |
/// - if there were an odd number of exprs, a compile error tells you about it | |
/// the macro is in continuation passing style, so you pass in a macro invocation and it will be called | |
/// twice, first with the "left" and then with the "right" (enclosed in square brackets) inserted as the last argument | |
macro_rules! halve { | |
// internal rules |
fn main() { | |
let values = vec![1, 2, 3]; | |
for x in values { | |
println!("{}", x); | |
} | |
// Rough translation of the iteration without a `for` iterator. | |
let values = vec![1, 2, 3]; | |
let mut it = values.into_iter(); |
#![allow(dead_code, unused_variables)] | |
//#![feature(trace_macros)] trace_macros!(true); | |
// strategy: scan the pattern for idents and pull them out, so we can create a let statement in the enclosing scope | |
macro_rules! guard { | |
(@as_stmt $s:stmt) => { $s }; | |
(@collect () -> ($($idents:ident)*), [($pattern:pat) ($rhs:expr) ($diverge:expr)]) => { | |
guard!(@as_stmt let ($($idents,)*) = if let $pattern = $rhs { ($($idents,)*) } else { $diverge }) | |
}; |
/// Wrapper for a struct declaration using C++-like "pub:" and "priv:" labels instead of Rust's individual member annotations | |
/// | |
/// Syntax is similar to a normal pub struct declaration (see example below) | |
/// The struct is given an automatic pub fn new() method which simply takes all members in order -- without this, there would be no way to construct an instance due to the private members | |
macro_rules! sticky_visibility { | |
// START INTERNAL RULES | |
// defeat the parser | |
(@as_item $i:item) => ($i); |
#[cfg(debug_assertions)] use std::ops::*; | |
#[cfg(debug_assertions)] use std::{f32, f64, fmt}; | |
#[cfg(debug_assertions)] | |
#[derive(Copy, Clone, Debug)] | |
struct Signaling<T>(T); | |
#[cfg(debug_assertions)] | |
impl<T: fmt::Display> fmt::Display for Signaling<T> { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
use std::sync::Arc; | |
macro_rules! clone_army { | |
($vars:tt | | $body:expr) => { | |
clone_army!(@emit $vars [] [] $body) | |
}; | |
($vars:tt move | | $body:expr) => { | |
clone_army!(@emit $vars [] [move] $body) | |
}; | |
($vars:tt || $body:expr) => { |
This is a distilled overview of the Lojban language.
Major concepts of the language are introduced by saying as much with as little as possible.
That is to say:
- For each concept the most crucial aspects are presented