If you're exposed to programming languages, you'll want to implement a REPL.
Abbreviation for Read-eval-print loop Read, evaluate, display and repeat like letters. Refers to an interactive evaluation environment.
I see.
(loop (print (eval (read))))
Read in order from the right, "Read-Eval-Print Loop" is certainly ** REPL **.
If you want to execute the contents of this article and stop in the middle, use Ctrl + D </ kbd> or Ctrl + C </ kbd>.
Let's do it with Ruby.
% ruby -e'loop{p eval gets}'
1 + 2 * 3
7
"Pixiv".downcase
"pixiv"
Yeah, it's perfect. "Gets-Eval-P Loop" is ** GEPL **.
PHP is a little longer.
% php -r'while(1){ $code = sprintf("\$result = %s;", fgets(STDIN)); eval($code); var_dump($result); }'
1 + 2 * 3
int(7)
strtolower("Pixiv")
string(5) "pixiv"
“Vardump-Eval-Fgets While” is ** VEFW **. What is it?
How about Python (2.7)? It's very hard to write with one liner.
% python -c "while True:
print(input())
"
1 + 2 * 3
7
"Pixiv".lower()
pixiv
I don't know why, but Python 2 series ʻinput () is the same as ʻeval (raw_input (prompt))
. Everyone wondered who would get it ... Python 3000's ʻinput ()is the same as the 2nd series
raw_input ()`.
"Input-Print While" is ** IPW **. Or "Rawinput-Eval-Print-While" ** REPW **!
I wrote something like ~ in Lisp, but I haven't written Common Lisp properly, so I tried it.
% sbcl
This is SBCL 1.2.16, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (loop (print (eval (read))))
(+ 1 (* 2 3))
7
debugger invoked on a END-OF-FILE in thread
#<THREAD "main thread" RUNNING {1002C74753}>:
end of file on #<SB-SYS:FD-STREAM for "standard input" {100632C013}>
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
(SB-IMPL::INPUT-CHAR/UTF-8 #<SB-SYS:FD-STREAM for "standard input" {100632C013}> T 0)
0](string-downcase "Pixiv")
"pixiv"
0] ^D
*
I'm not sure, but I didn't get the default prompt *
, so I felt like it was working. (Maybe it's not working)
I also thought about studying Perl, but I didn't understand the data type so I gave up.
Recommended Posts