Changeset 5591
- Timestamp:
- 07/14/05 15:24:51 (3 years ago)
- svk:copy_cache_prev:
- 7591
- Files:
-
- 1 modified
-
examples/eval.p6 (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
examples/eval.p6
r5580 r5591 3 3 4 4 # Todo list: 5 # - ^Z should exit.6 5 # - There must be a cleaner way of presenting .perl without a leading \. 7 6 # - Need to implement :{e,E,d,D,h,r,l}. … … 12 11 } 13 12 14 say "^Z doesn't work, please use :q for now."; 13 # We'd like to not pollute the eval's environment with our vars ($line, etc.). 14 sub clean_eval ($___str) { eval $___str } 15 15 16 my $EOF = chr(26); 16 say "Welcome to Pugs -- $?PUGS_VERSION"; 17 say "Type :h for help."; 17 18 18 19 loop (;;) { … … 21 22 print "pugs> "; 22 23 my $line = =$*IN; 23 chomp($line); 24 25 # Quit and EOF. 26 quit() unless defined $line; 27 $line .= chomp; 28 # Skip empty lines. 29 next if $line eq ""; 24 30 25 31 given ($line) { 26 when "" { } # XXX should simply move to the next iteration of the outer loop 27 when $EOF { quit(); } 28 when /^\: (.) \s+/ { 32 when rx:P5/^\:(.)/ { 29 33 given ($0) { 30 34 when "e" { … … 55 59 } 56 60 default { 57 my $ret = eval $_; 58 if ($!) { 59 say $!; 60 } else { 61 #say $ret.perl; 62 say $ret.perl.substr(1, $ret.perl.chars - 1); # XXX NASTY HACK 63 } 61 # We need to .perl the result right here to make prettyprinting of 62 # junctions work. 63 my $ret = clean_eval $line; 64 say chomp $! and next if $!; 65 66 # We've to .perl in a second pass (and in a try {...} block) to 67 # catch "fail_"s. 68 $ret = try { $ret.perl }; 69 say chomp $! and next if $!; 70 say substr($ret, 0, 1) eq "\\" ?? substr($ret, 1) :: $ret; # XXX NASTY HACK 71 #" #--vim 64 72 } 65 73 } … … 76 84 This simplistic program will keep reading from standard input and evaluating whatever is 77 85 typed. 78 79 =end
