MCPcopy Create free account
hub / github.com/argumentcomputer/ix / arbitrary_expr

Function arbitrary_expr

crates/ixon/src/expr.rs:172–297  ·  view source on GitHub ↗

Generate an arbitrary Expr using pointer-tree technique (no stack overflow)

(g: &mut Gen)

Source from the content-addressed store, hash-verified

170 }
171
172 /// Count nested applications for telescope compression.
173 pub fn app_telescope_count(&self) -> u64 {
174 let mut count = 0u64;
175 let mut curr = self;
176 while let Expr::App(f, _) = curr {
177 count += 1;
178 curr = f.as_ref();
179 }
180 count
181 }
182
183 /// Count nested lambdas for telescope compression.
184 pub fn lam_telescope_count(&self) -> u64 {
185 let mut count = 0u64;
186 let mut curr = self;
187 while let Expr::Lam(_, _, body) = curr {
188 count += 1;
189 curr = body.as_ref();
190 }
191 count
192 }
193
194 /// Count nested foralls for telescope compression.
195 pub fn all_telescope_count(&self) -> u64 {
196 let mut count = 0u64;
197 let mut curr = self;
198 while let Expr::All(_, _, _, body) = curr {
199 count += 1;
200 curr = body.as_ref();
201 }
202 count
203 }
204}
205
206#[cfg(test)]
207pub mod tests {
208 use super::*;
209 use crate::constant::Constant;
210 use crate::serialize::{get_expr, put_expr};
211 use crate::tests::gen_range;
212 use quickcheck::{Arbitrary, Gen};
213 use quickcheck_macros::quickcheck;
214 use std::ptr;
215
216 #[derive(Clone, Copy)]
217 enum Case {
218 Var,
219 Share,
220 Str,
221 Nat,
222 Sort,
223 Ref,
224 Rec,
225 App,
226 Lam,
227 All,
228 Prj,
229 Let,

Callers 9

gen_sharingFunction · 0.85
gen_definitionFunction · 0.85
gen_recursor_ruleFunction · 0.85
gen_recursorFunction · 0.85
gen_axiomFunction · 0.85
gen_quotientFunction · 0.85
gen_constructorFunction · 0.85
gen_inductiveFunction · 0.85
arbitraryMethod · 0.85

Calls 3

next_caseFunction · 0.85
gen_rangeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected