CH

February 27, 2014

In Which I Speak In Public on a Python Lisp

Filed under: Uncategorized — @ 12:00 a.m.
In Which I Speak In Public on a Python Lisp

"Whoever gave programmers the idea they should be talking in front of other people should be taken out back and shot."

Talk outline:

introduction

me

benkay @ <irc>

backends, infrastructure

bitcoin

lisp

business ∩ engineering ∩ design

hy

NOT PRODUCTION READY

get you a pylisp
$ brew install python3
$ virtualenv -p python3 hyplay
$ cd hyplay
$ source bin/activate
$ git clone http://github.com/hylang/hy
$ cd hy
$ python setup.py install
$ hy
=> (+ 1 2 3)
6

basics

addition:

=> (+ 1 2 3)
6

subtraction:

=> (- 3 2 1)
0

function nesting

=> (- (+ 1 2) (+ 2 1))
0

functions

ex1:

=> (defn add-two [added] (+ 2 added))
=> (add-two 4)
6

ex2:

=> (defn square [number]
     (** number 2))
=> (square 2)
4

NB: This was incorrect in the actual presentation.

ex3:

=> (defn square-root [num]
     (** num 0.5))
=> (square-root 25)
5.0
=> (square-root 27)
5.196152422706632

function composition

=> (defn add-four [added]
     (+ 2
       (add-two added)))
=> (add-four 4)
8

native python interop

lists

max

=> (max (list (range 10)))
9

min

=> (min (list (range 10)))
0

types

=> (type (square-root 27))
<class 'float'>

more types?

=> (type (range 20))
<class 'range'>

fun & crazy lispstuff

recursion

fibonacci number

mathy:
n_i = n_(i - 1) + n_(i - 2)
programmery:

current = previous + the-one-before-that

lispy:
=> (require hy.contrib.loop)
=> (defn fib-num [n]
    (loop [[i n]
	   [prev 0]
	   [cur 1]]
      (if (zero? i)
	cur
	(recur (dec i)
	       cur
	       (+ cur prev)))))
=> (list (take 10 (fib)))
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
=> (nth (fib) 20)
6765

An IRC acquaintance (heyo jnerula!) wanted to know why this didn't use standard multiple-arity lisp stuff (his example being an Erlang method for multiple arity implementations. The answers are that a) I'm lazy (a positive quality in engineers) and b) that the point of this was to demonstrate recursion without hurting anyone's brains.

mapping

english

ap-map takes a function of the special variable 'it', and a list, returning a generator

example 1a

=> (require hy.contrib.anaphoric)
=> (ap-map (+ 1 it) [1 2 3 4])
<generator object _hy_anon_fn_1 at 0x10e71b320>

example 1b

=> (ap-map (+ 1 it) [1 2 3 4])
<generator object _hy_anon_fn_1 at 0x10e71b320>
=> (list (ap-map (+ 1 it) [1 2 3 4]))
[2, 3, 4, 5]

example 2

=> (ap-map (fib-num it) [1 2 3])
<generator object _hy_anon_fn_1 at 0x10f9acaa0>
=> (list (ap-map (fib-num it) [1 2 3 4 5]))
[1, 2, 3, 5, 8]
=> (list (ap-map (fib-num it) [0 1 100 22 99 54]))
[1, 1, 573147844013817084101, 28657, 354224848179261915075, 139583862445]

example 2b

=> (list (ap-map (fib-num it) (range 20)))
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]

function reuse!

fibonacci sequence

code
=> (require hy.contrib.anaphoric)
=> (defn fib-seq [n]
(list (ap-map (fib-num it) (range n))))
results
=> (fib-seq 2)
[1, 1]
=> (fib-seq 4)
[1, 1, 2, 3]
=> (fib-seq 10)
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
=> (fib-seq 100)
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676221, 23416728348467685, 37889062373143906, 61305790721611591, 99194853094755497, 160500643816367088, 259695496911122585, 420196140727489673, 679891637638612258, 1100087778366101931, 1779979416004714189, 2880067194370816120, 4660046610375530309, 7540113804746346429, 12200160415121876738, 19740274219868223167, 31940434634990099905, 51680708854858323072, 83621143489848422977, 135301852344706746049, 218922995834555169026, 354224848179261915075]
=> (fib-seq 1000)
;; try it on your own box ;)

infinite sequences

fibonacci again…

code:
=> (defn fib []
     (setv a 0)
     (setv b 1)
     (while true
       (yield a)
       (setv (, a b) (, b (+ a b)))))
results
=> (list (take 10 (fib)))
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

macros

macros re-write your code at run-time

example:
=> (defreader t [expr] `(, ~@expr))
=> #t(1 2 3 4)
(1, 2, 3, 4)

why lisp?

Everything is a list

Queues

Iteration

MapReduce

Wikipedia:

"A MapReduce program is composed of a Map() procedure that performs filtering and sorting (such as sorting students by first name into queues, one queue for each name) and a Reduce() procedure that performs a summary operation (such as counting the number of students in each queue, yielding name frequencies)"

Reduction in mental overhead

Extreme flexibility in shaping the language to the problem domain

Abstraction composability without excessive mental overhead

Selectively absorbs good ideas from the programming mainstream

why not lisp?

you may develop job dissatisfaction

perennial toolchain problem

emacs

vim

IDEs

light table

it can be darn hard to find lisp work

you will become a grouchy old person with bizarre notions about technology

February 23, 2014

work, and not having any

Filed under: Uncategorized — @ 12:00 a.m.
work, and not having any

The Economist muses on the role of work in identity: http://www.economist.com/blogs/freeexchange/2014/02/social-norms

A world in which a healthy adult has the reasonable expectation of earning a decent living while working full-time at a market wage is absolutely a world in which the dignity of work is a useful social value to cultivate. In a world in which that is not a reasonable expectation, the dignity of work can be a harmful concept. Society would effectively be kicking people while they are down; in addition to the hardship involved in un- or underemployment and poverty society would demand that the workless individual feel shame at his or her inability to function as a valued member of society.

Most of America's psychological ills stem from misconceiving the world. It is not a wonderful place where the average person can derp their way through life and kinda be OK. No. The world is one unbroken landscape of constant war and competition for scarce resources. America's been through 70 years of absurd 'prosperity' wherein every working-age man could (before the previous two decades, at least) find an opportunity to put his shoulder to the wheel in return for some food credits and the promise of retirement.

That building is crumbling, as all buildings set upon foundations made by witch-doctors with the blood of innocents as mortar do1. America doth-mean revert to the natural state of the world, which is to say one wherein work is impossible to find for anyone with skills that fail to differentiate them from the mob.

In this world, do we give up on the nobility of work? Of course! This is communism! We say to the children: "imagine a world of no work! Where magically, your feeding tube is paid for, and you can be the creative snowflake you were meant to be!"

Stoppit. This is not the America of twenty or thirty years ago. There are but scraps on the table, and you must slit throats for your scraps or risk going hungry. Nobility of work?!?! Let me tell you about the nobility of failing to feed your family.

Maybe technological change will force a large share of the population to get by with too little to live on—or too little to live on relative to average earnings to be politically sustainable.

This will happen - this is the promise of Bitcoin. All fiat schemes will now fall apart, unable to generate currency fast enough to stay ahead of their own inflation. This includes all of the United States hanky-panky around borrowing money now to be repaid in printed dollars twenty years from now. The borrowing rates must increase. The welfare payouts will become more and more paltry, and the people will grow more and more restive. The corn subsidies will reduce the cost of gas and food less each year; the people who cannot find work (because America does not teach its people the value of fighting tooth and nail for a job, constantly improving oneself) will grow more and more desperate; the whole delicate edifice will suffer a shock it's unequipped to survive and boom! Chaos in the streets of New York2.

The problem that the Economist is grappling with under the hood here is that they can't actually wrap their heads around an America in which basically nobody can get work. You can see this in their treatment of wages and purchasing power:

Society will have to come up with new means to set useful incentives for people in a world in which we do not allocate purchasing power through market wages.

Do you hear that? Purchasing power is being allocated in some other way than wages. Are Facebook likes the new purchasing power? Oh, my sides…

It's communism all the way down. When the Economist says:

Economies that have relied on market wages to provide incentive structures for people for centuries (with a dash of dignity of work and other social norms thrown in) are going to have to change.

They intimate that things must change, and I can only imagine they mean for the government to pay everyone one of these "guaranteed minimum incomes". The laws of conservation must be satisfied, though, and that money must come from somewhere. Taxes won't pay for it, and attempting to impose them will drive the remaining capital from the country. Printing will pay for it much more easily today, at the cost of a ruined currency in a decade. This is the fate of all modern socialist governments with a printing press - ridiculous inflation to keep everyone who can't work in "food" and entertainment.

Footnotes:

1

In case you're wondering, the only foundation upon which you can construct a building safely has been engineered, not imagined.

2

Not that New York is a terribly civilized place to begin with, but whatever.

Monumental Dicks

Filed under: Uncategorized — @ 12:00 a.m.
Monumental Dicks

The finishing touch to my fortress-cum-pleasure-dome will be a giant cock ejaculating flames in the vehicular roundabout where most are wont to put delicate statues of the Niads and what have you. Something along these lines:

http://oglaf.com/lonelymountain/

"Java methods return exactly zero or one value..."

Filed under: Uncategorized — @ 12:00 a.m.
"Java methods return exactly zero or one value..."

Java methods return exactly zero or one value; that is the standard for java. If you need multiple values returned, create an object with the multiple values and return it.
http://stackoverflow.com/a/7470912

Why would anyone want to return multiple values from a function instead of creating a new encapsulation layer? Psh.

February 20, 2014

On Jaynes' The Origin of Consciousness in the Breakdown of the Bicameral Mind

Filed under: Uncategorized — @ 12:00 a.m.
On Jaynes' The Origin of Consciousness in the Breakdown of the Bicameral Mind

You don't need to read the Jaynes' book now, as Mircea Popescu's distilled it down to a morning's read.

Older Posts »

---