Common Lisp calculator, 2
.

1. To run the following code, you have to install the Quicklisp library manager by following the steps in my blog post titled cmu-infix.
.
2.1 To enable the library, in the Common Lisp REPL, run the code:
(ql:quickload :cmu-infix)
(named-readtables:in-readtable cmu-infix:syntax)
2.2 If you encounter the error message:
Lisp connection closed unexpectedly: connection broken by remote peer
2.2.1 empty the cache folder:
~/.cache/common-lisp/
2.2.2 Restart the Common Lisp REPL.
2.2.3 Reload the library.
.
3.1 The goal of the following code is to create our own REPL.
(defmacro infix-string-eval (a-string) `(eval (read-from-string (concatenate 'string "#I (" ,a-string ")")))) (defun read-repl-all () (loop (print (write-to-string (read))))) (defun my-repl () (loop (let ((a-string (write-to-string (read)))) (if (or (string-equal "(exit)" a-string) (string-equal "exit" a-string)) (return) (print (infix-string-eval (string-trim "|()" a-string)))))))
3.2 In the Common Lisp REPL, run the code:
(my-repl)
— Me@2022-12-26 01:10:34 PM
.
The symbol
^
is the bitwise exclusive OR.
To create an exponentiation, we use
^^
— Me@2023-09-09 12:51:46 PM
.
— Me@2023-11-22 12:56:00 PM
.
.
2023.11.23 Thursday (c) All rights reserved by ACHK

You must be logged in to post a comment.