How is it that the 8th most popular language, above SQL, Go, R, and Ruby, is ... assembly?!
popular tech explained using Seinfeld skits
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.
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 #Python, 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 #Java, 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.
Game studio pauses development on their game after sinking Kickstarter funds into crypto
August 11, 2022
https://web3isgoinggreat.com/?id=game-studio-pauses-development-on-their-game-after-sinking-kickstarter-funds-into-crypto
pdxpol
Good news for #Portland! I know people who have been working on #RankedChoice (#InstantRunoff) 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.
#2659 Unreliable Connection
NEGATIVE REVIEWS MENTION: Unreliable internet. POSITIVE REVIEWS MENTION: Unreliable internet.
https://xkcd.com/2659/
Installing #emacs on a Mac was a huge pain the last time I did it, but it's become easy again:
uspol, climate
Democrats on climate change:
https://www.youtube.com/watch?v=X8QByzxYYHk
Republicans:
I miss Shenzhen
---
RT @towernter
Learning programming following a video tutorial
https://twitter.com/towernter/status/1558745418867118082
CS professor, game designer, and fire dancer ordinaire.