(Mc)CLIM and Becoming Enlightened

This is a cross post from a Gemini site I recently set up.

About four years ago (based on Github’s estimate), I took an interest in the Common Lisp Interface Manager (CLIM), and more particularly in the McCLIM implementation of CLIM. I made a couple of YouTube videos of myself poking around and learning how to use it, but I did not get far at the time: I had quit my programming job some years earlier and was in law school, and mostly quit programming even as a hobby shortly thereafter. My favorite of the videos was a snake game, by the way:

Drawing in McCLIM (And a Snake Game)

When I decided to jump back into Common Lisp a couple of weeks ago, one of the first things I did was go back to that game, clean up the code a bit, and remove a line using a feature that is not present in current versions of McCLIM (and thus prevented the game from running). I had a lot of fun trying to learn McCLIM, but I constantly felt somewhat overwhelmed. The documentation seemed to hint at great power, but I could not see it. It seemed too complicated for a GUI library with a very dated appearance.

I finally obtained the first spark of enlightenment while writing my Gemini client. The client suffers from the same problem of treating McCLIM like a GUI library, but a couple of tasks changed my perspective. The first was links: I needed a way to get some “clickable” text onto a page, and perform an action when it was clicked. The second was similar: Bookmarks. In Observatory’s bookmark interface, bookmarks act like links that you can click on to visit a page, but have the additional option of deleting the bookmark when you bring up a context menu by right-clicking. The bookmark issue was fairly easy after I got links working (and, admittedly, gave up on a more complicated bookmark interface).

I spent several hours reading through the CLIM specifications and McCLIM’s user guide in order to figure out what to do about links. I had thought about just using push buttons (I think there may be a Gemini client out there that did just that), but I really wanted to use normal, albeit perhaps colored, text that was clickable. I had the idea that this thing called “presentations” might do the trick. I read through the portions of the documentation that describe presentations a couple of times before deciding that they wouldn’t work: They seemed to be about presenting an object to the user, and perhaps requesting user input to manipulate the object. I mean, you write translators to change objects into other objects, and these are somehow associated with presentations. What was that all about, and what could it possibly have to do with just making text clickable? Too much for links, and not quite relevant. I looked into putting gadgets (CLIM’s term for widgets) into the stream (the main pane of the output window is set up as a stream in Observatory, so the document can be displayed by pointing standard output to it), but again, I decided I wouldn’t be satisfied with buttons for links. Finally I read about presentations again, and this time I carefully reviewed the with-output-as-presentation and define-presentation-to-command-translator macros. This was the beginning of enlightenment.

Here is the code for writing a link to the application window in Observatory:

(defmethod write-doc-part ((line link-line))
  (let ((res (link-line-uri line)))
    (if res
    (if (string= (resource-protocol res) "gemini")
        (with-drawing-options (t :ink *link-color*)
          (with-output-as-presentation (t line 'link-line)
        (format t "~a" (resource-get-uri res))))
        (format t "~a" (resource-get-uri res)))))
  (format t " -- ~a~%" (link-line-description line)))

It works a little different from links in other Gemini clients: Instead of showing the link description and making it clickable, it displays the URI and makes it clickable, with the link description beside it. It would be trivial to make it work like other clients, but I found this to be more informative to the user about where he or she is being taken. But that is not relevant here. The point is, the clickable portion of the link is within with-drawing-options (which changes the color to blue) and with-output-as-presentation. The later is the important part: It associates the text that gets printed out by the call to format with ‘line’, an instance of the class ‘link-line’. We make it clickable by creating the aforementioned presentation to command translator:

(define-presentation-to-command-translator follow-link
  (link-line com-follow-link observatory-app
         :gesture :select
         :menu t)
  (object) (list object))

The above code associates the ‘link-line’ class with the command (defined elsewhere) ‘com-follow-link’. This command is run whenever the ‘select’ gesture is performed on a presentation of a link-line, resulting in the link being followed. The ‘select’ gesture is associated with a left-click by default in CLIM. (As an aside, “:menu t” makes the command show up in a context menu when you right click, so there are actually two ways to follow a link.)

Bookmarks have another option, since they can be deleted. So they have their own class with another presentation to command translator. This one also shows up in the right-click context menu:

(define-presentation-to-command-translator delete-bookmark
    (bookmark-holder com-delete-bookmark observatory-app
             :gesture :delete
             :menu t)
    (object) (list object))

The delete gesture is associated with SHIFT+middle-click, if I understand the documentation correctly, but I just assume users will use the right-click menu to perform the action. I expect ‘bookmark-holder’ will end up as a subclass of ‘link-line’ eventually, as I clean up some things in Observatory, assuming I continue to work on it.

Where is the enlightenment, you ask? Well, I learned from this experience that I should not think of CLIM as a GUI library. It is first and foremost an abstraction for presenting objects to the user, and providing him or her with operations, such as commands, that act on or using those objects. The interface is secondary, and should arise naturally from the commands made available to the user. This is a different paradigm from traditional event-driven GUI libraries, in which one crafts out the interface and then associates widgets with callback functions. It has its event loop, sure, but the programmer is expected to think more in terms of asking the user for input and acting on it, like a command line program, rather than waiting for events. Or really, a strange hybrid of the two programming styles, with some new concepts about how users interact with objects in the program. If my memory retains a correct history of those videos I made a few years ago, I remember being impressed by McCLIM’s interactor pane (which does not make an appearance in Observatory, by the way). I thought it could be something neat and useful, but I never really figured it out. I think I understand now: It is another way to get commands and references to objects from the user.

The next time I write a CLIM program, I will start out with a different type of thinking and different expectations. The interface will grow out of the needs of the program, rather than the program being made to fit into a predetermined type of interface. I will think about what type of things I want to do, and what data I want to operate on, and start out by providing commands for the user to work on that data. When a need arises for the user to provide input to a command, such as a reference to an object, that is where a bit of the interface will arise, naturally to fulfill a purpose.

Objective reality

According to quantum mechanics, a particle is in multiple states, called a “superposition,” until an observation (e.g., a measurement of its position or momentum) is made, at which point its wave function “collapses,” reducing the particle to a single state. A couple of years ago, physicists performed an experiment that showed that an observer could collapse the wave function of a photon, yet a subsequent experimenter could find the photon in a state of superposition. A writer for MIT Technology Review reported on this experiment and concluded that it means “there’s no such thing as objective reality.”

One could instead interpret the results as meaning that science is inherently unreliable, something we have known for some time already.

La urbo kaj la montoj

Hodiaŭ estas bela, klara tago en San Diego. Tra la fenestro de mia oficejo mi vidas, unue, la urbon, kaj je longa distanco malantaŭ la urbo montojn. Ho, la montoj! Kvankam ili aspektas kiel ombroj en la distanco, ili ŝajnas pli realaj ol la urbo. Ekde ĉi tie ili ĉiuj aspektas preskaŭ same, sed mi konas ilin. Kelkaj staras nudaj, kiel grandaj teramasoj. Aliaj estas vestitaj per de ĉi tie nevideblaj pinoj. Tiuj lastaj baldaŭ kovros siajn kapojn per neĝĉapo. Jes, ili ĉiuj apektas same en la distanco, sed ĉiu el ili estas unika, samkiel ĉiu homo estas malsama ol ĉiu alia.

Male, ĉiu konstruaĵego de la urbo aspektas malsame, sed ili ĉiuj estas same artefaritaj, makuloj sur la tero. En ili ŝrumpas la homaj animoj pro la nerealeco de la hodiaŭa vivo. Tia estas la urbo, la natura hejmo de kleruloj kaj profesiuloj, kiuj jam delonge perdis la saĝon. Ili arogas al si la rajton regi kaj gvidi la vivon de la kamparanoj kaj laboristoj, kvankam tiuj pli bone konas kaj pli akre perceptas la realon.

Ho mi estu fore de ĉi tie, mi estu en la montoj, kie la steloj vere brilas dum la nokto! En la urbo, la steloj mankas, dronite en la artefarita stratlumo. Tio estas ĝusta, taŭga bildo de la blindeco de la urbanoj, blindaj gvidantoj de la homaro! Ne, ne en la urbo kuŝas vera saĝo, sed en la freneza senhejmulo, la ermito kiu loĝas en la montoj. Sed la montoj ne estas mia hejmo, kaj mi ne taŭgas por la vera vivo tie. Post momenta revo la nuboj forigas la klarecon de la tago; mi memoras mian miopecon, kaj revenas al la nerealeco, al kiu mi apartenas.

Ŝpinado

Lastatempe mi eklernis—aŭ, pli bone, provis eklerni—ŝpinadon kaj trikadon. Mi sukcesis triki malgrandan trikoton, eĉ se ne tre bone, sed mi estas terure nekompetenta pri ŝpinado. Verdire, mi neniam estis tre kompetenta pri laboro per la manoj; tial mi laboras en oficejo. Tamen mi ne estas tiel facile venkita, do mi daŭre laboros kaj ekzercos min, ne nepre ĝis perfekteco, sed ĝis mi povos fari ion pri kio mi ne hontos!

Mia celo estas lerni teksi per teksilo. Malgraŭ tio, mi volis komenci per ŝpinado, ĉar mi scivolis pri kiel oni faris fadenon. Hodiaŭ oni faras ĝin per maŝinoj laŭ la plej nova teknologio, sed mi eĉ ne uzas radŝpinilo (eble tio estas mia problemo!); mi uzas—aŭ provas uzi—simpla spindelo en la manoj, samkiel oni faris dum miloj aŭ dekmiloj (aŭ eble pli) da jaroj. Kiam mi fariĝos almenaŭ iomete kompetenta pri ŝpinado, mi aĉetos teksilon kaj komencos lerni teksadon. Fakte, estas “gildo” de teksistoj ĉi tie en San Diego, al kiu mi aliĝos por pli bone lerni la arton.

Kion vi, karaj esperantistoj, faras kiel ŝatokupon?

Nobly

How you proceed must be as noble as the cause you seek.

The turn of phrase is fantastic. It lends itself to meditation, or to ponderous and solemn thoughts. It occurs in the middle of a discussion of people taking upon themselves the role of Satan, accusing others and thereby “causing jarring, contention and strife.” Moreover, the discussion suggests that this role is played even by people “who desire a good thing” and have well-intentioned hearts.

So what does the phrase mean? What is the cause being sought? Is it related to learning to live in peace with each other? What does “proceed” mean here? Is it our actions, particularly those we might think are productive in favor of “the cause [we] seek?” And what is “noble?” Is it intended to contrast with accusing and causing jarring, contention and strife? Is it related to “lov[ing] one another, not begrudgingly, but as brothers and sisters indeed?” Or to “align[ing our] words with [our] hearts?

“Noble” and its derivations appear in a few places in T&C. 138:18: “How much more dignified and noble are the thoughts of God than the vain imagination of the human heart?” 139:7: “[T]he pure in heart, and the wise, and the noble, and the virtuous shall seek counsel, and authority, and blessings constantly from under your hand.” 146:20: “[T]he truth of God will go forth boldly, nobly, and independent.” What does the word mean in those places? Is it related to its use in the phrase quoted at the beginning of this post?

Reforestation

I was looking into an idea that was put into my head by an acquaintance a couple of years ago: that trees attract rain. I wondered if this was true, and, if true, how it works. Certainly this may be a mechanism by which the desert could be made to blossom as a rose. What I have read includes an article in the journal Bioscience explaining for the educated layman a hypothesis about how forests may be acting like “pumps” that bring about rainfall, and an article from CIFOR (a forestry research organization) on the potential of forests to mitigate drought. I expressed the following thoughts on the matter on Facebook:

Trees’ complex interactions with the atmosphere can help prevent both drought and flooding. But you need a lot of them. One gentleman, who died well into his 90s in the early 2000s, recalled his parents or grandparents describing vast forests that covered most of the United States only a couple hundred years ago; they had been instrumental in cutting those forests down. (The term used was “rainforests,” but I am not sure whether we would use the word the same way today.) In hindsight, clearing large amounts of forest to make room for farms, ever so popular in the 1800s, was a poor decision. It may be that we would have been better served by clearing small amounts of trees as necessary, and developing methods of agriculture that coexist well with the forest.

It would be interesting if we could cover the country in forests once again. Doing so could alleviate part of the stress we have put on the climate, at least partially alleviate problems in water supply in parts of the country, and improve agricultural fertility in arid or semi-arid regions, which would allow for greater local self-sufficiency throughout much of the country.

The political right ought to see an opportunity for greater liberty and national strength by improving self reliance throughout the country, while the political left ought to see the environmental advantages of having to transport less food over large distances. The left should see forestation as a way to combat climate change, while climate-change skeptics among the right should still be able to enjoy the beauty and clean air provided by the ubiquitous forests. Moreover, greater local self-sufficiently would make it possible to reduce or pause travel between regions during a pandemic (such as at the present), slowing the spread of the disease while avoiding restriction of movement within communities. If an individual region is able to provide for its own needs, a temporary restriction on travel to and from the region, but allowance of travel within the region (to visit friends, local parks, etc.) may be more palatable to the general public than the restrictions against which they are chafing at present.

Indeed, fads like “permaculture” and “urban farming” attract adherents from both the left and the right, indicating that both take an interest in the environment and food security, though perhaps for different reasons. That should give reason for hope that there’s at least a small chance that we could persuade the nation (and the world) to undertake a large reforestation project. Perhaps such a project, by reconnecting us to the Earth and her natural cycles, would also improve our collective mental and social well-being.

The chance, however, is small: Good sustainable agricultural practices, the type that would coexist well with universal forests, are not nearly as profitable as the soil-depleting computerized factory farms of big agriculture. Either extensive community participation in local agriculture, or an acceptance of higher food prices, would be needed.

Liberty and life; captivity and death

The Book of Mormon uses the word “liberty” more than any other volume of scripture. “Liberty” is associated with “eternal life” while “captivity” is associated with “death” (2 Nephi 1:10). Curiously, famine and poverty resulting from a deprivation of liberty are poised to kill far more people than the deprivation of liberty was intended to save.

Although the Book of Mormon has examples of preserving liberty through a limited amount of bloodshed (see, e.g., Alma 20:12), it also includes examples of escaping captivity without bloodshed (Mosiah 11:10-11). It seems that the Lord would prefer the latter for us in our day (T&C 50:7). Either way, if we are not capable of living in liberty, forceful overthrow of the government would be futile, as it would merely lead us from one captivity to another; nor would it make sense for the Lord to give us the liberty that our lifestyle shows that we don’t want. At the very least, if we desire freedom, we should be capable of living and interacting with each other in a way that government is superfluous.

There are plenty of people laughing at those complaining about the loss of “mah freedumb.” Ironically, among those mockers of freedom appear to be many who previously complained about the current president being a dictator. Let them laugh, and seek to peacefully persuade those who can be persuaded to pray, vote, and live in a way that will bring liberty. That, it appears to me, is the best way to both stand up to and show love for those who use dishonesty and manipulation to try to keep the rest of us in captivity. To the humble, an honest voice will stand out against the ubiquitous deception.

A show of force is not necessary; brandishing weapons in front of government buildings will at best bring temporary results, and may backfire. There are other ways to boldly support liberty and life in the face of captivity and death. Abinadi, held in bondage, loved Noah enough to die for him, and as a result brought Noah’s people out of captivity and into a new life in Christ.

Social virus

The current pandemic has revealed much about ourselves and our relationship to the government and to each other. An already-existing wound has been deepened, and at this point it is unlikely that it will heal.

Conservatives’ eyes have been opened to see a government engaging in tyrannical overreach approaching the degree that conspiracy theorists have warned about: not just by liberals, but supported by conservative governors, and even an institution—the police—that they have trusted, praised, and upheld as heroes. They see liberals as foolishly supporting that tyranny, insufficiently self-aware to realize their bondage in the universal house arrest or the upcoming economic catastrophe.

Liberals’ eyes have been opened to see a conservative movement intent on activity that will kill people, and that the government must suppress the movement by force in order to save lives.

To conservatives, liberals are a threat to freedom and cannot be reconciled to reason. To liberals, conservatives are a threat to people’s lives and cannot be reconciled to reason. The logical conclusion for either side is that force must be used to bring the other side into submission.

The hatred may fester for a while, perhaps years, in mutual toleration, but without a fundamental change in people’s character, the inevitable result is going to be violence. Unless a group of people decline the invitation to hate those who don’t think like them, sooner or later violence will be unavoidable.

If you choose not to hate, sooner or later you will be hated for your choice. Choose it anyway. Love your neighbor, even when he hates you.

Laying a snare

The Book of Mormon describes in detail the ruses that the wicked use to entrap the righteous. When Alma and Amulek spoke at Ammonihah, “there were some among them who thought to question them, that by their cunning devices they might catch them in their words, that they might find witness against them, that they might deliver them to the judges, that they might be judged according to the law, and that they might be slain or cast into prison, according to the crime which they could make appear or witness against them.” Alma 8:4. The same tactic was used against Abinadi (Mosiah 7:16) and Nephi (Helaman 3:16). It is interesting that the wicked use questions in order to dispute. It leaves a sort of “plausible deniability” because they can claim that they only want clarification or are merely seeking more information, despite the true intent “that thereby they might make him cross his words or contradict the words which he should speak.” Alma 8:5.

These ruses are “the foundations of the Devil” and the result is always “the utter destruction of this people.” Alma 8:5. Both the fact that this devil-inspired tactic seems to be the normal method of argument in our day, and the promised results of it should trouble us. “Yea, and I say unto you that if it were not for the prayers of the righteous who are now in the land, that ye would even now be visited with utter destruction. Yet it would not be by flood, as were the people in the days of Noah, but it would be by famine, and by pestilence, and the sword. But it is by the prayers of the righteous that ye are spared. Now therefore, if ye will cast out the righteous from among you, then will not the Lord stay his hand, but in his fierce anger he will come out against you; then ye shall be smitten by famine, and by pestilence, and by the sword. And the time is soon at hand except ye repent.” Alma 8:5.

Christ taught that “there shall be no disputations among you.” 3 Nephi 5:8. I think it would be wise advice to simply speak the truth plainly. When you disagree with someone about a matter, and your inclination is to respond with a question rather than directly stating that you disagree, it would be wise to consider whether you are following this tactic, which the Book of Mormon identifies as “the subtlety of the Devil,“ whose purpose is “that he might bring you into subjection unto him, that he might encircle you about with his chains, that he might chain you down to everlasting destruction according to the power of his captivity.” Alma 9:1. I certainly would not want to be part of the “utter destruction of [my] people” (Alma 8:5), particularly when “it is by the wicked that the wicked are punished, for it is the wicked that stir up the hearts of the children of men unto bloodshed.” Mormon 2:1.

It is particularly interesting that just as the Devil inspires the wicked to ask questions in some contexts, in other contexts the hard-hearted fail to ask questions when they should. “And I said unto them, Have ye inquired of the Lord? And they said unto me, We have not, for the Lord maketh no such thing known unto us. Behold, I said unto them, How is it that ye do not keep the commandments of the Lord? How is it that ye will perish because of the hardness of your hearts? Do ye not remember the thing which the Lord hath said, If ye will not harden your hearts, and ask me in faith, believing that ye shall receive, with diligence in keeping my commandments, surely these things shall be made known unto you?” 1 Nephi 4:2. I think I will make an effort to try to avoid disputing with questions, but at the same time I will try to bring more questions to the Lord. The choices seem to be that you can either help cause the utter destruction of your people, or you can be the reason that they are spared, at least until they get rid of you. Alma 8:5. If possible, I would rather choose the latter.