Fork me on GitHub

Can I print the bytecode of a compiled function at the REPL? Just curious.


I know I can touch the three parts, the name, the var, and the function itself, but can I print the function's code?


no.disassemble is amazing ❤️


Thanks guys! 💯💯


fwiw, there was this nice article that touches on this topic too with some practical advice:

thanks2 4
Eric Ihli18:11:10

Anyone good with statistics? I'm trying to answer a question. If I scratch 100 lottery tickets, what can I expect my winnings/losses to be within 66% of the time, 95% of the time, etc...? I'm not sure what words to use to describe this. I think it's something like "I want to see the graph of the cumulative distribution function for 100 scratches of a particular scratch off lottery game"?

Alex Miller (Clojure team)18:11:07

I think that's more probability (specifically combinations) than statistics

Alex Miller (Clojure team)18:11:33

although maybe when you include the distribution you get there


66% and 95% sound very standard deviation like numbers.


phrases like "within 1 standard deviation" and "within 2 standard deviations" seem possibly relevant

Eric Ihli19:11:36

I think what I need are the formulas in this stackexchange post. But nothing is making sense.

Eric Ihli19:11:01

# (prize_value, num_prizes_in_game)
# In statistics terms, I think this is: (observation, weight*)
# *Once we convert the scalar number of tickets to percentages
# by dividing the number of tickets at each prize level by the total
# number of tickets in the game.
tickets = [
    (15e6, 4),
    (1e6, 13),
    (1e5, 4),
    (2e4, 351),
    (1e4, 358),
    (5e3, 1066),
    (1e3, 24488),
    (500, 52608),
    (200, 175536),
    (100, 825885),
    (50, 1409291),
    (40, 2116878),
    (30, 3534425),
    (0, 13051157),

total_num_tickets = sum(t[1] for t in tickets)
scratch_tickets_percentages = [(t[0], t[1] / total_num_tickets) for t in tickets]

# Since we converted the weights to percentages, this is simply 1.0
# And since the sum of the weights is 1.0, we don't really need
# to divide by it in the following formula. But I'm leaving it there
# for reference because I'm not sure if I should have converted the number
# of tickets into percentages. Will that affect anything? Is it
# effectively the same going forward?
sum_weights = sum(t[1] for t in scratch_tickets_percentages)
weighted_mean = sum(
    weight * val
    for val, weight in scratch_tickets_percentages
) / sum_weights

sum_of_squares_of_weighted_means = sum(
    weight * (val - weighted_mean) ** 2
    for val, weight in scratch_tickets_percentages
)  # AKA variance

Eric Ihli19:11:13

Sorry for the Python, but off-topic eh? That gives me a variance of 43095998 (standard deviation of 6564), but what is that the answer to? $6,564 is obviously not the standard deviation of buying a single $30 lottery ticket. It's also obviously not the standard deviation of buying every ticket in the game. So while I think I followed the formula correctly, I'm not sure what question that formula is answering.

Eric Ihli19:11:29

End goal of this is I want to plug numbers into a formula, like, and get a visualization of where I can expect to be after 10 tickets, 100 tickets, etc...

Alex Miller (Clojure team)19:11:15

I'm going to save you the trouble and say you will be down :)

😆 17
Drew Verlee22:11:23

What's a good way to keep up with version changes on a project? (Clojure, JavaScript, java etc...) To know what new features are in a version. For instance, if I have a clojure project It would be nifty if you could subscribe to get notified if any deps had new versions and see those changes in a uniform way. Or as a point on time manual tool. Such a view would depend on people writing a changelog in the same way. Tag on question, do changelogs have a specification?


This is as close to a spec for changelogs as you'll find I think


This might be hard to give general advice on, and it also might be fairly arbitrary, but when it comes to the data structure of an event type that components of a system communicate, do people prefer vectors ie [:new-message/dogs {:payload 123 :timestamp 12345 :id 11} or maps like {:event/topic :new-message/dogs :event/data {:payload 123 :timestamp 12345 :id 11} :event/timestamp 12344} ? The vector style feels a bit nicer to type out when dispatch is usually based on topic, or when events are nested. however the map is easier to extend over time and more flexible, and I've found that it's pretty common in my usage to dispatch on something other than topic anyway. Anyone have any thoughts on this?

Drew Verlee22:11:40

i perfer the hashmap, vectors are best for items where the order implies something. Here the order implies what the values are, which is better reflected by keys in a map.

Drew Verlee22:11:23

I think the exception to this is if your very sure your api will be stable forever, then using values in a list might be ok bc it reduces the overhead. e.g anything in core, etc..


Yeah that's an interesting point too about the ordering. back to the nested/wrapped events, the ideal case for the vector events seems to be when dispatch is solely based on topic aka event-type aka first vector item. In that case it's a case of "first, what is the type of this thing, then based on that type hand the thing itself somewhere"

Drew Verlee22:11:16

i'm not sure what context the question is asked in. But i would like to see more event dispatch systems do dispatch like clojure does multimethods where it can be done off arbitrary code. For one, i quickly found that event names overlaped :logout-x :logout-y , etc.. As opposed to at least having it be tagged based [logout][x] [logout][y]

Drew Verlee22:11:00

there was a post on clojurverse that also talked about the pros and cons of using data for code in that context.

Drew Verlee22:11:35

it was a heavy topic, so i can't really summarize it, but it was from a week or so back, might be worth digging up if your building such a system.


Cool I'll try to find it


have been curious why vectors are used sometimes -- would like to hear why 🙂


The way I often like to think of it in general is that data is the raw representation of an idea, the language for the idea, and is a mapping of keys to values. The vector is a shorthand, an implicit mapping of integers to values (by position) that themselves often are implicitly supposed to represent some other key. So the map is the explicit data, the vector is implicit shorthand

👍 4
Andy Wootton09:11:25

I'm a Clojure learner, coming from a distant procedural language history but I've been thinking about this a lot. A vector is values/facts, onto which our mind projects an idea. A mapping of keys with meaningful names makes the idea more explicit. It is human-readable meta-data about declared knowledge. The data that is code is how-to knowledge. Data, facts and knowledge may all be wrong and need to be corrected later. Immutability allows the changes to be audited.


(I'm speaking highly in the general -- not necessarily specific to this case)


@sogaiu I've been using the vector style for awhile and it does feel nicer to me to type out and destructive. [:component/foo [ {:args-for :bar}]] can be nice when you multiple levels of routing, one to pass the message to the :component/foo handler and then that handler knows how to deal with the message. This is nicer to type and destrucure than the nested map alternative.


the places i've seen vectors that come to mind immediately are: unrepl, re-frame, and punk


(all that said I'm leaning towards switching to maps)


sente is where I was originally introduced to it


@zdot101 that's a good point too that a vector is basically just a map anyway


@jjttjj hadn't thought about the multiple levels -- thanks for mentioning that


aha well I'm carefully trying to call it a mapping in place of a map -- I feel like the words map and vector are themselves the perfect words to use when differentiating between these kinds of mappings


its so hard to find language sometimes for this sort


because its so precise


Examples btw where we use a similar sort of mapping with implicit meaning is lisp lists / function calls themselves! You could have written things like {:fn add :args [1 2 3]} and called the language MAPP but we stuck with the shorthand of (fn arg1 arg2 arg3) ahaha


also hiccup vs

Alex Miller (Clojure team)23:11:03

vectors are inherently positional, and thus have implicit attributes

Alex Miller (Clojure team)23:11:58

implicit usually means something is hidden/assumed - the tradeoff is typically that it's easier to type, more concise, but also less explicit about meaning

Alex Miller (Clojure team)23:11:35

implicit also typically means it's more fragile (harder to extend without violating assumptions)

Alex Miller (Clojure team)23:11:33

one common dodge here is to base your api on the explicit form, but support an implicit form for ease of use and a means of transforming from implicit to explicit

Alex Miller (Clojure team)23:11:36

often the explicit form is more amenable to programmatic transformation and manipulation too


ah and here I almost wrote something like that; what I was going to say is 'if I was going to use a short form, I'd often still want an explicit form underneath it as the base'

Alex Miller (Clojure team)23:11:54

the tradeoff for doing both is of course - more code, bigger api


but then I started getting into a conversation with myself over the trade offs and left it


cool, I hadn't considered doing both

Alex Miller (Clojure team)23:11:45

you can look around and find lots of examples all across this set of dimensions

Alex Miller (Clojure team)23:11:22

full let bindings = explicit, destructuring = implicit (there is an undocumented function destructure that converts from destructuring forms into let bindings)