From 5e222eb91a02c42c52659b8786357760eb40d0ac Mon Sep 17 00:00:00 2001 From: lolisa Date: Fri, 9 Oct 2015 22:55:28 -0700 Subject: [PATCH] add show --- cirno.hpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cirno.hpp b/cirno.hpp index e0c8577..0425edb 100644 --- a/cirno.hpp +++ b/cirno.hpp @@ -7,21 +7,22 @@ using namespace algebraic_data_type; typedef recursive_indicator ri; DECLARE_ADT( expr, - ( (Unit) - , (True) - , (False) - , (Print, ri) - , (Seq, ri, ri) - , (When, ri, ri) - , (Unless, ri, ri) - , (If, ri, ri, ri) - , (String, std::string) + ( (Unit), + (True), + (False), + (Print, ri), + (Seq, ri, ri), + (When, ri, ri), + (Unless, ri, ri), + (If, ri, ri, ri), + (String, std::string), + (Show, ri) ), X ) bool value_to_bool( const expr & e ) { - return e.match( with( True( uim ), []( ){ return true; } ) - , with( False( uim ), []( ){ return false; } ) ); + return e.match( with( True( uim ), []( ){ return true; } ), + with( False( uim ), []( ){ return false; } ) ); } @@ -55,7 +56,8 @@ expr execute( const expr & e ) If( arg, arg, arg ), []( const expr & i, const expr & t, const expr & e ) { return value_to_bool( execute( i ) ) ? execute( t ) : execute( e ); } ), - with( String( arg ), []( const std::string & str ) { return String( str ); } )); + with( String( arg ), []( const std::string & str ) { return String( str ); } ), + with( Show( arg ), []( const expr & e ) { return String( show( execute( e ) ) ); } ) ); } #endif // CIRNO_HPP