; SLIME 2016-02-10 ;;SB: Look for any packages ('systems') with "shell" in their names: CL-USER> (ql:system-apropos "shell") # # # # # # # # # # # # # CL-USER> (ql:system-apropos "trivial-shell") # # ; No value ;;SB: Loading "trivial-shell", which I googled. CL-USER> (ql:quickload "trivial-shell") To load "trivial-shell": Load 1 ASDF system: trivial-shell ; Loading "trivial-shell" ("trivial-shell") ;;SB: Testing the simplest shell command. The function returns multiple values. CL-USER> (trivial-shell:shell-command "pwd") "/Users/user/cs59/midterm/warmup " "" 0 ; <-- Shell command's exit status ;;SB: Tried to run my script, forgetting I always run run it with "ruby ..." CL-USER> (trivial-shell:shell-command "./expr2sexp.rb '1+2+3'") "" "/bin/sh: ./expr2sexp.rb: Permission denied " 126 ; <-- Existed with an error code ;;SB: Now it works: CL-USER> (trivial-shell:shell-command "ruby expr2sexp.rb '1+2+3'") "(:program ((:binary (:binary (:@int \"1\" (1 0)) :+ (:@int \"2\" (1 2))) :+ (:@int \"3\" (1 4))))) " "" 0 ;;SB: Avoid annoying warnings: CL-USER> (defvar line) LINE ;;SB: It works now! CL-USER> (setq line (trivial-shell:shell-command "ruby expr2sexp.rb '1+2+3'")) "(:program ((:binary (:binary (:@int \"1\" (1 0)) :+ (:@int \"2\" (1 2))) :+ (:@int \"3\" (1 4))))) " CL-USER> line "(:program ((:binary (:binary (:@int \"1\" (1 0)) :+ (:@int \"2\" (1 2))) :+ (:@int \"3\" (1 4))))) " ;;SB: Loaded all of my code in warmup.lisp. Plenty of warnings, ;; and some errors where my tests were supposed to produce an error: CL-USER> (load "~/cs59/midterm/warmup/warmup.lisp") ;;SB: ; in: DEFUN RUBY-ARITHM-EVAL ; (DO-OP OP (RUBY-ARITHM-EVAL ARG1) (RUBY-ARITHM-EVAL ARG2)) ; ; caught STYLE-WARNING: ; undefined function: DO-OP ; ; compilation unit finished ; Undefined function: ; DO-OP ; caught 1 STYLE-WARNING condition While evaluating the form starting at line 389, column 0 of #P"/Users/user/cs59/midterm/warmup/warmup.lisp": T ;;SB: So, how do we make a sexp from the returned string? With read-from-string: CL-USER> (read-from-string "(+ 1 2)") (+ 1 2) 7 ; <-- Second returned value is string length. CL-USER> (setq line (trivial-shell:shell-command "ruby expr2sexp.rb '1+2+3'")) "(:program ((:binary (:binary (:@int \"1\" (1 0)) :+ (:@int \"2\" (1 2))) :+ (:@int \"3\" (1 4))))) " CL-USER> (read-from-string line) (:PROGRAM ((:BINARY (:BINARY (:@INT "1" (1 0)) :+ (:@INT "2" (1 2))) :+ (:@INT "3" (1 4))))) 93 CL-USER> (ruby-arithm-eval (read-from-string line)) 6 ;;SB: We really don't need any intermediate variables: CL-USER> (ruby-arithm-eval (read-from-string (trivial-shell:shell-command "ruby expr2sexp.rb '3*5-2*3'"))) 9 CL-USER>