Source

Finger-deques / test.pkg

# Requires: standard

# Requires: finger-deque.lib


package test:  api {
                   main: ((String, List( String )))   ->   winix::process::Status;
               }
{
    package deq = finger_deque;
    include trap_control_c;		# trap_control_c	is from   src/lib/std/trap-control-c.pkg

    fun print_to_stderr msg
        =
        file::write
            (
              file::stderr,
              string::cat msg
            );

    fun print_factors ( number, factors ) = {
	printf "%d:" number;
	map (printf " %d") factors;
	printf "\n";
    };


    fun main' args = {
	if FALSE
	    my q = deq::empty_queue;	
	    q = fold_left (fn (a, b) = deq::push(b, a)) q (explode("0123456789abcdefghijklmnopqrstuvwxyz"));
	    # deq::debug_print(q);
	    my (q, c) = deq::pull(q);
	    printf "Pulled: %c\n" (the c);
	    # deq::debug_print(q);
	    q = deq::unpull(q, '*');
	    printf "Unpull: *\n";
	    # deq::debug_print(q);
	    my (q, c) = deq::pull(q);
	    printf "Pulled: %c\n" (the c);
	    # deq::debug_print(q);
	fi;
	if FALSE
	    my q = deq::empty_queue;	
	    q = fold_left (fn (a, b) = deq::push(b, a)) q (explode("0123456789abcdefghijklmnopqrstuvwxyz"));
	    # deq::debug_print(q);
	    for (q = q; !(deq::queue_is_empty(q)); q = q) {
		my (q, item) = deq::unpush(q);
		case (item)
		     NULL => raise exception SUBSCRIPT;
		     THE(item) => printf "%s" (implode([item]));
		esac;
	    };
	    printf "\n";
	fi;
	if FALSE
	    my q = deq::empty_queue;	
	    q = fold_left (fn (a, b) = deq::push(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
	    # deq::debug_print(q);
	    for (q = q; !(deq::queue_is_empty(q)); q = q) {
		my (q, item) = deq::pull(q);
		case (item)
		     NULL => raise exception SUBSCRIPT;
		     THE(item) => printf "%s" (implode([item]));
		esac;
	    };
	    printf "\n";
	fi;
	if TRUE
	    my q = deq::empty_queue;	
	    q = fold_left (fn (a, b) = deq::unpull(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
	    # deq::debug_print(q);
	    for (q = q; !(deq::queue_is_empty(q)); q = q) {
		my (q, item) = deq::unpush(q);
		case (item)
		     NULL => raise exception SUBSCRIPT;
		     THE(item) => printf "%s" (implode([item]));
		esac;
	    };
	    printf "\n";
	fi;
	if FALSE
	    my q = deq::empty_queue;	
	    q = fold_left (fn (a, b) = deq::push(b, a)) q (explode("The quick brown fox jumps over the lazy dog."));
	    # deq::debug_print(q);
	    my (q, x) = deq::unpush(q);
	    my (q, x) = deq::unpush(q);
	    my (q, x) = deq::unpush(q);
	    my (q, x) = deq::unpush(q);
	    q = deq::push(q, 'k');
	    q = deq::push(q, 'i');
	    q = deq::push(q, 't');
	    q = deq::push(q, 't');
	    q = deq::push(q, 'e');
	    q = deq::push(q, 'n');
	    q = deq::push(q, '.');
	    # deq::debug_print(q);
	    for (q = q; !(deq::queue_is_empty(q)); q = q) {
		my (q, item) = deq::pull(q);
		case (item)
		     NULL => raise exception SUBSCRIPT;
		     THE(item) => printf "%s" (implode([item]));
		esac;
	    };
	    printf "\n";
	fi;
	# printf "%s\n" (implode(deq::to_list(q)));
	();
    };

    fun main (name, args) = {

	fun run_program () = main' args;

	{   catch_interrupt_signal  run_program;
	    winix::process::success;
	}
	except
	    CONTROL_C_SIGNAL
		=>
		{   print_to_stderr [name, ": Interrupt\n"];
		    winix::process::failure;
		};

	    any =>
		{   print_to_stderr [   name,
			    ": uncaught exception ",
			    exceptions::exception_message any,
			    "\n"
			];

		    winix::process::failure;
		};
	end ;
    };
};
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.