In [1]:
using Stochy, Gadfly, Stochy.GadflySupport

In [2]:
@pp function literallistener(utterance)
enum() do
local world = worldprior(),
m = meaning(utterance, world)
factor(m ? 0 : -Inf)
world
end
end

Out[2]:
literallistener (generic function with 1 method)
In [3]:
@pp function worldprior()
randominteger(4) - 1
end

Out[3]:
worldprior (generic function with 1 method)
In [4]:
@pp function utteranceprior()
local utterances = [
"some of the people are nice",
"all of the people are nice",
"none of the people are nice"]
utterances[randominteger(3)]
end

Out[4]:
utteranceprior (generic function with 1 method)
In [5]:
@pp function meaning(utterance, world)
utterance == "some of the people are nice" ? world > 0 :
utterance == "all of the people are nice" ? world == 3 :
utterance == "none of the people are nice" ? world == 0 :
true
end

Out[5]:
meaning (generic function with 1 method)
In [6]:
dist = @pp literallistener("some of the people are nice");

In [7]:
bar(dist)

Out[7]:
In [8]:
@pp function speaker(world)
enum() do
local utterance = utteranceprior()
#factor(world == sample(literallistener(utterance)) ? 0 : -Inf)
local l = literallistener(utterance)
factor(score(l, world))
utterance
end
end

Out[8]:
speaker (generic function with 1 method)
In [9]:
@pp function listener(utterance)
enum() do
local world = worldprior()
#factor(utterance == sample(speaker(world)) ? 0 : -Inf)
local s = speaker(world)
factor(score(s, utterance))
world
end
end

Out[9]:
listener (generic function with 1 method)
In [10]:
dist = @pp listener("some of the people are nice");

In [11]:
bar(dist)

Out[11]:
In [11]: