Code Conversion Language (2019)
107 points
1 day ago
| 5 comments
| emacsninja.com
| HN
lmz
1 day ago
[-]
Judging by the name and by these opcodes

https://github.com/emacs-mirror/emacs/blob/7cb77385d38b96377...

it seems to be intended for character set conversion especially JIS.

reply
usr1106
1 day ago
[-]
More documentation in https://github.com/emacs-mirror/emacs/blob/7cb77385d38b96377...

The directory is lisp/international, that already tells something

   ;; CCL is used for code conversion at process I/O and file I/O for
   ;; non-standard coding-systems.  In addition, it is used for
   ;; calculating code points of X fonts from character codes.
And

   $ find /usr/share/emacs/26.3/lisp/ \! -name ccl.el.gz -name \*.el.gz -exec zgrep ccl- {} +
   /usr/share/emacs/26.3/lisp/obsolete/pgg-parse.el.gz:(when (fboundp 'define-ccl-program)
   /usr/share/emacs/26.3/lisp/obsolete/pgg-parse.el.gz:  (define-ccl-program pgg-parse-crc24
   /usr/share/emacs/26.3/lisp/obsolete/pgg-parse.el.gz:      (ccl-execute-on-string pgg-parse-crc24 h string)
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:specified by the attributes `:ccl-decoder' and `:ccl-encoder'.
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:`:ccl-decoder' (required if :coding-type is `ccl')
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:VALUE is a CCL program name defined by `define-ccl-program'.  The
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:`:ccl-encoder' (required if :coding-type is `ccl')
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:VALUE is a CCL program name defined by `define-ccl-program'.  The
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:        '(:ccl-decoder
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:          :ccl-encoder
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:    (plist-put properties :ccl-decoder (car flags))
   /usr/share/emacs/26.3/lisp/international/mule.el.gz:    (plist-put properties :ccl-encoder (cdr flags))))
   /usr/share/emacs/26.3/lisp/language/vietnamese.el.gz:;;  '(ccl-decode-vps . ccl-encode-vps)
   /usr/share/emacs/26.3/lisp/language/ethiopic.el.gz:(define-ccl-program ccl-encode-ethio-font
   /usr/share/emacs/26.3/lisp/language/ethiopic.el.gz:(setq font-ccl-encoder-alist
   /usr/share/emacs/26.3/lisp/language/ethiopic.el.gz:      (cons (cons (purecopy "ethiopic") ccl-encode-ethio-font) font-ccl-encoder-alist))
Mule was non-ASCII support in the 1990s before Unicode was a thing.
reply
thih9
1 day ago
[-]
The source code mentioned in the article is well documented and an interesting read too; e.g.:

https://github.com/emacs-mirror/emacs/blob/master/src/ccl.c

reply
usr1106
1 day ago
[-]
I have used Emacs since 1986 or so, daily since 1989 (with smaller breaks while working at companies where it was not available). I had no idea this exists.

Here is my first CCL program.

   (define-ccl-program hw
     '(1
       (loop
        (write r0 [72 101 108 111])
        (r1 += 1)
        (if (r1 == 3) (repeat) ())
        (r0 += 1)
        (if (r0 < 4) (repeat) (break))
        )
       )
       )

   (ccl-execute-on-string
   'hw
   [0 0 0 0 0 0 0 0 1] "")

Tested in *scratch* buffer, worked. Probably not very idiomatic...
reply
uludag
1 day ago
[-]
Interesting. I've been using Emacs for 6 years and have never heard of CCL. I would love to read a book on all the strange and fascinating code that Emacs has accumulated over the years.
reply
sourcepluck
1 day ago
[-]
Yes, it seems ripe for quasi-archaelogical investigations. One tidbit that I couldn't believe was that Julian Assange had written an early version of Windmove, or an addition to an early version, or something along those lines.

I've nosed through some of the elisp files for the games - little goldmines everywhere in there.

reply
thih9
1 day ago
[-]
Looks like the details are in the file itself:

> Special thanks to Julian Assange (proff@iq.org), whose change-windows-intuitively.el predates Windmove, and provided the inspiration for it.

Source: https://github.com/emacs-mirror/emacs/blob/4823fa1077e4330bd...

change-windows-intuitively: http://quimby.gnus.org/s/change-windows-intuitively.el

reply
sourcepluck
1 day ago
[-]
Ah thank you, yes, that's it. A precursor to windmove, then. Very nice!
reply
Conscat
1 day ago
[-]
I recently played Emacs tetris, and I was confused by how the tetrominos were selected so I dove into the source code to impress my boyfriend. It turns out that the tetrominos' behavior is configurable with a defcustom, but by default it chooses to play without the bag rule, making their tetris hard to take seriously as an implementation for competitive play >:c
reply
sourcepluck
1 day ago
[-]
A. And was he impressed? My S.O. tends to have mixed reactions if I go on about source code too much. It's a fine line. She's an excellent tetris player though, so maybe this would get a pass.

B. I am not a big tetris player (too afraid of the inevitable addiction), but had a game there to see, and am now looking at the source code. ~tetris-allow-repetitions~ just has to be changed to nil, and then it does the correct bag rule behaviour?

C. I wonder why Emacs' tetris default is without the bag rule then... maybe you could submit a patch and propose a tournament? I only learned recently that the platform used for official tournaments is the NES version of Tetris, and now I'm learning that they use the bag rule. Tetris is more serious than I ever knew.

reply
tadfisher
11 hours ago
[-]
NES Tetris predates the bag rule. The RNG is an 8-sided die with one side meaning "reroll", so it is basically random. That's how you can easily get into droughts of I-pieces for long enough to end a run, and this greatly influences top-level play to encourage "burning" L- and T- pieces instead.
reply
Conscat
22 hours ago
[-]
Yes, he did seem impressed. I decided awhile ago that I'm only dating software nerds.
reply
sourcepluck
20 hours ago
[-]
Aha. That's the trick, then. Noted
reply
nanna
23 hours ago
[-]
Bag rule?
reply
Conscat
22 hours ago
[-]
In Tetris, you are supposed to have a "bag" of five tetrominos that are drawn from in random order. You can see the tetromino falling down and which one is coming next, and you know the one after that must be one of the remaining three that haven't been drawn yet (assuming there are any). If all five have been drawn, then the bag is reshuffled. This mechanic is what constrains the randomness to something that you can reason about to design openers or other strategies, which is also why Tetris can theoretically be played forever.
reply
layer8
15 hours ago
[-]
As someone who grew up with Game Boy Tetris, this sounds much too easy, to the point of making it quite a different game. ;)
reply
Conscat
13 hours ago
[-]
Correction, there are 7 tetrominos not 5. >.< Idk what I was thinking when I wrote that
reply
nanna
23 hours ago
[-]
Wow Windmove is a little gem that I'd never heard of. Shift-<arrow> is way more intuitive for me for moving around buffers than bashing C-x o or invoking ace window and then choosing a buffer number. Activate with

  (when (fboundp 'windmove-default-keybindings)
    (windmove-default-keybindings))
Thanks Julian!
reply
sourcepluck
20 hours ago
[-]
Brilliant, discovering things that you didn't know you needed that are already there in Emacs is a joy. Like getting a hug from the hackers[0] who went before.

[0] in the early MIT sense.

reply
usr1106
1 day ago
[-]
Not only archaeological. Some new Android stuff was implemented in CCL only last year.
reply
usr1106
1 day ago
[-]
Title should say (2019)
reply
medo-bear
1 day ago
[-]
not really. emacs is eternal
reply