I watch KEXP and NPR’s Tiny Desk concerts probably too much during this COVID-19 WFH period. Los Bitchos is a London-based instrumental band, which I found on KEXP’s YouTube channel.
In the very beginning of my career, I was using Perl. Mixi, a company I work for was a Perl shop. They were literally using LAMP (Linux, Apache, MySQL and Perl) at that time. Naturally I read Perl’s interpreter a bit. So, I know a few odd things about Perl.
The Lord of the Rings
All .c files in the Perl interpreter has a quote from “The Load of the Rings”. For example, perl.c has;
/*
* A ship then new they built for him
* of mithril and of elven-glass
* --from Bilbo's song of Eärendil
*
* [p.236 of _The Lord of the Rings_, II/i: "Many Meetings"]
*/
regcomp.c has;
/*
* 'A fair jaw-cracker dwarf-language must be.' --Samwise Gamgee
*
* [p.285 of _The Lord of the Rings_, II/iii: "The Ring Goes South"]
*/
Perl’s VM has a lot of opcodes
Perl’s opcode.h is long, because a lot of built-in functionalities are actually have opcodes internally. chomp
has its opcode, stat
has its opcode.
Some of them share its opcode wildly. For example sin
, cos
, exp
, log
and sqrt
are all eventually go to pp_sin
.
/* also used for: pp_cos() pp_exp() pp_log() pp_sqrt() */
PP(pp_sin)
{
dSP; dTARGET;
int amg_type = fallback_amg;
const char *neg_report = NULL;
const int op_type = PL_op->op_type;
switch (op_type) {
case OP_SIN: amg_type = sin_amg; break;
case OP_COS: amg_type = cos_amg; break;
case OP_EXP: amg_type = exp_amg; break;
case OP_LOG: amg_type = log_amg; neg_report = "log"; break;
case OP_SQRT: amg_type = sqrt_amg; neg_report = "sqrt"; break;
}
A heuristic approach to resolve the grammar’s ambiguity
This is the best.
In Perl’s grammar, s/$numbers[1]/xxx/g;
would be parsed as either “embed $numbers
here and then [1]
as a set of chracters” or “embed $numbers[1]
here”. The interpreter uses a heuristic to decide that. The implementation is in toke.c;
/* S_intuit_more
* Returns TRUE if there's more to the expression (e.g., a subscript),
* FALSE otherwise.
*
* It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
*
* ->[ and ->{ return TRUE
* ->$* ->$#* ->@* ->@[ ->@{ return TRUE if postderef_qq is enabled
* { and [ outside a pattern are always subscripts, so return TRUE
* if we're outside a pattern and it's not { or [, then return FALSE
* if we're in a pattern and the first char is a {
* {4,5} (any digits around the comma) returns FALSE
* if we're in a pattern and the first char is a [
* [] returns FALSE
* [SOMETHING] has a funky algorithm to decide whether it's a
* character class or not. It has to deal with things like
* /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
* anything else returns TRUE
*/
/* This is the one truly awful dwimmer necessary to conflate C and sed. */
STATIC int
S_intuit_more(pTHX_ char *s, char *e)
{
PERL_ARGS_ASSERT_INTUIT_MORE;
if (PL_lex_brackets)
return TRUE;
if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
return TRUE;
if (*s == '-' && s[1] == '>'
&& FEATURE_POSTDEREF_QQ_IS_ENABLED
&& ( (s[2] == '$' && (s[3] == '*' || (s[3] == '#' && s[4] == '*')))
||(s[2] == '@' && memCHRs("*[{",s[3])) ))
return TRUE;
if (*s != '{' && *s != '[')
return FALSE;
PL_parser->sub_no_recover = TRUE;
if (!PL_lex_inpat)
return TRUE;
The whole function is ~130 lines long. Perl is great.
3 days ago
GNU: date --date '3 days ago'
BSD: date -v -3d
From UNIX epoch
GNU: date --date @1594956336
BSD: date -r 1594956336
So what GNU date can do with --date
? What is the syntax?
From man date(1);
The
--date=STRING
is a mostly free format human readable date string such as “Sun, 29 Feb 2004 16:21:42 -0800” or “2004-02-29 16:21:42” or even “next Thursday”. A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.
Oh, yeah. I love this stubborn GNU-ism! The quote in the info documentation is also fascinating.
I was looking I’m happier without a smartphone (2018) from Firefox’s History. I recently found this post and I liked it.
Getting rid of a smartphone is not for me, but I’ve been following basically what Jake Knapp wrote on the “Make Time” book.
For me, an iPhone without distracting apps is an amazing device. Mine still has music and podcasts. It has tools straight out of Harry Potter: The Knight Bus (Uber and Lyft) and the Weasleys’ clock (Find Friends). I can read foreign languages with Google Translate. I can talk to Siri, and she (often) understands me. My phone still has fantastic maps and a kick-ass camera. It even has a flashlight!
On my OnePlus 5T, I have neither Chrome nor social apps, but I still have Google Maps, Line (WeChat/WhatsApp equivalent in Japan), Pocket Casts and some others, which I don’t spend too much time.
I can do stuff but I cannot kill time on my phone. Being bored is good, especially as a parent. Kids don’t interrupt you when you do nothing. They are actually giving things to do for you, from playing with Lego to changing diapers.
I’ve been using Emacs for more than a decade. In the very beginning, I was using Meadow, which was Emacs 20’s fork, for Windows, which supports Japanese and other languages better than the original at that time. I might have used Mule for Win32 for a moment, but I cannot recall.
For me, Emacs, or the fork was the gateway drug for Linux. When I first used Linux, certain things didn’t work compared to Windows, but certain things did work well, and those things were often Emacs stuff.
Fast-forward a few years, I bought iBook and admired the fact C-n, C-f, C-b, and C-p work universally. First-forward another few years, my project at work was in Android, and I started using Android Studio. Another Java project, IntelliJ IDEA. Slowly and lately I was adopting JetBrain’s IDEs. I also used Visual Studio Code. Awesome Emacs Keymap is great.
But now, I realized that my fingers don’t recall Emacs’s original keybindings sometimes. C-g during isearch-forward
moved my cursor to a surprising position. Seems I’m used to its half-emulated behavior on some other non-Emacs IDEs/editors. The original Emacs is now “surprising” for me.
That makes me sad.
So, I’m adding alias e='emacsclient --no-wait'
on my ~/.zshrc. I tend to use code ...
to start Visual Studio Code. I could replace this use-case with Emacs. Creating a full-fledged IDE from Emacs would be impossible, but Language Server Protocol could make IDE features more editor-agnostic. Emacs Lisp has lexical binding since 24.1.
Ditching Emacs is like dressing like the 20s. I’m old. I can be just old-school regarding Emacs.