Leonidas changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 4.13.0 released: https://ocaml.org/releases/4.13.0.html | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
rgrinberg has quit [Ping timeout: 256 seconds]
Tuplanolla has quit [Quit: Leaving.]
<d_bot> <NULL> How recently if you remember ?
chrisz has joined #ocaml
<companion_cube> Hmm I'm probably wrong but I think around 4.03
glassofethanol has quit [Quit: leaving]
glassofethanol has joined #ocaml
xd1le has joined #ocaml
Anarchos has quit [Quit: Vision[]: i've been blurred!]
Corbin has quit [Ping timeout: 256 seconds]
glassofethanol has quit [Quit: leaving]
rgrinberg has joined #ocaml
Haudegen has quit [Ping timeout: 252 seconds]
rgrinberg has quit [Ping timeout: 256 seconds]
rgrinberg has joined #ocaml
zebrag has quit [Quit: Konversation terminated!]
namkeleser has quit [Ping timeout: 256 seconds]
abraham has left #ocaml [The Lounge - https://thelounge.chat]
rgrinberg has quit [Ping timeout: 256 seconds]
rgrinberg has joined #ocaml
namkeleser has joined #ocaml
zebrag has joined #ocaml
dstein64- has joined #ocaml
dstein64 has quit [Ping timeout: 260 seconds]
dstein64- is now known as dstein64
rgrinberg has quit [Ping timeout: 252 seconds]
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 252 seconds]
xiongxin has joined #ocaml
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 256 seconds]
waleee has quit [Ping timeout: 252 seconds]
rgrinberg has joined #ocaml
zebrag has quit [Quit: Konversation terminated!]
namkeleser has quit [Quit: Client closed]
rgrinberg has quit [Ping timeout: 252 seconds]
rgrinberg has joined #ocaml
mbuf has joined #ocaml
rgrinberg has quit [Read error: Connection reset by peer]
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 252 seconds]
namkeleser has joined #ocaml
xiongxin1 has joined #ocaml
xiongxin has quit [Ping timeout: 256 seconds]
xiongxin1 is now known as xiongxin
wwilly has joined #ocaml
Techcable has quit [Ping timeout: 256 seconds]
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 256 seconds]
wwilly has quit [Remote host closed the connection]
wwilly has joined #ocaml
rgrinberg has joined #ocaml
shawnw has joined #ocaml
rgrinberg has quit [Ping timeout: 256 seconds]
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 256 seconds]
Serpent7776 has joined #ocaml
wwilly has quit [Ping timeout: 256 seconds]
rgrinberg has joined #ocaml
chrisz has quit [Quit: leaving]
rgrinberg has quit [Ping timeout: 252 seconds]
wwilly has joined #ocaml
Techcable has joined #ocaml
Tuplanolla has joined #ocaml
wwilly has quit [Ping timeout: 252 seconds]
bartholin has joined #ocaml
wwilly has joined #ocaml
bronsen has quit [Quit: WeeChat 3.3]
bronsen has joined #ocaml
Anarchos has joined #ocaml
Anarchos has quit [Quit: Vision[]: i've been blurred!]
olle_ has joined #ocaml
mro has joined #ocaml
bartholin has quit [Ping timeout: 256 seconds]
bartholin has joined #ocaml
mro has quit [Remote host closed the connection]
waleee has joined #ocaml
mro has joined #ocaml
mro has quit [Remote host closed the connection]
spip has joined #ocaml
spip is now known as Guest9898
Haudegen has joined #ocaml
Goldstein has joined #ocaml
namkeleser has quit [Ping timeout: 256 seconds]
<Goldstein> Hi! I'm trying to learn some OCaml by solving Advent of Code puzzle. I've written a working solution of Python, but after rewriting it to OCaml it started giving wrong answers. I can't find the difference between two solutions (except language, of course): https://gist.github.com/GoldsteinE/d0a324844871f7d70687bf932aaf2662
<Goldstein> Somehow OCaml version gives higher answer than Python version
gravicappa has joined #ocaml
<d_bot> <antron> Goldstein: im not able to eyeball it. can only suggest finding a small example where there is a difference
<Goldstein> Yeah, I'm trying to craft a minimal input that breaks the solution, but no luck so far
<d_bot> <antron> but i do recommend using `Hashtbl.replace` (<https://ocaml.org/api/Hashtbl.html#VALreplace>) rather than `Hashtbl.add`, `add` masks the previous binding but does not replace it
<d_bot> <andreypopp> was just about to point about `Hashtbl.add`!
<Armael> that might be it! because then the fold will iterate over the several bindings
<Goldstein> Thanks! Hashtbl.replace solves the problem. I'm going to re-read Hashtbl documentation
<d_bot> <antron> Armael, wow, i didn't realize it would do that
<d_bot> <antron> i do use Hashtbl.replace consistently these days, but now im horrified about my usage of Hashtbl.add back in the day
<d_bot> <andreypopp> I remember I was stumbled upon that when was learning OCaml
<d_bot> <andreypopp> the good thing `Base.Hashtbl.add` returns `Ok | Duplicate` and I use `Base` now mostly
bartholin has quit [Ping timeout: 252 seconds]
bartholin has joined #ocaml
<d_bot> <VPhantom> Yeah it's odd that `add` effectively stacks. I was bitten by that one too.
<d_bot> <leviroth> I'm a tad horrified that `Hashtbl.add` does that.
<qwr> there is Hashtbl.replace
<qwr> the add is actually useful somethimes and is probably done to use/expose internal separate chaining, though might have been clearer with 'a list Hashtbl.t
<d_bot> <leviroth> yeah, exactly, I'm sure a hashtable where the values are stacks is useful sometimes, but you can just do that explicitly
<d_bot> <leviroth> Is there any other language where, immediately after removing a key from the default hashtable data structure, the key can still be present?
glassofethanol has joined #ocaml
rgrinberg has joined #ocaml
zebrag has joined #ocaml
glassofethanol has quit [Quit: leaving]
glassofethanol has joined #ocaml
rgrinberg has quit [Ping timeout: 256 seconds]
bartholin has quit [Ping timeout: 256 seconds]
Corbin has joined #ocaml
unyu has quit [Quit: WeeChat 3.3]
unyu has joined #ocaml
olle_ has quit [Ping timeout: 256 seconds]
rgrinberg has joined #ocaml
xiongxin has quit [Quit: xiongxin]
glassofethanol has quit [Remote host closed the connection]
<d_bot> <VPhantom> I guess that's why it's called `remove` and not `delete` or `unset`.
<d_bot> <VPhantom> But yeah it probably should be made clearer from very early on in the documentation that it's a hash of stacks.
rgrinberg has quit [Ping timeout: 256 seconds]
bgs has quit [Ping timeout: 256 seconds]
bartholin has joined #ocaml
bgs has joined #ocaml
xd1le has quit [Quit: xd1le]
gzj has joined #ocaml
<d_bot> <VPhantom> A pull request in OCaml itself? 😱 I am just a rookie. 😛
<d_bot> <Et7f3> > Previous bindings for [key] are not removed, but simply
<d_bot> <Et7f3> > hidden
<d_bot> <VPhantom> Yes. Actually `add` describes the stack behavior very clearly (which is how I knew to search for something else, and found `replace`). That said, I don't see an equivalent for `remove` which would remove everything at the key. 🤔
gzj has quit [Remote host closed the connection]
rgrinberg has joined #ocaml
mro has joined #ocaml
<d_bot> <Et7f3> useful for a compiler: When you see a variable just add it to env and when you go out of scope you have a list of variable added at that scope you can remove
<d_bot> <VPhantom> Instead of managing a hash table per scope and search through each one from closest to furthest. Clever.
<d_bot> <NULL> Or you use an immutable structure
<d_bot> <VPhantom> I was thinking about `Map` or something for that, yeah.
<d_bot> <Et7f3> it become log(depth)*log(mean var per level)
<d_bot> <Et7f3> so a bit slower
<d_bot> <VPhantom> (The more I use OCaml, the more I realize it's the language I always wanted but never knew existed until just a couple years ago.)
<d_bot> <NULL> "mean var per level" ?
<d_bot> <Et7f3> moyenne de variable par niveau 🤷
<d_bot> <NULL> Doesn't help
<d_bot> <VPhantom> Still, I'm surprised there's no `Hashtbl.remove_all` which would remove a key (vs `remove` which just pops).
<d_bot> <Et7f3> number of variables/depth
rgrinberg has quit [Ping timeout: 256 seconds]
<d_bot> <VPhantom> Average number of symbols per scope, I think? Yeah.
<d_bot> <Et7f3> Yes thanks
<d_bot> <NULL> Why would it not be `log(nb_vars)` total ?
<d_bot> <Et7f3> You repeat the lookup in many small maps so it has *
<d_bot> <VPhantom> Hm, yeah there would always be just one `Map` to search, the inner scope's.
<d_bot> <NULL> ^ single map
<d_bot> <NULL> That's also why it's comfortable, you only have a single environment
<d_bot> <Et7f3> let global = 4
<d_bot> <Et7f3> let fx x = x + global
<d_bot> <VPhantom> Maps are immutable, so you'd have a local copy with local variables, if you will, as you create inner scopes.
<d_bot> <NULL> That's a closure, you completely swap out your environment
<d_bot> <Et7f3> one map with global one with x and when you goes out of fx you need to recover your old env
<d_bot> <VPhantom> Oh, closures. 🤔
<d_bot> <VPhantom> The scope of `fx` would simply be kept. If `global` changed after its creation, it would still be `4` in that scope.
rgrinberg has joined #ocaml
<d_bot> <Et7f3> well depend of implementation: You either copy all bindings or you have a tree structure and lookup is slower
<d_bot> <NULL> (`global` can't change)
<d_bot> <leviroth> Simply call `remove` and `mem` in a loop. Or for an O(1) solution, use `Hashtbl.replace table key (Obj.magic ())` and pray to the runtime gods.
<d_bot> <NULL> Well it's immutable, you "copy" at 0 cost
<d_bot> <Et7f3> but then how you handle: ```
<d_bot> <Et7f3> let global = 4
<d_bot> <Et7f3> let fx x =
<d_bot> <Et7f3> let global = 3 in
<d_bot> <Et7f3> global + x
<d_bot> <Et7f3> ```
<d_bot> <NULL> Not the same var
<d_bot> <VPhantom> Yeah I was thinking of `replace ; remove` (didn't know about the magic trick). Depending on the implementation of `replace`, it could be more efficient than a loop of `remove`.
<d_bot> <NULL> You shadow the outer `global` with your inner one
<d_bot> <Et7f3> Yes but for a compiler how do you differentiate both (you need two "global" stored)
<d_bot> <VPhantom> Your `fx` would have to carry with it the scope as it was when it was declared.
<d_bot> <leviroth> To be clear, I'm not sure it's actually safe to use `Obj.magic` here; it might cause segfaults or worse problems depending on implementation details of the compiler.
<d_bot> <VPhantom> Yeah my take-away as a rookie was "know it exists, but never touch it". 😛
<d_bot> <NULL> You can do some name disambiguation by adding info in the name (or use more than the name as index to your env)
<d_bot> <leviroth> I'd be surprised if `replace` were not O(1), but I guess it's not the first time I'd be surprised today.
<d_bot> <VPhantom> I'm mostly surprised to be chatting about OCaml on my first day off in several weeks. I should go for a walk, or something. 😉
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<d_bot> <Et7f3> Wait but we have a #compilers channel
<d_bot> <NULL> We do
<d_bot> <Et7f3> I propose we move here
olle_ has joined #ocaml
<Franciman> which garbage collection strategy does ocaml use?
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 245 seconds]
rgrinberg has joined #ocaml
oriba has joined #ocaml
mro has quit [Remote host closed the connection]
bartholin has quit [Ping timeout: 252 seconds]
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bartholin has joined #ocaml
<d_bot> <hcarty> https://dev.realworldocaml.org/garbage-collector.html has a decent description. Generational mark and sweep with big changes to enable parallel collection coming in OCaml 5.x. Someone with GC expertise could give a more precise answer!
rgrinberg has joined #ocaml
<Franciman> thanks a lot @hcarty
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
olle_ has quit [Ping timeout: 256 seconds]
mro has joined #ocaml
rgrinberg has quit [Ping timeout: 256 seconds]
mro has quit [Remote host closed the connection]
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 252 seconds]
gareppa has joined #ocaml
gareppa has quit [Remote host closed the connection]
mro has joined #ocaml
mbuf has quit [Quit: Leaving]
mro has quit [Remote host closed the connection]
bartholin has quit [Ping timeout: 256 seconds]
rgrinberg has joined #ocaml
wwilly_ has joined #ocaml
gravicappa has quit [Ping timeout: 256 seconds]
shawn has joined #ocaml
gahr_ has joined #ocaml
gahr has quit [Read error: Connection reset by peer]
bgs has quit [Ping timeout: 256 seconds]
Techcable has quit [Quit: ZNC - https://znc.in]
Techcable_ has joined #ocaml
bartholin has joined #ocaml
<d_bot> <VPhantom> Wasn't there already a significant change this past year? A new algorithm which performed mostly better, was optional at first… I don't remember exactly what. 🤔
bgs has joined #ocaml
wwilly has quit [Ping timeout: 256 seconds]
shawnw has quit [Ping timeout: 256 seconds]
rgrinberg has quit [Ping timeout: 252 seconds]
mro has joined #ocaml
<d_bot> <quernd> Next-fit allocation policy is now default since 4.13
olle_ has joined #ocaml
<d_bot> <quernd> Best-fit, I mean. Next-fit was default before
<d_bot> <JulesHastings200> merci !
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
Haudegen has joined #ocaml
gravicappa has joined #ocaml
rgrinberg has joined #ocaml
gravicappa has quit [Ping timeout: 256 seconds]
rgrinberg has quit [Ping timeout: 245 seconds]
rgrinberg has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bartholin has quit [Ping timeout: 268 seconds]
jonasbits has quit [Ping timeout: 268 seconds]
oriba has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
bartholin has joined #ocaml
grobe0ba has quit [Read error: Connection reset by peer]
grobe0ba_ has joined #ocaml
grobe0ba_ is now known as grobe0ba
rgrinberg has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jonasbits has joined #ocaml
Tuplanolla has quit [Ping timeout: 252 seconds]
Goldstein has quit [Ping timeout: 252 seconds]
bartholin has quit [Quit: Leaving]
rgrinberg has joined #ocaml
jakzale has quit [Changing host]
jakzale has joined #ocaml
Tuplanolla has joined #ocaml
Lycurgus has joined #ocaml
olle_ has quit [Ping timeout: 256 seconds]
mro has quit [Quit: Leaving...]
jonasbits has quit [Ping timeout: 252 seconds]
Haudegen has quit [Ping timeout: 252 seconds]
jonasbits has joined #ocaml