Drkcore

14 04 2009 perl lisp Tweet

perlでread-eval-print-loop

クォートされたS式を受け取って文字列を返すものをつくってみた。

use Term::ReadLine;
my $term = new Term::ReadLine 'Simple LISP REPL';
my $prompt = "CL-USER> ";
my $OUT = $term->OUT || \*STDOUT;

while ( defined ($_ = $term->readline($prompt)) ) {
  my $res = $_;
  warn $@ if $@;
  $res =~ s/^\'//;
  print $OUT $res, "\n" unless $@;
}

実行

$ perl s.pl
CL-USER> '(+ 1 2)
(+ 1 2)
CL-USER>

という手抜き。

だが、Readerを実装して処理させれば良いのであろう。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021