From 7762fa4b128ad1e685e356a0de275842f0d43676 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 9 Aug 2024 02:33:48 +0200 Subject: [PATCH] simplify posint example remove setup_hex_master() / setup_dec_master() functions and instead directly call apply_morphism() --- examples/tty-04-posint/src/main.rs | 47 ++++++++++++++---------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/examples/tty-04-posint/src/main.rs b/examples/tty-04-posint/src/main.rs index b03bdd1..011ea32 100644 --- a/examples/tty-04-posint/src/main.rs +++ b/examples/tty-04-posint/src/main.rs @@ -32,28 +32,6 @@ use { std::sync::{Arc, RwLock}, }; -fn setup_hex_master(ctx: &Arc>, rt_int: &Arc>) { - rt_int.write().unwrap().detach( ctx ); - ctx.read().unwrap().apply_morphism( - rt_int, - &laddertypes::MorphismType { - src_type: Context::parse(&ctx, "ℕ ~ ~ > ~ ~ Char> ~ EditTree"), - dst_type: Context::parse(&ctx, "ℕ ~ ~ > ~ ~ Char> ~ EditTree") - } - ); -} - -fn setup_dec_master(ctx: &Arc>, rt_int: &Arc>) { - rt_int.write().unwrap().detach( ctx ); - ctx.read().unwrap().apply_morphism( - rt_int, - &laddertypes::MorphismType { - src_type: Context::parse(&ctx, "ℕ ~ ~ > ~ ~ Char> ~ EditTree"), - dst_type: Context::parse(&ctx, "ℕ ~ ~ > ~ ~ Char> ~ EditTree") - } - ); -} - #[async_std::main] async fn main() { /* setup context @@ -92,7 +70,16 @@ async fn main() { dst_type: Context::parse(&ctx, "ℕ ~ ~ > ~ ~ Char> ~ EditTree") }); - setup_hex_master(&ctx, &rt_int); + /* set Hex-editor to be master + */ + rt_int.write().unwrap().detach( &ctx ); + ctx.read().unwrap().apply_morphism( + &rt_int, + &laddertypes::MorphismType { + src_type: Context::parse(&ctx, "ℕ ~ ~ > ~ ~ Char> ~ EditTree"), + dst_type: Context::parse(&ctx, "ℕ ~ ~ > ~ ~ Char> ~ EditTree") + } + ); let edittree_hex_be_list = ctx.read().unwrap() .setup_edittree( @@ -174,14 +161,24 @@ async fn main() { 0 => { let mut li = last_idx.write().unwrap(); if *li != 0 { - setup_hex_master(&ctx, &rt_int); + rt_int.write().unwrap().detach( &ctx ); + ctx.read().unwrap().apply_morphism(&rt_int, &laddertypes::MorphismType { + src_type: Context::parse(&ctx, "ℕ ~ ~ ~ Char> ~ EditTree"), + dst_type: Context::parse(&ctx, "ℕ ~ ~ ~ Char> ~ EditTree") + }); + *li = 0; } } 1 => { let mut li = last_idx.write().unwrap(); if *li != 1 { - setup_dec_master(&ctx, &rt_int); + rt_int.write().unwrap().detach( &ctx ); + ctx.read().unwrap().apply_morphism(&rt_int, &laddertypes::MorphismType { + src_type: Context::parse(&ctx, "ℕ ~ ~ ~ Char> ~ EditTree"), + dst_type: Context::parse(&ctx, "ℕ ~ ~ ~ Char> ~ EditTree") + }); + *li = 1; } }