Show more

COVID: *wanes*

"Free Hugs" guy: *blows dust off sign*

Monkeypox:

Guy: %$#@!

News stories now come with the added dramatic tension of, "If I scroll past the next bunch of ads, is there more to the story?"

Today a child suggested that I look like Isaac Newton, which, fair.

The challenge for the obligatory Halloween costume is getting apples to continuously fall on my head.

@jalefkowit In one of the movie adaptations, a character inherits a sword and exclaims, "Ah, the weapon of a musketeer!" I always thought that would be, y'know, a musket.

@2ck Wait until you find out about Kickstarter. It might be YEARS.

One of the first in-class examples for my programming language class is a program that generates numbers, following a grammar from Scott, Programming Language Pragmatics.

In , this is 10 tiny functions, 49 lines including lots of PEP 8 whitespace:

import random

def evaluate(exp):
if isinstance(exp, str):
return exp
return exp()

def concatenate(*exps):
return ''.join([evaluate(e) for e in exps])

def choose(*exps):
return evaluate(random.choice(exps))

def star(exp):
result = ''
while random.randint(0, 1):
result += evaluate(exp)
return result

def number():
return choose(integer, real)

def integer():
return concatenate(digit, star(digit))

def real():
return choose(concatenate(integer, exponent), concatenate(decimal, choose(exponent, '')))

def decimal():
return concatenate(star(digit), choose(concatenate('.', digit), concatenate(digit, '.')), star(digit))

def exponent():
return concatenate(choose('e', 'E'), choose('+', '-', ''), integer)

def digit():
return choose('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')

print(number())

In , largely because there's no way to define a new type that subsumes String, it's an interface, 5 classes, 11 functions, 6 instance variables, 6 enum values, a huge switch statement, and 125 lines.

import java.util.Random;

interface Symbol {
public String generate();
}

class Terminal implements Symbol {

String symbol;

public Terminal(String symbol) {
this.symbol = symbol;
}

public String generate() {
return symbol;
}
}

class Concatenation implements Symbol {

Symbol[] symbols;

public Concatenation(Symbol... symbols) {
this.symbols = symbols;
}

public String generate() {
String result = "";
for (Symbol s : symbols) {
result += s.generate();
}
return result;
}
}

class Choice implements Symbol {

static Random r = new Random();

Symbol[] symbols;

public Choice(Symbol... symbols) {
this.symbols = symbols;
}

public String generate() {
return symbols[r.nextInt(symbols.length)].generate();
}
}

class Star implements Symbol {

static Random r = new Random();

Symbol symbol;

public Star(Symbol symbol) {
this.symbol = symbol;
}

public String generate() {
String result = "";
while (r.nextBoolean()) {
result += symbol.generate();
}
return result;
}
}

public enum Nonterminal implements Symbol {

NUMBER, INTEGER, REAL, DECIMAL, EXPONENT, DIGIT;

public String generate() {
switch (this) {
case NUMBER:
return new Choice(INTEGER, REAL).generate();
case INTEGER:
return DIGIT.generate() + new Star(DIGIT).generate();
case REAL:
return new Choice(
new Concatenation(INTEGER, EXPONENT),
new Concatenation(DECIMAL, new Choice(EXPONENT, new Terminal("")))).generate();
case DECIMAL:
return new Concatenation(
new Star(DIGIT),
new Choice(
new Concatenation(new Terminal("."), DIGIT),
new Concatenation(DIGIT, new Terminal("."))),
new Star(DIGIT)
).generate();
case EXPONENT:
return new Concatenation(
new Choice(new Terminal("e"), new Terminal("E")),
new Choice(new Terminal("+"), new Terminal("-"), new Terminal("")),
INTEGER
).generate();
case DIGIT:
return new Choice(
new Terminal("0"),
new Terminal("1"),
new Terminal("2"),
new Terminal("3"),
new Terminal("4"),
new Terminal("5"),
new Terminal("6"),
new Terminal("7"),
new Terminal("8"),
new Terminal("9")
).generate();
}
return null; // We should never get here
}

public static void main(String[] args) {
System.out.println(NUMBER.generate());
}
}

I used to love Java, but this amount of boilerplate really gets in the way.

I've noted before that most of the neural network books on my shelf are blue. That's probably a coincidence, but the similarity between these two programming languages book covers (from different publishers) is just weird.

pdxpol 

Good news for ! I know people who have been working on () voting for decades. It solves the "spoiler problem" by letting you vote for the candidate you like best rather than guessing how everyone else is going to vote and weighing "lesser evil" choices.


QT: pdx.social/@portlandmercury/10

Portland Mercury (unofficial)  
Measure to Change Portland Charter Can Stay on Ballot, Judge Rules https://www.portlandmercury.com/news/2022/08/15/45061907/measure-to-change-portl...

@jalefkowit If you think that's bad, a couple of college presidents ago we would get official emails saying only, "Please read this important message from the president's office," with a Word attachment.

#2659 Unreliable Connection 

NEGATIVE REVIEWS MENTION: Unreliable internet. POSITIVE REVIEWS MENTION: Unreliable internet.
xkcd.com/2659/

@grammargirl I prefer to ignore the accent mark and assume it rhymes with "Luddites".

@freakwater This was the first search hit I found. I don't make a lot of use of homebrew, so this was easier for me.

Show more
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.