code logs -> 2023 -> Mon, 11 Dec 2023< code.20231210.log - code.20231212.log >
--- Log opened Mon Dec 11 00:00:31 2023
00:09
<&McMartin>
I'm used to 'box' meaning "put this value into a (potentially mutable) cell"
00:09
<&McMartin>
In languages where mutability is the norm, "box" means "heap-allocate this and track its lifetime independently of what would otherwise be its container"
02:12 Vornicus [Vorn@Nightstar-ivektl.res.spectrum.com] has joined #code
02:12 mode/#code [+qo Vornicus Vornicus] by ChanServ
03:15 Degi [Degi@Nightstar-ct3364.pool.telefonica.de] has quit [Ping timeout: 121 seconds]
03:16 Degi [Degi@Nightstar-ntsuc1.pool.telefonica.de] has joined #code
03:25
<&ToxicFrog>
[R]: clojure calls this function `constantly`, i.e. `(constantly x)` returns a 0-arity function that, when called, returns x
04:53 Vornicus [Vorn@Nightstar-ivektl.res.spectrum.com] has quit [Connection closed]
08:27 [R] [rms@Nightstar-d7h8ki.org] has quit [Ping timeout: 121 seconds]
08:38 Alek [Alek@Nightstar-06ca3p.il.comcast.net] has quit [Ping timeout: 121 seconds]
08:41 Alek [Alek@Nightstar-06ca3p.il.comcast.net] has joined #code
08:59 [R] [rms@Nightstar-d7h8ki.org] has joined #code
08:59 mode/#code [+ao [R] [R]] by ChanServ
11:33 panzerfaus [uid279771@Nightstar-l49s2t.irccloud.com] has joined #code
13:41 panzerfaus [uid279771@Nightstar-l49s2t.irccloud.com] has quit [[NS] Quit: Connection closed for inactivity]
14:51 Vornicus [Vorn@Nightstar-ivektl.res.spectrum.com] has joined #code
14:51 mode/#code [+qo Vornicus Vornicus] by ChanServ
17:00 Emmy [Emmy@Nightstar-qo29c7.fixed.kpn.net] has joined #code
17:52
<&[R]>
Thanks TF! I was sure some other functional language would have made it for whatever reason
17:52 * [R] is curious what clojure needs constantly's for though
17:55
<&[R]>
I guess the other way to do it would have the function behave as if it were curried (not the constantly function, but the ones that need it to recieve more than one list)
18:06
<&ToxicFrog>
As for what it's used for -- rummaging through my code, I mostly seem to use it in places where some API requires a filter function that I'm not using (so (constantly true) instead), or when using updater APIs where I don't care about the old value
18:07
<&ToxicFrog>
Although I think some places where I've used updaters there's an equivalent setter, e.g. reset! instead of swap!
18:07
<&ToxicFrog>
or assoc-in instead of update-in
18:07
<&[R]>
Ah, those would make sense
18:09
<&ToxicFrog>
(for a concrete example of the filter usage, I worked on a multiplayer game where log events could have functions attached to them to determine which players they were visible to; (constantly true) gives you an event that is unconditionally visible to all players, and a set of players (since sets are functions over the domain of their elements) makes it visible to exactly that set)
18:10
<&ToxicFrog>
So, it's not something that I use constantly (hah) but it's useful enough that I'd probably end up defining it myself if it weren't built in.
18:38
<&[R]>
Good to know, still learning that I'm going to need to think about problems differently
18:38
<&[R]>
https://fossunleashed.xiennith.com/2023/12/11/xs-two-lists/ <-- my notes on the subject
18:46
<&ToxicFrog>
I think that does count as currying, since currying is exactly the translation from a function of arity n to a function that returns successively nested functions of arity 1 (with the last one returning the computed return value), which is what you're doing there with the first vs. second implementations of common
18:47
<&ToxicFrog>
It's not something the language is doing for you automatically the way Haskell does, but it doesn't have to be a language builtin to be conceptually valid.
18:49
<&[R]>
Just with the way that it handles lists/arguments I feel that makes it not currying
18:52
<&[R]>
Arguments are always put into a list then unpacked, so to have a function that needs a single argument, one would protect it by {|x junk| ...} so that if multiple arguments were passed the excess would end up in $junk
18:52
<&[R]>
If you just had {|x| ...} and passed multiple values, $x would be a list of all the arguments.
18:52
<&ToxicFrog>
Aah
18:53
<&[R]>
A variable is always a list
18:54
<&ToxicFrog>
This sounds like there is room for philosophical argument between "all functions are n-arity" and "all functions are 1-arity (and that one argument is a list, which may be destructured)"
18:54
<&[R]>
Setting a variable to an empty list will unset it, an unset variable is a 0-length list
18:54
<&[R]>
Yeah
19:03
<&ToxicFrog>
So whether it is currying or not depends on where one falls in that debate
19:04
<&[R]>
Yeah
19:05
<&[R]>
Not thinking of fragments as taking a condensed list of the arguments is a good way to write something that has a bug due to XS not behaving in a way you'd expect
19:05 * [R] has been burned enough by that, that he just constantly keeps in mind how XS handles arguments
19:07
<&ToxicFrog>
Given that, it's probably best to think of all functions in xs as being 1-arity functions over the domain of lists, with a convenient destructuring syntax
19:07
<&[R]>
Yeah
19:08
<&ToxicFrog>
In which case this is definitely currying :P
19:09
<&[R]>
:p
19:13
<&[R]>
I should really poke at `es` and see how different it is
19:14
<&[R]>
(XS is descended from es, which is descended from the rc shell from plan9)
19:17
<&[R]>
Anyways, thank you for your help TF
19:18
<&ToxicFrog>
You're welcome!
20:50 himi [sjjf@Nightstar-o4k.pal.170.103.IP] has quit [Ping timeout: 121 seconds]
21:19 Vornicus [Vorn@Nightstar-ivektl.res.spectrum.com] has quit [Connection closed]
21:27 panzerfaus [uid279771@Nightstar-l49s2t.irccloud.com] has joined #code
22:02 himi [sjjf@Nightstar-1drtbs.anu.edu.au] has joined #code
22:02 mode/#code [+o himi] by ChanServ
22:55 Emmy [Emmy@Nightstar-qo29c7.fixed.kpn.net] has quit [Connection reset by peer]
--- Log closed Tue Dec 12 00:00:32 2023
code logs -> 2023 -> Mon, 11 Dec 2023< code.20231210.log - code.20231212.log >

[ Latest log file ]