Saturday 30 January 2016

Editable garbage printed at bash prompt after printing binary file in an xterm

Sometimes I would have garbage printed at the bash prompt in xterm after printing a binary file, like

64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c62;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c

I've never got around to work out why, until now.

The reason is the presence of byte 9A in the file. See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html. This is the "DECID" control sequence, which should cause the terminal to send a response string (as if it had been typed by the operator). Equivalent to DA or "Send Device Attributes". The response string in this case is

64;1;2;6;9;15;18;21;22c

with some more bytes at the beginning (ESC ? or ESC >, I'm not sure which).

Friday 8 January 2016

Meaning of lexical scope in Lisp

Lexical scope is described with the following:

Lexical scope. Here references to the established entity can occur only within certain program portions that are lexically (that is, textually) contained within the establishing construct

(Guy Steele et al (1989), Common Lisp the Language, 2nd edition, Chapter 3, Scope and Extent)

I think a nicer description is that lexical scope is early binding. It just so happens that all language constructs (lambdalet) that can create a binding for a variable that can be in effect when a function is defined happen to contain the textual region of the program where the variable is used.

I understood this from

Joel Moses (1970), The Function of FUNCTION in LISP