Got Scheme... actually Racket working with Org
This commit is contained in:
		
							parent
							
								
									72cdbdaea6
								
							
						
					
					
						commit
						78fa9d989a
					
				
					 1 changed files with 104 additions and 18 deletions
				
			
		| 
						 | 
					@ -25,49 +25,135 @@ A literate programming file configuring Emacs.
 | 
				
			||||||
  ;;; Code:
 | 
					  ;;; Code:
 | 
				
			||||||
  #+END_SRC
 | 
					  #+END_SRC
 | 
				
			||||||
* Introduction
 | 
					* Introduction
 | 
				
			||||||
First, install MIT-Scheme, the Lisp dialect used throughout the book:
 | 
					First, install MIT-Scheme, the Lisp dialect used throughout the SICP book:
 | 
				
			||||||
=brew install mit-scheme= or =sudo apt install mit-scheme= .
 | 
					=brew install mit-scheme= or =sudo apt install mit-scheme= .
 | 
				
			||||||
#+BEGIN_SRC sh
 | 
					#+BEGIN_SRC sh
 | 
				
			||||||
  brew install mit-scheme
 | 
					  brew install mit-scheme
 | 
				
			||||||
#+END_SRC
 | 
					#+END_SRC
 | 
				
			||||||
Ah, hell, we should install them all!
 | 
					
 | 
				
			||||||
 | 
					Or better yet, let’s use Guile:
 | 
				
			||||||
#+BEGIN_SRC sh
 | 
					#+BEGIN_SRC sh
 | 
				
			||||||
brew install guile racket chicken
 | 
					  brew install guile
 | 
				
			||||||
#+END_SRC
 | 
					#+END_SRC
 | 
				
			||||||
* Install Scheme
 | 
					* Geiser (Scheme Interface)
 | 
				
			||||||
The [[https://www.nongnu.org/geiser/][geiser project]] attempts to be the interface between Emacs and various Schemes.
 | 
					The [[https://www.nongnu.org/geiser/][geiser project]] attempts to be the interface between Emacs and various Schemes. Since I can’t decide which to use, I’ll install/configure them all.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#+BEGIN_SRC emacs-lisp
 | 
					#+BEGIN_SRC emacs-lisp
 | 
				
			||||||
  (use-package geiser
 | 
					  (use-package geiser
 | 
				
			||||||
    :init
 | 
					    :init
 | 
				
			||||||
    (setq geiser-mit-binary "/usr/local/bin/scheme"
 | 
					    (setq geiser-mit-binary "/usr/local/bin/scheme"
 | 
				
			||||||
          geiser-active-implementations '(mit))
 | 
					          geiser-racket-binary "/usr/local/bin/racket"
 | 
				
			||||||
 | 
					          geiser-guile-binary "/usr/local/bin/guile"
 | 
				
			||||||
 | 
					          geiser-active-implementations '(guile)
 | 
				
			||||||
 | 
					          geiser-default-implementations '(guile))
 | 
				
			||||||
    :config
 | 
					    :config
 | 
				
			||||||
    (use-package geiser-mit)   ; Choose favorite
 | 
					    (use-package geiser-mit)
 | 
				
			||||||
 | 
					    (use-package geiser-guile)
 | 
				
			||||||
 | 
					    (use-package geiser-racket)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-to-list 'org-babel-load-languages '(scheme . t)))
 | 
					    (add-to-list 'org-babel-load-languages '(scheme . t)))
 | 
				
			||||||
#+END_SRC
 | 
					#+END_SRC
 | 
				
			||||||
* Install SICP
 | 
					Do we need a Scheme work for Org Babel? According to [[https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-scheme.html][this document]], we just need to make sure we add the =:session= variable to start the REPL.
 | 
				
			||||||
 | 
					** Try it Out
 | 
				
			||||||
 | 
					:PROPERTIES:
 | 
				
			||||||
 | 
					:header-args:scheme:    :session *scheming* :results value
 | 
				
			||||||
 | 
					:END:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This should work?
 | 
				
			||||||
 | 
					#+name: hello-world
 | 
				
			||||||
 | 
					#+header: :var message="Hello World! What?"
 | 
				
			||||||
 | 
					#+begin_src scheme
 | 
				
			||||||
 | 
					message
 | 
				
			||||||
 | 
					#+end_src
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					However, it doesn’t output the results /back into/ this buffer. What is the point of connecting it to =ob=?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					** Install SICP
 | 
				
			||||||
 | 
					:PROPERTIES:
 | 
				
			||||||
 | 
					:header-args:scheme: :session sicp :results value replace
 | 
				
			||||||
 | 
					:END:
 | 
				
			||||||
Let’s get the book available as an Info page:
 | 
					Let’s get the book available as an Info page:
 | 
				
			||||||
#+BEGIN_SRC emacs-lisp
 | 
					#+BEGIN_SRC emacs-lisp
 | 
				
			||||||
(use-package sicp)
 | 
					(use-package sicp)
 | 
				
			||||||
#+END_SRC
 | 
					#+END_SRC
 | 
				
			||||||
* Try it Out
 | 
					 | 
				
			||||||
#+BEGIN_SRC scheme :results value
 | 
					 | 
				
			||||||
  (define (fib n)
 | 
					 | 
				
			||||||
    (if (< n 2) 1
 | 
					 | 
				
			||||||
        (+ (fib (- n 1)) (fib (- n 2)))))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  (fib 5)
 | 
					And does this work?
 | 
				
			||||||
 | 
					#+BEGIN_SRC scheme
 | 
				
			||||||
 | 
					  (inc 42)
 | 
				
			||||||
#+END_SRC
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Technical Artifacts                                :noexport:
 | 
					Still having difficulty getting the Scheme REPL to output the results back into this document. Let’s try Racket...
 | 
				
			||||||
Looks like we need this, at least, temporarily.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If we want to read the [[file:~/.emacs.d/straight/build/sicp/sicp.info][sicp.info]] file, looks like we need this, at least, temporarily:
 | 
				
			||||||
#+BEGIN_SRC emacs-lisp
 | 
					#+BEGIN_SRC emacs-lisp
 | 
				
			||||||
(add-to-list 'auto-mode-alist '("\\.info\\'" . Info-mode))
 | 
					(add-to-list 'auto-mode-alist '("\\.info\\'" . Info-mode))
 | 
				
			||||||
#+END_SRC
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					* Racket
 | 
				
			||||||
 | 
					Actually, let’s do this with [[https://racket-lang.org/][Racket]]:
 | 
				
			||||||
 | 
					#+BEGIN_SRC emacs-lisp
 | 
				
			||||||
 | 
					  brew install racket
 | 
				
			||||||
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					While Racket, as a Scheme, should work with Geiser (below), let’s also get [[https://racket-mode.com/][racket-mode]] working:
 | 
				
			||||||
 | 
					#+BEGIN_SRC emacs-lisp
 | 
				
			||||||
 | 
					  (use-package racket-mode
 | 
				
			||||||
 | 
					    :config (setq racket-program "/usr/local/bin/racket"))
 | 
				
			||||||
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Can we get Racket working with Org?
 | 
				
			||||||
 | 
					#+BEGIN_SRC emacs-lisp
 | 
				
			||||||
 | 
					  (use-package ob-racket
 | 
				
			||||||
 | 
					    :straight (:type git :protocol ssh :host github :repo "DEADB17/ob-racket")
 | 
				
			||||||
 | 
					    :after org
 | 
				
			||||||
 | 
					    :config
 | 
				
			||||||
 | 
					    (add-to-list 'org-babel-load-languages '(racket . t)))
 | 
				
			||||||
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					** Try It Out
 | 
				
			||||||
 | 
					:PROPERTIES:
 | 
				
			||||||
 | 
					:header-args:racket: :session racketeering :results value replace :lang racket
 | 
				
			||||||
 | 
					:END:
 | 
				
			||||||
 | 
					Working for values?
 | 
				
			||||||
 | 
					#+BEGIN_SRC racket
 | 
				
			||||||
 | 
					  (* 6 7)
 | 
				
			||||||
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#+RESULTS:
 | 
				
			||||||
 | 
					: 42
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Working for output?
 | 
				
			||||||
 | 
					#+BEGIN_SRC racket :results output replace
 | 
				
			||||||
 | 
					  (define str-1 "hello")
 | 
				
			||||||
 | 
					  (define str-2 "world")
 | 
				
			||||||
 | 
					  (define all (string-join (list str-1 str-2) ", "))
 | 
				
			||||||
 | 
					  (display (string-titlecase all))
 | 
				
			||||||
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#+RESULTS:
 | 
				
			||||||
 | 
					: Hello, World
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The interface is horrendously slow, as the =:session= doesn’t seem to work, and starting up a Racket REPL takes a long time.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					** SICP and Racket
 | 
				
			||||||
 | 
					:PROPERTIES:
 | 
				
			||||||
 | 
					:header-args:racket: :session *rsicp* :results value replace :lang sicp
 | 
				
			||||||
 | 
					:END:
 | 
				
			||||||
 | 
					If using [[https://docs.racket-lang.org/sicp-manual/SICP_Language.html][Racket for SICP]], install the SICP language:
 | 
				
			||||||
 | 
					#+BEGIN_SRC sh
 | 
				
			||||||
 | 
					  raco pkg install --auto --update-deps sicp
 | 
				
			||||||
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					We now can give it a =#lang sicp= (or better yet, use the =:lang= header) to define certain SICP-specify features:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Let’s try this now:
 | 
				
			||||||
 | 
					#+BEGIN_SRC racket
 | 
				
			||||||
 | 
					(inc 42)
 | 
				
			||||||
 | 
					#+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#+RESULTS:
 | 
				
			||||||
 | 
					: 43
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Technical Artifacts                                :noexport:
 | 
				
			||||||
Let's =provide= a name so we can =require= this file:
 | 
					Let's =provide= a name so we can =require= this file:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#+BEGIN_SRC emacs-lisp :exports none
 | 
					#+BEGIN_SRC emacs-lisp :exports none
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue