Scala, Java, Unix, MacOS tutorials (page 54)

Many moons ago, I took a very long vacation and spent a lot of time driving around Alaska and Canada. When I stopped at a restaurant in a small town in Canada, I learned this story about Robin Williams and the move, Insomnia. (See my website, One Man’s Alaska, for more stories.)

Robin Williams, Insomnia, and a small town in Canada

“It’s only fear that makes you run,
The demons that you're hiding from.”

~ Melissa Etheridge, I’m Not the Only One

Which reminds me of this:

“There are two kinds of people in Alaska: those who were born here, and those who come here to escape something. I wasn’t born here.”

~ Rachel Clement, Insomnia

“It’s very hard to grow, because it’s difficult to let go of the models of ourselves in which we’ve invested so heavily.”

~ from the book One Liners, by Ram Dass

As a brief note today, here are some examples of the Scala 3 for loop syntax, including the for/do and for/yield expressions that are new to Scala 3.

Scala 3 'for' loop syntax (for/do)

// single line
for i <- ints do println(i)
for (i <- ints) println(i)

// multiline
for
    i <- ints
    if i > 2
do
    println(i)

Using 'end for' with for/do

You can also add end for to the end of a Scala 3 for loop, so the previous multiline example can also look like this:

for
    i <- ints
    if i > 2
do
    println(i)
end for

When your for loops get longer, I find that adding end for to the end of them makes them easier to read.

Scala 3 'for' loop as the body of a method

These examples show how to use a for loop as the body of a Scala method:

import io.Source

def printLines1(source: Source): Unit =
    for line <- source.getLines do println(line)

def printLines2(source: Source): Unit =
    for line <- source.getLines
    do println(line)
    
def printLines3(source: Source): Unit =
    for line <- source.getLines
    do
        println(line)
        
def printLines4(source: Source): Unit =
    for
        line <- source.getLines
    do
        println(line)
        
def printLines5(source: Source): Unit =
    for
        line <- source.getLines
        if line.trim != ""
    do
        // a multiline `do` block
        println("in `do` block of `for`")
        println(line)

Scala 3 for/yield expressions

Here are some single-line for/yield expressions:

I knew about GOTO statements from using FORTRAN, and today I learned about COMEFROM statements. For more information:

GOTO en.wikipedia.org/wiki/COMEFROM

GOTO and COMEFROM statements in programming

Scala FAQ: Can you show an example of the Scala 3 if-then-else-if syntax?

Scala 3 solution

Here’s an example of the Scala 3 if-then/else-if/else syntax, as used as the body of a method:

Expectations lead to suffering. :)

(For Bodhi Day, December 8th of every year.)

Buddha says expectations lead to suffering (Haven)

I took this photo of the Badlands in South Dakota on my drive up to Alaska in May, 2007. It’s still one of the most unique things I have seen.

The Badlands in South Dakota

If you use (a) a Mac/MacOS system, (b) Bash, (c) one or more Terminal tabs or windows, and (d) occasionally can’t find commands that should be in your Bash command history, you might find them in your ~/.bash_sessions directory. cd there and then grep for what you’re looking for.

macOS: Can’t find a command that should be in my history

Growing up, I remember that Dick Allen was considered a controversial figure, but I had no idea why, I was too young to comprehend those things. He passed away today, December 7, 2020, and the following text is from a story he tells in this video. The background is that the story takes place in 1963, in Little Rock, Arkansas, and he was a minor league baseball player:

They send me to Little Rock on a 24-hour recall, and left me there by myself. And when I say “myself,” I mean the only black player. Me being from Pennsylvania, I thought there was no racial tension, but geez, going to the soda machine to get a Pepsi out of the soda machine, and a cop car pulled in with the lights and there he is with a gun in my face. Hell, they’re trying to kill me right here. In America.

I come home, I think it was only a nickel or dime, and I put it in the pay phone. “Mama, I want to come home.”

You listen to me, boy, you hear me?

Back in May, 2007, on my drive up to Alaska, I stopped at Mt. Rushmore. One of my former co-workers found this little genie figurine that I/we started referring to as Little Buddha. When I held it up to take this photo, some guy that was also visiting there got really upset with me, and his wife had to calm him down.

Buddha at Mt. Rushmore

Thanks to this Twitter post, and the image shown here from this NASA page, I now know what an analemma is.

Analemma of the Moon

At some point over the last few months I realized that nobody in the fitness center wears a mask, so I haven’t exercised significantly since September. So I was pleasantly surprised to see my heart rate get down into the low 50s, even without that exercise.

I woke up at 3am and made some notes about a long dream sequence, which seems to correspond to the low in my little dipper there.

In a related note, if I die from a lack of exercise, this is a result of Covid-19: People don’t wear masks, so I don’t go to exercise in the fitness center. I can walk outside, but that’s nowhere near the level of exertion I can get on an elliptical trainer. (And you can’t really bike-ride safely in this area.)

Heartrate while sleeping (via Apple Watch)

Season 2, Episode 8 of Fringe, titled, August, has to be one of the Top 10 episodes of that series.

“She seduced me with baked goods.”

~ Walter talking about Fauxlivia (alternate universe Olivia) on Fringe

Back in 2018 I couldn’t find any decals I liked, so I bought some black chalkboard paint and painted the old computer I use as a Linux laptop. With a piece of chalk, I can now have a different logo on it whenever I want a new one. :)

Chalkboard-painted laptop

For a variety of reasons I recently wrote an “intentionally slow” HTTP socket server using Scala 3. Though I also wanted to test some things with Scala 3, the main reason for writing it is so I can test some client-side code, and make sure I handle server-side timeouts correctly.

As a brief note to self, this is an example sbt build.sbt file I just used for a Scala 3 (3.0.1) project on July 22, 2021, including several scalacOptions:

“When someone learns to drive a race car, one of the first lessons taught is that when you are going around a curve at 200 mph, do not focus on the wall; focus on the road. If you focus on the wall, you will drive right into it. If you focus on the road, you follow the road. Running a company is like that.”

~ Ben Horowitz, The Hard Thing About Hard Things

While driving through the mountains in Alaska and Canada in the winter, you learn a similar lesson: Focus on the road, not falling off the cliff. :)

When you want to print an sbt project’s version number from the command line — and only the version number — Seth Tisue came up with this answer here on the sbt gitter channel: