bs2gs

Guile

Learning Guile Scheme is helping me to implement D.R.Y. for teachers. The script below opens .csv files (encoded in the troublesome SJIS or cp932 Japanese character set). For each .csv file the script saves three files: two html files and a scheme file. Printing the html files provides a seating chart to start the semester, and a roll sheet for use throughout the semester. The scheme file is provides a way to end the semester by printing a simple html page to show class dates and attendance. That second script still needs to be made presentable. But the starting script may be useful.

Developing the script let me discover compact expressions to open and write files. Longer expressions derived from Kent Dybvig's /The Scheme Programming Language: Fourth Edition/ worked. Shorter expressions from the Guile Manual helped. There must be a simpler way to print scheme definitions to a file but now I use and output string and juggle symbols and strings. It's awkward, but it works for now.

With simple html (generated by sxml->xml) and .css (view2.css file) the pages have a good “ink to data” ratio. I think the style is consistent with that found in Koreo Kinoshita's (木下是雄) books: “Writing Techniques for Science Majors” 理科系の作文技術 and “Putting Together Reports” レポートの組み立て方 .

Here is a collage of samples from the script's generated pages, and Kinoshita's book on reports.

Read more...

After a few weeks with Guile I can now do with Scheme what I used to do with org-mode. The work flow is still in emacs but with the Geiser and shell modes there is less overhead. With less overhead it is easier to focus on the data, the solutions, and learning Guile Scheme with emacs as a second language. Typing data into Lisp lists may be simpler than working with tables, even org-table which seem to have so much less overhead than office software spreadsheets.

With free software, even irritating administrative work demanded by bureaucracy can be fun. With some time and free approach, bureacracy doesn't have to make us stupid all the time.(fn:1)

Emacs, Guile, and Firefox

Later I will show how to convert a csv data file to associative lists, but for now this script is an example of getting data(lists) from a file(port) and using the file name and data to generate an html page with sxml. I took me a while to get used to opening ports, and to remember to set their encodings to overcome issues with Japanese characters.

At first glance the sxml->xml and backquoting seemed overwhelming, but after some immersion experiences, mapping over lists to generate markup becomes second nature. If you see a lot of (quote (unquote ... in the generated sxml, it means that you typed a single-quote “ ' ” instead of a back-tick “ ` “.

Read more...

Guile lets us use ImageMagick and potrace with the procedures system and system*. I use (system "ls") to check the files in the REPL's current working directory. Browsing the manual(fn:1) showed (getcwd) as a way to avoid (system "pwd"), and (chdir "directory-to-change-to") as a way to stay in scheme.

もっと読む…

Recursion in general and named let in particular provide a natural way to implement many algorithms, whether iterative, recursive, or partly iterative and partly recursive; the programmer is not burdened with two distinct mechanisms. —– R. Kent Dybvig (fn:1)

This paragraph made me think of Ogden's Basic English and the English Through Pictures by I.A. Richards and Christine Gibson. Avoiding unnecessary burdens makes for better learning and working with ideas. Named let might have a place in a sequence with the aim of learning the most lucid and widely useful constructs for working with a computer language.

“Named let” didn't make sense to me when I first read in The Scheme Programming Language. (fn:1)

Read more...

Scheme Languages have fascinated me for a while, along with Racket, Emacs Lisp, and Common Lisp. It's hard to decide(fn:0) which language to concentrate on. But, on principle, I have to go with Guile: Gnu's Ubiquitous Intelligent Language Extension. And, in practice, SXML and scheme seem like a good way for me to re-implement the way I generate teaching worksheets from pictures and sentences. Also, the quote notation of I.A. Richards might be made more accessible with scheme-generated html pages too. Ethically, the most principled way, doing the right thing is the most important. Probably, in the long run, the time and attention dedicated to working with Free Software is the best way to grow and contribute as a decent person.

Free Programming Start: Computers on Kotatsu

Debian 9 with Gnome makes these computers, an older smaller notebook bought used and a newer larger laptop, work for me. I've been using the larger laptop for much longer than the older notebook, which I bought used and loaned to people as an free software experience.

Along with Racket, GNU's Guile Scheme from Debian's apt repositories had been on the bigger computer for some time. I was able to play with some examples while reading R. Kent Dybvig's The Scheme Programming Language ,but, Skribilo's installation gave me trouble a few months ago.

With a few free hours the other night, I read slow enough to see the Skribilo needs Guile 2.2 while I only had Guile 2.0. Complications took some time to overcome during the installation on larger computer that had Guile 2.0. Overcoming those complications made installation on the next computer easier, but Guile 2.2.4 seems to need a Guile 2.0 installation in order to have shared libraries to access. For learning Skribilo, and if all goes well – Artanis as well, I imagine I will only need one Guile. So I uninstalled Guile 2.0 apt uninstall guile after installing Guile 2.2.4.

Read more...

This blog is for learning to think with Guile Scheme:

  • GUILE: GNU's Ubiquitous Intelligent Language for Extensions
U for Guile
and and
I for Me

Working with Scheme Language will make me more intelligent: I for me.

Learning through examples will make Guile more ubiquoitous: U for guile.

Writings about Guile and Me, might work towards discoveries for “U” and “I”.

Recent Discoveries

Years ago I spent a week with The Schemer's Guide and I read a lot of Paul Graham's On Lisp too. Maybe all that time is starting to take effect now that I'm motivated to work in Guile, but I'm also wondering if well-graded or well-strutured classroom work with lambda , cut and fold- could encourage a quiet approach that lets the mind comprehend complex processes.

cut

The book, プログラミング Gauche (p.84), by the Kahua Project and Shiro Kawai got me started with cut. Modules are needed if you want to play with the ideas in Guile Scheme.

(use-modules (rnrs lists))    ;; find
(use-modules (srfi srfi-26)) ;; cut

(define nums '(1 2 3 4 5 6 7))
(find (lambda (n) (< 3 n)) nums)
(find (cut < 3 <>) nums)

Here is a useful example that uses cut for brevity: let's batch convert image files:

(use-modules (ice-9 ftw)) ;; scandir
(use-modules (ice-9 regex)) ;; string-match
(use-modules (srfi srfi-26)) ;; cut

(define bmps (scandir “./” (cut string-match “jpg$” <>)))

(define bmp2svg
  (lambda (bmp)
    "convert a .jpg  file to .svg file using system calls to ImageMagick's `convert' and then to `potrace'."
    (let ((pnm (replace-file-ext bmp "pnm"))
	  (svg (replace-file-ext bmp "svg")))
      (system* "convert" bmp pnm)
      (system* "potrace" "-b" "svg" "--tight" "-M" ".02" "--opaque" pnm "-o" svg))))
 ;; should really (delete-file pnm) after the potrace call, pnm files are huge.

(for-each bmp2svg bmps)

;; converting the svgs to pngs makes for clearer images that you would get converting directly from jpg files.

(define svg2png
  (lambda (fsvg)
    (let ((fpng (replace-file-ext fsvg "png")))
      (system* "convert" fsvg "-background" "white" "-layers" "merge" "-geometry" "x250" "-bordercolor" "white" "-gravity" "southwest" "-pointsize" "10" "-fill" "grey" "-annotate" "+0+0" "MioSato" fpng))))

(define svgs (scandir “./” (cut string-match “.svg$” <>)))
(for-each svg2png svgs)

;; convenience procedure to work with filenames
;;  I had scripts like this working in Emacs-Lisp using f.el or something but haven't discovered ready-made utilities like that for guile

(define get-file-ext
  (lambda (fname)
    "Get the extension from a filename with string-split and reverse"
    (let ((len (string-length fname)))
      (car (reverse (string-split fname #\.))))))

(define get-ext-len
  (lambda (fname)
     "Get length of file extention using get-file-ext"
    (string-length (get-file-ext fname))))

(define get-file-base
  (lambda (fname)
    "Get basename of file using string-length, get-ext-len, and substring."
    (let ((flen (string-length fname))
	  (elen (get-ext-len fname)))
      (substring fname 0 (- flen (1+ elen))))))

(define add-file-ext
  (lambda (bname fext)
    "Add to a basename a period '.' and a file extension."
    (string-append bname "." fext)))

(define replace-file-ext
  (lambda (fname next)
    "Remove from a filename its extension and replace the extension, using `get-file-base and `add-file-ext'."
    (let ((base (get-file-base fname)))
      (add-file-ext base next))))

I use the image-converstion procedures to blog gdm lessson worksheets. (fn:1)

fold-left fold-right

Programming Gauche also offer brain-training exercises with fold:

(use-modules (rnrs lists)) ;; fold-left , fold-right
(define nums '(1 2 3 4 5 6 7))

(fold-left    - 0 nums) ;; => -28

(fold-right - 0 nums) ;; => 4

I got the feeling that work with fold could lead to an appreciation of recursion, or an approach to following processes with your mind. After a few hours of thought with cut and fold I find that I use them more than I suspected. They turned out to be more than just attention-training exercises to help me get through an awful day of proctoring standardized tests.

Kent Dybvig's TSPL4 and Kahua's Gauche books, notebook, Guile Manual printouts, and PC keyboard

On-line Resources

FootNotes

#Guile #Scheme #ImageConversion #ImageMagick #potrace