High level machine language

susam 16 days ago

The first article in this issue of BYTE has a very interesting characterization of Lisp that I have not come across before. I mean, famous quotes like “Lisp is a programmable programming language” by John Foderaro and “The greatest single programming language ever designed” by Alan Kay are often mentioned in articles about Lisp. But in this issue of BYTE, the article “An Overview of LISP” by John Allen at page 10 has something very interesting to say. Excerpt from the article:

“The best description of the LISP programming language is that it is a high level machine language. That is, it shares many of the facets of contemporary machine language –the necessity for attention to detail and the freedom to manipulate the machine’s data and programs without restriction– yet LISP is high level in that the language contains the expressive power and convenience of traditional high level languages. The contradiction is resolvable: a LISP machine is just a higher level machine whose data items are organized differently from the binary bit patterns of most machines, and the LISP programming language is the assembly language for this machine.”

Consider the Emacs Lisp (Elisp) interpreter for example. Elisp interpreter is the Lisp machine. It understands Elisp symbolic expressions, the language of this machine. With enough code written in this machine’s language, we get this fine editing and productivity software known as Emacs!

aap_ 16 days ago

This exactly matches my thoughts. It seems that machine language and LISP are the only two languages (that I know anyway) where code and data are fundamentally the same kind of thing.

— Byte Magazine: LISP (1979)

— Hacker News

.

.

2022.08.22 Monday ACHK

Haskell mode

The goal of this blog post is to install an advanced Haskell mode, called LSP mode, for Emacs.

0. In this tutorial, you will need to go to the official website of NixOS and that of MELPA (Milkypostman’s Emacs Lisp Package Archive). Make sure that both websites are the real official ones. Any instructions from an imposter website can get your machine infected with malware.

1. Assuming your computer OS is Ubuntu 20.04 or above, go to the NixOS official website. Follow the instructions to install the Nix package manager (not the NixOS) onto your OS. Choose the “single-user installation” method.

2. On the NixOS official website, click the magnifying glass at the top right corner to reach the package search engine.

3. Search “haskell language server” and then copy its installation command.

nix-env -iA nixpkgs.haskell-language-server

4. Run the command in the bash terminal to install the Haskell Language Server.

.

5. Search “stack” on the package search engine.

6. Run its installation command

nix-env -iA nixpkgs.stack

to install the Haskell Tool Stack.

7. Search “ghc” on the package search engine.

8. Run its installation command

nix-env -iA nixpkgs.ghc

to install the Glasgow Haskell Compiler.

.

9. Reboot your computer.

This step is needed for triggering the OS to recognize the Nix package manager setup.

.

10. Go to MELPA package manager’s official website. Follow the instructions to install “Melpa”, not “Melpa Stable”.

11. Open the Emacs editor. Click "Options" and then "Manage Emacs Packages".

Install the following packages. For each of them, make sure that you have chosen the source archive as “melpa“. Versions from other sources would not work.

company Modular text completion framework
flycheck On-the-fly syntax checking
lsp-haskell Haskell support for lsp-mode
lsp-mode LSP mode
lsp-ui UI modules for lsp-mode

12. Open Emacs’ initialization file, which has the filename

.emacs

Its location should be

~/.emacs

13. Add the following code to the file.

;;;;;;;;;;;;;;;;;;;;;;;;;;

(require 'company)

(require 'flycheck)

(require 'lsp-ui) 

;;;;;;;;;;;;;;;;;;;;;;;;;;

(require 'lsp)

(add-hook 'haskell-mode-hook #'lsp)

(add-hook 'haskell-literate-mode-hook #'lsp)

(save-place-mode 1)

;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun haskell-and-go-back ()

  (interactive)
  
  (haskell-process-load-file)
  
  (windmove-up))

(global-set-key 
            (kbd "C-n") 
            'haskell-and-go-back)

;;;;;;;;;;;;;;;;;;;;;;;;;;

14. Close the Emacs program.

.

15. Create a dummy Haskell source code file named “test.hs”.

16. Use Emacs to open it.

17. You should see this message:

18. Select one of the first 3 answers. Then you can start to do the Haskell source code editing.

19. To compile your code, hold the Ctrl key and press n.

Ctrl+n

— Me@2022-08-18 05:22:02 PM

.

.

2022.08.20 Saturday (c) All rights reserved by ACHK

Org-babel-clojure

SICMUtils, 2

.

The goal of this post to setup the Emacs editor for Clojure programming.

.

1. Read and follow the exact steps of the last post.

.

2. Open the .emacs file. Go to the end of the file. Add the following code:

(require 'org)
(require 'ob-clojure)

(setq org-babel-clojure-backend 'cider)
(require 'cider)

(set-register ?c '(file . "~/my-stuff/my-stuff.org"))

(setq org-confirm-babel-evaluate nil)

(setq org-src-tab-acts-natively t)

3. Close Emacs.

.

4. Go to the directory “~/my-stuff/” and then create a file named “my-stuff.org“.

5. Use Emacs to open the file.

6. Within the file, add the following code:

#+BEGIN_SRC emacs-lisp

  (+ 1 1)

#+END_SRC

7. Place the text cursor in the code block (between the line #+BEGIN_SRC and the line #+END_SRC).

8. Hit the Emacs command

C-c C-c

9. You will get the evaluation result:

#+RESULTS:
: 2

.

10. Hit the Emacs command:

M-x cider-jack-in

11. Within the file “my-stuff.org“, add the code:

#+BEGIN_SRC clojure :results value		  

  (require '[sicmutils.env :as env])

#+END_SRC

12. Place the text cursor in the code block.

13. Hit the Emacs command

C-c C-c

.

14. Add the code:

#+BEGIN_SRC clojure :results value		  

  (env/bootstrap-repl!) 

#+END_SRC

15. Place the text cursor in the code block and then hit the Emacs command

C-c C-c

.

16. Add the code:


#+BEGIN_SRC clojure :results replace drawer
 
(->TeX (simplify ((D cube) 'x)))
 
#+END_SRC

17. Place the text cursor and then hit

C-c C-c

It will give you the \LaTeX code

#+RESULTS:
:RESULTS:
"3\\,{x}^{2}"
:END:

— Me@2022-07-27 11:34:28 PM

.

.

2022.07.28 Thursday (c) All rights reserved by ACHK

SICMUtils

A Clojure(script) implementation of the scmutils system for math and physics investigations in the Clojure and Clojurescript languages.

.

1. To install Clojure in Ubuntu, just this command is enough:

sudo apt-get install elpa-cider

Although the Clojure version you get is probably not the most updated one, that is not important, because you can specify which version you want in the config file of each project.

.

2. Then use this command to generate a new project named my-stuff:

lein new app my-stuff

.

3. Use Emacs to open the file:

~/my-stuff/project.clj

.

4. Replace the existing :dependencies line with this one

  :dependencies [[org.clojure/clojure "1.11.1"]
                 [sicmutils "0.22.0"]]

And make sure that both clojure and sicmutils have the most updated version numbers.

.

5. In Emacs, type the command

M-x cider-jack-in

.

6. In the clojure window (cider-repl), type

(clojure-version)

with enter at the end.

.

7. Type

(require '[sicmutils.env :as env])

.

8. Type

(env/bootstrap-repl!) 

.

9. Code

((D cube) 'x)

will result

(+ (* x x) (* x (+ x x)))

.

10. Type the Emacs command

M-p

to access the last input. Then modify it into

(simplify ((D cube) 'x))

.

It will result

(* 3 (expt x 2))

.

11. Code

(->TeX (simplify ((D cube) 'x)))

will give the LaTeX code

3\\,{x}^{2}

.

12. You can exit by the Emacs command

<C-c C-q> 

.

For the time being, SICMUtils is not suitable for the book SICM (Structure and Interpretation of Classical Mechanics). In other words, SICMUtils cannot replace the scmutils library yet, because:

a. You would have to do the translation manually, from the scmutils code in the book to SICMUtils.

b. Although it can generate LaTeX source code, it does NOT do the LaTeX rendering.

c. It cannot plot graphs.

However, SICMUtils has one advantage over scmutils. It can generate LaTeX source of an expression, but scmutils cannot. So I am planning to use both scmutils and SICMUtils.

Also, I will learn how to use SICMUtils with other Clojure libraries and the Jupyter Notebook. That would get LaTeX rendering and graph plotting running.

— Me@2022-07-26 11:03:51 AM

.

.

2022.07.26 Tuesday (c) All rights reserved by ACHK

Common Lisp Reloaded

; sudo apt-get install sbcl

; sudo apt-get install slime

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq inferior-lisp-program "sbcl")

(defun load-slime-with-correct-buffer-position ()

  (save-excursion (slime))
     
 
  (delete-other-windows) 
) 

(defun prelude-start-slime ()
  (unless (slime-connected-p)
    (load-slime-with-correct-buffer-position)))

(add-hook 'slime-mode-hook 'prelude-start-slime)

(set-register ?f '(file . "/path_to/lisp_file.lisp"))

— Me@2022-07-23 05:20:32 PM

.

.

2022.07.23 Saturday (c) All rights reserved by ACHK

C-h ?


C-h w command-name

C-h k key-sequence

C-h f function-name

— Me@2022-06-18 12:52:10 PM

.

.

2022.06.19 Sunday (c) All rights reserved by ACHK

3Blue1Brown

(defun 3b1b ()

    (interactive)

    (setq is-python-mode (string= major-mode "python-mode"))

    (if (not is-python-mode)
        (print "This is not a python file.")


        (print buffer-file-name)

        (setq the-command (format "%s %s %s" 
                                "manim -p"
                                buffer-file-name  
                                "JustAShape")) 

        (print the-command)                        

        (shell-command the-command) 
    )  
)

(global-set-key (kbd "C-p") '3b1b)

(global-set-key (kbd "C-/") 'comment-region)

(global-set-key (kbd "C-.") 'uncomment-region)

— Me@2022-06-05 04:00:37 PM

.

.

2022.06.05 Sunday (c) All rights reserved by ACHK

Watermelon

1990s, 19

.

(package-initialize)

(custom-set-variables
 '(cua-mode t nil (cua-base))
 '(custom-enabled-themes (quote (leuven))))
(custom-set-faces
 )

(set-register ?e '(file . "~/.emacs"))

(prefer-coding-system 'utf-8)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun backup-dot-emacs ()
  (interactive)

  (save-buffer)

  (setq backup-path (format "%s%s%s" 
              "/path_to_the_backup_folder/ubuntu_dot_emacs_" 
              (format-time-string "%Y_%m_%d_%I_%M_%S_%p")  
              ".el"))
  
  (write-file backup-path 'confirm)

  (setq original-cursor (point))

  (kill-buffer) 
  (find-file "~/.emacs")

  (goto-char original-cursor)
)

(global-set-key (kbd "C-`") 'backup-dot-emacs)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(set-register ?d '(file . "/path_to_the_blog_folder/dialogue59.txt"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun backup-blogging-tray ()
  (interactive)
  (save-buffer)

  (setq return-file-name (buffer-file-name))

  (setq backup-path (format "%s%s%s" 
                "/path_to_the_backup_folder/blogging_tray_" 
                (format-time-string "%Y_%m_%d_%I_%M_%S_%p")  
                ".txt"))

  (write-file backup-path 'confirm)

  (setq original-cursor (point))

  (kill-buffer) 

  (find-file return-file-name)

  (goto-char original-cursor)
 
)

(global-set-key (kbd "C-x C-a") 'backup-blogging-tray)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

— Me@2022.05.14 05:10:49 PM

.

.

2022.05.14 Saturday (c) All rights reserved by ACHK

scmutils, 3

Structure and Interpretation of Classical Mechanics

Scheme Mechanics Installation for GNU/Linux

.

This post assumes that you have already installed the scmutils library and been able to open it using the standard editor Emacs.

If not, go to the bottom of this post to click the category scmutils, so that you can see all the posts in this scmutils series.

d_2020_02_22__16_02_00_PM_

Then go to the post “scmutils, 2.3.2” to follow the installation and setup instructions.

.

After installing and setting up the scmutils library, you can start to use it.

d_2020_02_22__18_12_54_PM_

However, what if you want to close the Emacs editor? How to save your scheme program before closing Emacs?

By default, you cannot. So I have written a small program to help. Here is the installation instruction:

1. Go to the end of the .emacs file. Add the following code, if it does not already exist:


(defun mechanics()
  (interactive)
  (run-scheme
   "/usr/local/scmutils/mit-scheme/bin/scheme --library
/usr/local/scmutils/mit-scheme/lib"
  ))

2. Add the following code:


(fset 'set-working-dir
      (lambda (&optional arg) "Keyboard macro."
	(interactive "p")
	(kmacro-exec-ring-item
	 (quote ("(set-working-directory-pathname! 
                  \"~/Documents/\")\n" 0 "%d")) arg)))
 
(fset 'load-scm
      (lambda (&optional arg) "Keyboard macro."
	(interactive "p")
	(kmacro-exec-ring-item
	 (quote ("(load \"tt.scm\")" 0 "%d")) arg)))
 
(defun mechan ()
  (interactive)
  (split-window-below)
  (windmove-down)
  (mechanics)
  (set-working-dir)
  (comint-send-input)
  (windmove-up)			
  (find-file "~/Documents/tt.scm")
  (end-of-buffer)
  (windmove-down)
  (cond ((file-exists-p "~/Documents/tt.scm")
	 (interactive)
	 (load-scm)
	 (comint-send-input)))
  (windmove-up)
)
 
(defun cxce ()
  (interactive)
  (save-buffer)
  (windmove-down)
  (load-scm)
  (comint-send-input)
  (windmove-up)
)
 
(global-set-key (kbd "C-x C-e") 'cxce)

3. Close Emacs. Re-open it.

4. Type the command

M-x mechan

The command M-x means pressing the Alt key and x together. Then type the word mechan.

5. You will see the Emacs editor is split into two windows, one up and one down.

The lower window is the scheme environment. You can type a line of code and the press Enter to execute it.

The upper window is the editor. You can type multiple lines of code and the type

C-x C-e

to execute it. The command C-x C-e means pressing Ctrl and x together and then Ctrl and e.

d_2020_03_11__20_28_27_PM_

6. Your scheme code is saved to the following file

"~/Documents/tt.scm"

In case you need to backup your code, backup this file.

— Me@2020-03-10 10:59:45 PM

.

.

2020.03.10 Tuesday (c) All rights reserved by ACHK

scmutils, 2.3.2

Scheme Mechanics Installation for GNU/Linux

.

Steps:

1. The following steps are tested in Ubuntu 18.04. Prepare Ubuntu 18.04 if you can.

Note: Since the installation of the library scmutils requires the root access of your Linux system, please do NOT use it on your working computer. Instead, create an isolated virtual machine to use it.

.

2. Go to the bottom of this post to click the category scmutils, so that you can see all the posts in this scmutils series.

d_2020_02_22__16_02_00_PM_

3. Go to the post titled “scmutils, 2.3” to download

scmutils-20160827-x86-64-gnu-linux

4. Although the official installation guide advises you to install “MIT/GNU Scheme system” before installing scmutils, you do NOT need to install “MIT/GNU Scheme system” at all.

5. Unzip the file scmutils-20160827-x86-64-gnu-linux.

In the following, if you need to copy any commands or programming codes, remember that any number on the left of the vertical green line is NOT part of the code.

6. Run the command

tar xzf scmutils-20160827-x86-64-gnu-linux.tar.gz

to further extract the file.

-x — extract files from an archive;
-f — specify the archive’s name;
-v — show a list of processed files.

— Wikipedia on tar (computing)

Then two folders will be created: bin and scmutils.

7. Run the command

cd bin

to go into the folder.

You will see a file called mechanics.

.

8.1 Run the command

mechanics

You will get the error

mechanics: command not found

8.2 Instead, you should run the command

./mechanics

to specify that the file mechanics is actually in the current folder.

You will get the error

./mechanics: line 16: exec: xterm: not found

It is because your Linux system has not the program xterm yet.

8.3 Run the following command to install it.

sudo apt-get install xterm

8.4 Run the command again:

./mechanics

There will be an xterm window popup, but with an error message inside:

d_2020_02_22__17_08_35_PM_

That means you should move the two folders, bin and scmutils, to the pre-defined locations.

.

9.1 Run the command to move the folder scmutils to its pre-defined location:

mv scmutils /usr/local/

You will get the error

mv: cannot move 'scmutils' to '/usr/local/scmutils': 
Permission denied

9.2 Try again by

sudo mv scmutils /usr/local/

.

10.1 Go inside the folder bin.

10.2 Move its content to the pre-defined location by this command:

sudo mv mechanics /usr/local/bin/

.

11. Run the command

mechanics

Then you will see the Edwin window is opened. That means, in theory, you system has successfully installed the scmutils library. You can use it within the Edwin window if you like.

However, in practice, it is difficult, because it provides no syntax-highlighting. Also, you cannot use mouse in the Edwin window, so if you want to copy and paste a command or a series of commands, there will be no obvious way to achieve that.

So I suggest you to use the standard Emacs as the editor instead.

.

12.1 If you do not know Emacs, learn its basics.

12.2 Also, learn how to open Emacs’ initialization file, which has the filename

.emacs

After opening the file, you will see that it is just a text file.

12.3 Go to the end of the .emacs file. Add the following code:

(defun mechanics()
  (interactive)
  (run-scheme
     "/usr/local/scmutils/mit-scheme/bin/scheme --library
     /usr/local/scmutils/mit-scheme/lib"))

12.4 Save the file. Close Emacs. Then re-open Emacs.

12.5 Within Emacs, type the command

M-x mechanics

M-x means that while the Alt key is pressed down, press also x. Then type the word mechanics.

d_2020_02_22__18_12_12_PM_

12.6 Type the command

(+ 1 1)

to test the system.

d_2020_02_22__18_12_54_PM_

13. If you want to access your last command without re-typing it, type the command

M-p

d_2020_02_22__18_19_31_PM_

— Me@2020-02-22 06:25:47 PM

.

.

2020.02.22 Saturday (c) All rights reserved by ACHK

SLIME

SLIME, the Superior Lisp Interaction Mode for Emacs, is an Emacs mode for developing Common Lisp applications. SLIME originates in an Emacs mode called SLIM written by Eric Marsden. It is developed as an open-source public domain software project by Luke Gorrie and Helmut Eller. Over 100 Lisp developers have contributed code to SLIME since the project was started in 2003. SLIME uses a backend called Swank that is loaded into Common Lisp.

— Wikipedia on SLIME

.

C-x o

Window-Move to other

C-x C-e

Evaluate last expression

C-c C-r

Evaluate region

.

.

2018.10.19 Friday (c) ACHK

Emacs, 2

Nice to see Emacs getting a bit of press recently. I’ve used it for almost 20 years now and it dominates my time at the keyboard. It isn’t perfect and I’m reluctant to recommend it but I wouldn’t want to be without it. Let me explain.

The best thing about Emacs is that it can do everything (including the things it can’t do yet). The worst thing about Emacs is finding out how it does anything. I wouldn’t call it discoverable. In fact, on several occasions, I’ve learned about Emacs by accident: you press the wrong key combination (easy to do when you’re holding down a couple of keys and stretching for a third) and, look, something interesting happens!

— Accidental Emacs

— 2008-05-06 

— Thomas Guest

2013.03.04 Monday ACHK

Emacs

If you are a professional writer – i.e., if someone else is getting paid to worry about how your words are formatted and printed – Emacs outshines all other editing software in approximately the same way that the noonday sun does the stars. It is not just bigger and brighter; it simply makes everything else vanish.

— In the Beginning…

— Neal Stephenson

2013.02.01 Friday ACHK