Morning
Good Morning!
đź‘‹
o/
Morning
mogge
One thing that I can't figure out is why does this work (let [{funky-name :old-name} my-map] funky-name)
. How does the {}
know to pull out the key called :old-name
and give it a new name called funky-name
?
what is the value of `my-map'?
looks like an unwholesome kind of destructuring within-a-let-statement kind of thing?
morning
Mornin
not unwholesome, that's just destructuring
people get tempted into deeply nesting them
I'm not a big fan
my-map is just {:old-name "david"}
I use {:keys [foo bar baz]} my-map
a lot in my code
yeah like that form
but there a few odd occasions, for clarity, that when I pull out a key from a map, I want to rename it
https://clojure.org/guides/destructuring#_associative_destructuring
I dislike it because the syntax is subtle
and I dont want to have to deal with nuance when reading some elses code
i'm the other way around - i quite often find myself destructuring two objects of the same type next to each other, and :keys
is useless then, and even when it's not absolutely necessary i find a destructure like [{u-name :name u-id :id :as u} user]
makes the subsequent code easier to read
Morning
so i actively avoid :keys
🙂 It’s good to know there are a few ways of doing these things. I’ll ask in #beginners
about how it works for the renaming
the docs are not bad @dharrigan https://clojure.org/guides/destructuring#_associative_destructuring
Yes, I’ve read them
doh! dup :man-facepalming:
but I don’t understand the mechanics
how does it know to pull out the key from the map
it’s abit counterintuiative
for example
I would have expected this
{:old-name funky-name} so to speak
since we do this
(:old-name my-map)
So this explains what it is doing
The destructuring form is now a map rather than a vector, and instead of a symbol on the left side of the let, we have a map. The keys of the map are the symbols we want to bind in the let. The values of the destructuring map are the keys we will look up in the associative value.
I just don’t understand the mechanics
I've steered clear of the basic associative destructuring approach in the past of favour of keys
because the way that works is more intuitive.
destructuring forms are written backwards from map-literal forms - which kind of makes sense @dharrigan - map-literals are putting something in to a map, destructuring is taking it out
(let [{foo :foo} {:foo 10}] foo)
okay… so why not (my-map :old-name)
since that’s taking old-name out of my-map
(let*
[map__211906
{:foo 10}
map__211906
(if (seq? map__211906)
(clojure.lang.PersistentHashMap/create (seq map__211906))
map__211906)
foo
(get map__211906 :foo)]
foo)
reading…
there's an example of what happens (gotten with macroexpand-1
)
@dharrigan (my-map :old-name)
is exactly what happens after macroexpansion
right, using the get
variant
yep
I see I see
here's a keys example
(let [{:keys [foo]} {:foo 10}] foo)
(let*
[map__211910
{:foo 10}
map__211910
(if (seq? map__211910)
(clojure.lang.PersistentHashMap/create (seq map__211910))
map__211910)
foo
(get map__211910 :foo)]
foo)
the generated code is identical!
ah! right. digesting. starting to make sense
what a lively on-topic discussion for a Friday morning! 🙂
Thank you everyone 🙂
I will go away and study.
I don’t really use a mac, but were people here stung badly by the oscp outage yesterday?
prevented mac apps from opening
(which is diabolical anyway! - apple controls what you can open up on your computer. every bit of software calls home to apple on open)
I can't upgrade my new work laptop to Big Sur yet (although maybe that's a good thing)
<https://twitter.com/lapcatsoftware/status/1326990296412991489>
i never noticed - didn't try and install anything yesterday
Oh, my OS upgrade is downloading now. Exciting!
the outage wasn’t about installing anything
it was the ocsp server on apple being unavailable. Everytime you open an app on a mac, it calls home
every single time
to check if it’s allowed to run or not (i.e., if apple kindly bestows its blessing upon you to run the apps that you may have bought)
if that is offline, then apps don’t open, as rather than a soft-fail (which is what is recommended), apple did a hard-fail.
i prefer this syntax, it's declarative and i can read it at a glance years later
@dharrigan are you sure about that? surely they must work offline
also you could just block the phoning home :woman-shrugging:
also final point on the destructuring - the long form with an :as entity-type
is imo the most readable
Alex, it was confirmed by multiple instances across t’interwebs
I do block it
I have 0.0.0.0 <http://ocsp.apple.com|ocsp.apple.com>
in my hosts file for my mac that I use now-and-again
@alex.lynham the problem was instead of hard-failing on the TCP connection (which would be fast), it was timing out after a long time (30s? 60s?); Happened to me as well and rebooting (hence opening lots of apps) exasperated the problem. I ended up booting into safe-mode to modify my /etc/hosts
and restore my sanity.
It's a wonderful example of Leslie Lamport's: "A distributed system is one in which the failure of a computer you didn't even know existed can render your own computer unusable."
so it is solvable by modifying your hosts file then? cool cool
i used to do a similar thing to stop adobe creative cloud cocking up my work laptop when i switched wifi networks
Be careful on upgrading to Big Sur
looks like apple can bypass any vpn restrictions (or little snitch restrictions) you have in place
but presumably not the hostsfile?
i'm still on mojave, no plans to move atm
I use one of those ethernet power plug things, and I frequently lose internet but stay connected. I don't usually notice for about 30m or so. It's just me, vim and localhost. Bliss.
do you have flakey electrics @dominicm? i've got the ethernet power plug things and i almost never lose connection
@mccraigmccraig the electrics in this house haven't been checked since before I was born.
So, probably.
my old house was much different - definitely flakey electrics and some sockets didn't work very well, others were fine
I also have really old versions of the ethernet plugs, which don't use ground. The new ones are supposed to be way more reliable.
I have a powerline too. Never experienced any droppage that I didn’t initiate myself.
They are rock solid
a pair of dlinks
yeah i found they were solid but the speed was poor, so i switched a several relay wireless routers and the speed is way higher now
although that powerline unit was bought in errrr 2014? so possibly they're better now
I have a pair of Gigabit powerlines
They were all us based before I believe. So the power line standard was just 2-port. I'm planning to run ethernet throughout the house for cctv and computers pis etc
morning đź‘‹
I think the powerline bandwidth is highly sensitive to the quality of the wiring in your house
agreed 🙂
When I was living in a shared house, I would just drop cable everywhere
and other electrical items perturbing the AC wave
Oh, I like that word
perturbing
haven't heard that in a while
I sense a great perturbance in the force