#!/usr/bin/env ruby root = File.expand_path('../..', __FILE__) %w(lib shen/lib).each do |path| full_path = File.join(root, path) $LOAD_PATH << full_path unless $LOAD_PATH.include? full_path end require 'shen_ruby' # Leave gracefully if someone hits Control-C during loading Signal.trap("INT") { puts "\nLeaving..."; exit 1 } # Load the Shen Envinronment print "Loading..." STDOUT.flush start = Time.now.to_f shen = ShenRuby::Shen.new now = Time.now.to_f puts ". Completed in %0.2f seconds.\n" % (now - start) # Now that the Shen environment is loaded, repurpose the SIGINT # handler to interrupt the current execution. class ReplInterrupt < StandardError; end Signal.trap("INT") { raise ReplInterrupt } # Launch the REPL command = :"shen-shen" begin shen.__eval(Kl::Cons.list([command])) rescue StandardError => e # K Lambda simple errors are already handled by the Shen REPL. Therefore # this must be another type of exception. Print it as such and reenter # the REPL without re-display the initial credits. if e.kind_of? ReplInterrupt puts "Execution interrupted. If you are trying to exit the REPL, use (quit)." else puts "Ruby exception: #{e.message}" end command = :"shen-loop" retry end