<FromGitter>
<johnjansen> now there is some trickery going on here involving a proc within the each etc etc, but in essence the ‘i’ from that block was clearly colliding with the var of the same name from the level above … my stupid fault … but it does seem like there is something happening that i dont yet fully understand (like the type of ‘i’ is locked as Bool)
<FromGitter>
<johnjansen> im willing to bet you have something similar with a var of type `Int32` who’s name you are sharing somewhere with something you later assign a `Pointer(BucketList::Bucket(Pointer(Void)))` to, possibly in what you would think to be another scope
<Papierkorb>
Wish I knew, those are all @@class_vars
<FromGitter>
<johnjansen> using a proc anywhere?
<Papierkorb>
BucketList isn't, no, and that's the only place where those are assigned
<FromGitter>
<johnjansen> crap i got it the wrong way roung
<FromGitter>
<johnjansen> -g+d
<FromGitter>
<johnjansen> you’ve got a `Pointer(BucketList::Bucket(Pointer(Void)))` that you are trying to assign an `Int32` to
<FromGitter>
<johnjansen> the messages are backward i think
<Papierkorb>
`SIZE = sizeof(UInt16) * 8` invalid constant value. Are you kidding me.
<FromGitter>
<johnjansen> thats ok till you try to assign it
<FromGitter>
<johnjansen> — to a constant
<Papierkorb>
Using it as argument to StaticArray
<FromGitter>
<johnjansen> you cant even `StaticArray.new(Int32, (8*2)).new 0`
<Papierkorb>
I replaced the sizeof with `2` .. and now it works
<Papierkorb>
Yeah those rules are a bit crude
<FromGitter>
<johnjansen> im betting its because sizeof is not constant so it cant be assigned to a constant at compile time
<Papierkorb>
sizeof(UInt16) is probably the most constant thing after a literal you can get
<FromGitter>
<johnjansen> yeah … you might have to hard code that one ;-)
<FromGitter>
<johnjansen> or do `UINT16_SIZE = 2`
<FromGitter>
<johnjansen> unless that is defined somewhere?
Renich has quit [Quit: Renich]
<FromGitter>
<fridgerator> what is the syntax to load a shard from the local filesystem?
<FromGitter>
<elorest> Looks like it will be included in the stdlib eventually.
<FromGitter>
<johnjansen> no @fridgerator but i believe you can over FTP
<FromGitter>
<drosehn> macOS also has the `dscl` command, although you need to have some idea of how the Directory Service is set up. Or at least all my Macs have that, I'm not sure if the `dscl` command still exists in Sierra or High Sierra.
<FromGitter>
<johnjansen> ;-)
<FromGitter>
<johnjansen> JOKE
<FromGitter>
<fridgerator> lol
<FromGitter>
<drosehn> On my mac, I have a userid 'gad'. I can see that it exists via: `dscl . -list /Users | grep gad`, and I can see all the directory-information associated with 'gad' via the command: `dscl . -read /Users/gad` (which is about a megabyte of information)
<FromGitter>
<elorest> @fridgerator Yes you an load over samba as long as the remote drive already has a mountpoint on your OS>
<FromGitter>
<elorest> Probably this sort of seems like the kind of thing that should be native.
<FromGitter>
<johnjansen> i agree, but dont have the time
<FromGitter>
<johnjansen> :-)
<FromGitter>
<drosehn> You can also ask for specific items, such as: `dscl . -read /Users/gad RealName UserShell`. If anyone's interested, that should be enough to point you in the right direction.
<FromGitter>
<elorest> It would probably be really easy to wrap the `ftp` command in terminal.
<FromGitter>
<elorest> just send system calls to it for now
<FromGitter>
<fridgerator> thanks guys!! I was just joking about the samba thing though
<FromGitter>
<elorest> Dangit. I thought you were serious. I tested it and everything.
<FromGitter>
<johnjansen> lol … glad i didnt bother looking into it then
<FromGitter>
<johnjansen> haha
<FromGitter>
<johnjansen> bad @fridgerator !
<FromGitter>
<fridgerator> hhahaha
<FromGitter>
<elorest> Well now you know.
<FromGitter>
<fridgerator> my bad
<FromGitter>
<fridgerator> I was trying to throw something rediculous out there
<FromGitter>
<fridgerator> but you guy showed me
<FromGitter>
<elorest> If I hadn't been working with nfs a lot at my day job I probably wouldn't have thought you were serious. 🔥
<FromGitter>
<drosehn> [going back a few hours] wrt Base64 vs Base91 vs Base122, there's also the Ascii85 format implemented by the `btoa` command written by Paul Rutter, Joe Orost & Stefan Parmark. It's also somewhat interesting note that crystal's `Int.to_s`includes support for base62.
<FromGitter>
<drosehn> (while the earlier Ascii85 has implementations in 8-10 languages)
<FromGitter>
<johnjansen> @drosehn you are not just going back a few hours, but a few years with your knowledge
<FromGitter>
<johnjansen> Ascii85 is interesting … im sure the 6 people who used it, loved it at the time ;-)
<FromGitter>
<johnjansen> im joking again
<FromGitter>
<drosehn> Well, @elorest was talking about Base91 vs Base122 about six hours ago, and I'm just catching up. That reminded me that at one point I used the `btoa` command to encode some binary data which was being sent through ascii email (and had to fix a bug in it wrt 32-bit vs 64-bit platforms).
<FromGitter>
<johnjansen> he was indeed
greengriminal has joined #crystal-lang
<FromGitter>
<drosehn> So here it is, the first time in weeks that I've had any spare time to look at crystal, and the first thing I do is dream up yet-another project to add to my never-ending list of interesting projects.
<FromGitter>
<johnjansen> what did tou dream up
<FromGitter>
<drosehn> implementing all of these in crystal, obviously!
<FromGitter>
<drosehn> I've been looking at `Int.to_s` for other reasons, and this topic kinda dovetails in with that.
<FromGitter>
<johnjansen> add them to the issues in crystal-libraries-needed so we know about them
<FromGitter>
<johnjansen> i have a feeling @elorest might start on the one he was talking about earlier .. 91? or close
<FromGitter>
<johnjansen> dont know about the query part, or obviously, if data is actually json, or if query one is falsy if it doesnt find something, ⏎ but what i do know is your method returns `(String | Bool)`, `(String|Nil)` might be preferable
<FromGitter>
<watzon> @johnjansen out of curiosity is that custom `ls` command available for download? Haha
<FromGitter>
<johnjansen> @watzon it will be eventually … at least thats the plan, in the meantime you could pull the repo and build it
<FromGitter>
<watzon> Awesome 😁 I’m gonna do just that
<FromGitter>
<johnjansen> its called `lsr`
<FromGitter>
<johnjansen> regex per path segment
<FromGitter>
<watzon> Also, hello everyone! 👋 I’ve been inactive here for a while, but I’m going to hopefully start making some PRs again in the near future
<FromGitter>
<johnjansen> accepting PR’s ;-)
<FromGitter>
<johnjansen> oh and @watzon for now you need a minimum of the `-l` flag to see anything
<FromGitter>
<johnjansen> early days
<FromGitter>
<elorest> @drosehn does btoa exist in Crystal.
<FromGitter>
<watzon> @johnjansen what still needs to be added?
<FromGitter>
<johnjansen> take a look at the option parser for # TODO’s plus its really just thrown together right now, so re-organize, but the primary thing is a default (short) view, with just file names, in columns as per vanilla `ls`
<FromGitter>
<johnjansen> its very handy already though (at least for me)
<FromGitter>
<confact> Hi guys! i am new here. I am planning to write some ML stuff in crystal :)
<FromGitter>
<drosehn> [btoa exists] ah. thanks for the info.
<FromGitter>
<drosehn> er, wait, maybe I misunderstood what you wrote. did you mean that `btoa` does already exist? or were you asking a question about it?
<FromGitter>
<johnjansen> @drosehn he was asking a question
<FromGitter>
<watzon> Can `shards.yml` include c and c++ dependencies? Or how does that work?
<FromGitter>
<elorest> could you link me to a btoa crystal implementation.
<FromGitter>
<watzon> @johnjansen I don't think it gives any info in there about where to include the `c` libraries though. Or do they just have to be installed on the machine?
<FromGitter>
<johnjansen> man you (@elorest) and @drosehn are totally off the reservation ;-) … ⏎ so @elorest (my friend), there is no `btoa` implementation in crystal, both you and @drosehn are both asking not offering ;-)
<FromGitter>
<elorest> Ok. I thought @drosehn said he had used it with crystal.
<FromGitter>
<johnjansen> @watzon ive avoided getting into this, so i cant offer anything useful, @elorest might remember the details … i think i was asleep when that was being discussed
<FromGitter>
<elorest> shards.yml can't include c or c++ deps. It could however include crystal deps that wrap clibs. You could also run a make file or other script after shard install do install the clib if necessary.
<FromGitter>
<johnjansen> @elorest im wondering if there is anything in the code camp slides?
<FromGitter>
<elorest> You'd have to test that it worked everywhere though so it's probably better just to tell the user to make sure it's installed.
<FromGitter>
<johnjansen> im going to be you need them installed
<FromGitter>
<drosehn> Sorry that I gave the wrong impression. Your comments on base91 got me thinking of the `btoa` program which is written in C, and I couldn't remember what "base" was used for `btoa`. I just remembered that I came across it while looking for something better than base64.
<FromGitter>
<elorest> That's a handy comparison chart.
<FromGitter>
<johnjansen> dont know how useful they will be
<FromGitter>
<drosehn> But then I checked the wikipedia page on binary-to-text encoding, and got to thinking how it'd be nice to have all of those implemented in crystal.
<FromGitter>
<watzon> @johnjansen there doesn't happen to be a video of that presentation being given, is there?
<FromGitter>
<elorest> No.
<FromGitter>
<elorest> If you know C then creating cbinding is pretty easy. If you don't then you'll have to look at the code and google a lot of stuff.
<FromGitter>
<watzon> Interesting. In a real world scenario that would probably be done with a Makefile though right?
<FromGitter>
<watzon> I am definitely a `c`/`c++` beginner
<FromGitter>
<elorest> there are a lot of real world scenarios that don't use makefiles but yes that would be a good way to do it.
<FromGitter>
<watzon> Anyone have a good example of a shard that wraps a c++ library? I feel like it would help if I could look at a real implementation
balduin has quit [Ping timeout: 240 seconds]
balduin has joined #crystal-lang
<oprypin>
johnjansen, CrSFML has FTP lol but it's silly to use for that
<FromGitter>
<johnjansen> @oprypin extracting it might not be a bad idea
<oprypin>
watzon, yep https://github.com/oprypin/crsfml it is but it's a bit crazy in not making proper C bindings, just hiding the bare minimum like c++ name mangling and c++ standard library
<oprypin>
johnjansen, extracting? nah it's a shitty c++ implementation, not worth it
<FromGitter>
<codenoid> is crystal have telegram group ?
<oprypin>
hopefully not. never heard of such a group.
<FromGitter>
<elorest> The ruby one is almost definitely the easiest to port.
<oprypin>
elorest, hardcoding gcc and ldflags is nice and all but i hate how people just ignore Windows
<oprypin>
and Makefile also doesn't help
<oprypin>
y'all need some CMake
<FromGitter>
<elorest> Windows is coming back on into the mix and we’ll all figure that out. For years though windows tied it’s self to the .net ide for all development. They’ve made a lot of positive changes lately though.
<oprypin>
watzon, generally i would say the C lib has to be already installed, but sometimes people bundle the lib, that seems fragile to me though
<oprypin>
if you're a C beginner, binding a C++ library would be a nightmare for sure
<oprypin>
not suitable for a first Crystal project either
<FromGitter>
<konovod> Just to clarify - there are C++ libraries with C interface though. So, @watzon, if you are talking about library with C++-interface - it's a nightmare like @oprypin says. If the library have C interface - wrapping is easy, no matter what is underlying language.
<FromGitter>
<bararchy> did I just crashed the Regex engine ?
<FromGitter>
<sdogruyol> lol
<FromGitter>
<sdogruyol> pcre went wild
hightower2 has quit [Ping timeout: 260 seconds]
rohitpaulk has quit [Ping timeout: 240 seconds]
fazibear has joined #crystal-lang
hightower2 has joined #crystal-lang
fazibear has quit [Ping timeout: 248 seconds]
Groogy has quit [Quit: WeeChat 1.7.1]
Groogy has joined #crystal-lang
fenicks has left #crystal-lang [#crystal-lang]
greengriminal has joined #crystal-lang
<FromGitter>
<akzhan> @sdogruyol implementation of yet another regexp engine has not only benefits. And anyway Rust regex doesn’t support backreferences etc. It’s not easy at all.
<FromGitter>
<sdogruyol> yeah, it's hard
Philpax has joined #crystal-lang
<FromGitter>
<akzhan> All we need is just to switch to Onigmo that’s built into Ruby. ⏎ Or to enable PCRE PCRE_UCP, but I don’t know how :)
<Groogy>
do you guys use regexps on a regular basis in production code? I've always imagined regexp as ultra slow?
<Groogy>
though I have nothing to base that fact on, just something I've assumed for a long time
<Groogy>
because change is scary
<FromGitter>
<akzhan> Exgexps are great for text processing at all. They are built into a lot of languages.
<Groogy>
I know was just curious about speed
<FromGitter>
<straight-shoota> And they are way easier than writing a custom string matcher/parser, but obviously much slower.
<Groogy>
I use them a lot in text documents when I am replacing a lot of stuff in it so I don't have to do it manually
<FromGitter>
<straight-shoota> But I think in many applications the potential speed gain is not worth the effort to switch to something else.
<FromGitter>
<akzhan> Regexps are fast. With precompilation they sometimes better than hand writing code :)
<Groogy>
Right can the compiler in crystal optimize the expression somewhat if it is known at compile time?
<FromGitter>
<sdogruyol> LLVM should be smart to do that :P
<FromGitter>
<straight-shoota> I don't think so
<FromGitter>
<akzhan> No, it’s LLVM task.
<Groogy>
Well is it a builtin type in LLVM?
<Groogy>
otherwise how would LLVM know what it is to optimize it?
<Groogy>
(mind you I do not know much about LLVM)
<Papierkorb>
don't we use libPCRE? How should LLVM suddenly optimize a shared library?
<FromGitter>
<akzhan> Crystal compiler is very non optimized. But it should be task after 1.0. ⏎ ⏎ LLVM optimizes only known patterns with POD type etc.
<Papierkorb>
..huh?
<FromGitter>
<straight-shoota> regexps are handled by libpcre, not llvm
<Papierkorb>
LLVMs optimization is ridicolously good, not exactly on the level of GCC, but really good
<Papierkorb>
Far better than anything we'd be able to write till 1.0 or whatever.
<FromGitter>
<akzhan> But for now Crystal in benchmarks looks as fast as C, and faster than Go etc.
<Groogy>
I know, we have a file in our project that Clang will try and optimize the shit out off
<Groogy>
so in non-release mode we have to disable optimizations of that file
<Groogy>
becuase it takes 45 minutes or some such
<Papierkorb>
Look at disassemblies of --release built binaries. For some algorithms, it managed to write x64 assembly that was shorter line-wise than my Crystal code. That's insane.
<Groogy>
ow yah is there any OpenGL based libraries for Crystal?
<Groogy>
like UI or some such=
<Groogy>
I looked before and didn't find anything that seemed.... eh complete?
<FromGitter>
<akzhan> Crystal-gl, crystal-raw-gl
greengriminal has quit [Quit: This computer has gone to sleep]
<Groogy>
no didn't mean opengl bindings :/
<Groogy>
mean like, library that implements drawing a sprite, drawing a button, etc.
<Groogy>
or do I need to reinvent that wheel?
<Papierkorb>
CrSFML
<Papierkorb>
And Crystal is young and UI is terribly complex.
<Papierkorb>
Someone has to do that dirty work.
<Groogy>
meh I could port my naive C++ GUI library
<Groogy>
think I can do it easier with features in Crystal
<Papierkorb>
[14:12] <Papierkorb> CrSFML
<Groogy>
no I need a clean OpenGL environment
<Groogy>
SFML needs 2.0 and will kind of wreck the environment unless oyu actually push and pop manually the stack
<Groogy>
i.e if you combine sfml-graphics with custom OpenGL, you are gonna have a lot of headaches
<Groogy>
(not blaming SFML mind you, it's just how OpenGL is built)
<FromGitter>
<akzhan> @groogy just google for "crystal lang opengl". ⏎ ⏎ But anyway OpenGL ES is ok, for OpenGL for desktops is something old and supercedes with Vulcan.
Philpax has quit [Ping timeout: 260 seconds]
<Groogy>
Eh no actually vulcan doesn't replace OpenGL like DirectX12 replaces 11
<Groogy>
Have you tried using Vulcan :P
<Groogy>
to be clear with what I mean is, OpenGL is gonna continue to see plenty of use in the future because of the nature of Vulcan API
<FromGitter>
<konovod> > SFML needs 2.0
<FromGitter>
<konovod> So you need OpenGL 1.0 GUI library? Then library will have a limited use imho.
<FromGitter>
<akzhan> I’m work for computer game company but a’m backender :) some people already used Vulcan with Unity.
<Groogy>
What no
<Groogy>
I would be working with 4.x konovod
<Groogy>
but SFML turns on the compability context
<Groogy>
akzhan well they are never directly exposed to Vulcan
<Groogy>
if you are working with Unity you don't have to manage the command buffers manually I am pretty sure
<FromGitter>
<akzhan> Vulcan faster for 35% for one of the games just by switching of renderer
<Papierkorb>
They might as well use DirectX, not much would change for the developer
<FromGitter>
<akzhan> Of course )
<Groogy>
Yeah I am not saying that Vulkan isn't faster?
<Papierkorb>
Is that on Windows?
<Papierkorb>
Windows drivers are known for their awful OpenGL implementation, especially nvidia
<Groogy>
vulkan works on Windows as well yeah
<FromGitter>
<konovod> oh. Then it's strange, i was told that sfml is pretty useful even if you draw everything by yourself.
<Groogy>
Well point of vulkan and directx12 is the minimal driver implementation Papierkorb
<Papierkorb>
So if Vulkan is faster there, no big surprise really
<Groogy>
konovod it is
<Groogy>
but if you are doing 3D
<Groogy>
and you are combining 3D with their graphics package
<Groogy>
there is tons of "if's and buts"
<Papierkorb>
Groogy: Doesn't change the fact that the OpenGL layers of Windows drivers have been historically crippled to be much slower than it could have been
<FromGitter>
<konovod> with vulkan you need ~1000 lines to draw a triangle)
<Groogy>
no don't disagree with that
<Groogy>
What konovod said
<Groogy>
In Unity or similar you won't notice that
<Groogy>
If you are just one random guy trying to make something, Vulcan is not for you
<Groogy>
unless you have a middleware
<Groogy>
just want to be clear konovod, SFML is super good, I've been advocate for it forever and still am. Just pointing out it has it's own problems just like any other piece of software
rohitpaulk has joined #crystal-lang
<FromGitter>
<codenoid> ` crystal init app jihantoro.sd` == crystal made mistake to himself
<FromGitter>
<codenoid> can init app remove . (dot) on app name ?
<FromGitter>
<straight-shoota> Go compiles much faster than Crystal because it doesn't need a huge type inference algorithm and is way more optimized
<FromGitter>
<sdogruyol> yeah
<FromGitter>
<sdogruyol> that's why it provides a real-time like response time
<FromGitter>
<straight-shoota> yes
<Groogy>
I mean most C++ IDE's have an interactive console you can use while debugging
<Groogy>
that let's you run C++ code at runtime
<FromGitter>
<sdogruyol> @Groogy how come? Incremental compilation?
<Groogy>
¯\(°_o)/¯ haven't really looked into it
<Groogy>
I just use it a lot
<Groogy>
I mean when you think about it, you have bunch of memory, and if you have the debug data you can easily translate symbols into that memory and then the rest is just instructions to run
<Groogy>
it's probably "simpler" than we imagine
<Papierkorb>
Aw damn. johnjansen, I found the issue. finally.
<Papierkorb>
The code `def foo; yield('0', 0); end; foo{|_, _| }` crashes the compiler.
<Papierkorb>
Because _ isn't too special, and instead of complaining about duplicate argument names .. or whatever, really, the compiler crashes
<FromGitter>
<johnjansen> setting a constant with a variable
<FromGitter>
<bararchy> The error can be a "little" more clear about that lol
<FromGitter>
<johnjansen> haha yeah
<FromGitter>
<johnjansen> another one like this came up last night `SIZE = sizeof(UInt16) * 2` which all seems pretty constant, but seemingly is not when your then try to `AR = StaticArray(Int32, SIZE).new(0) # SIZE is 0 right now … who knows why`
<Papierkorb>
Is it for you? For me, the compiler didn't like `SIZE` at all there and complained (didn't crash though)
<FromGitter>
<johnjansen> @papierkorb, i got a better error report when i hacked around a bit …
<FromGitter>
<johnjansen> beautiful … and so tricky to spot
<Papierkorb>
The Haskell uni class fooled me into thinking that `_` was special in Crystal >_>
<FromGitter>
<sdogruyol> Why
<FromGitter>
<johnjansen> yeah `_` as a var name should have some special significance or be disallowed
<Papierkorb>
in Haskell, _ is truly special as in, the compiler ignores whatever it was. In Crystal, it's a perfectly fine symbol name and is not special apart from convention
<Papierkorb>
sdogruyol ^
<FromGitter>
<johnjansen> even though the approach is promoted, given these kinds of cryptic failures ensue
<Papierkorb>
I'm wondering if it would be possible to make the compiler make a guess where the issue is in the source code on a compiler crash. Would maybe speed up the process of finding the issue
<Papierkorb>
Took me ages to figure out my #find method itself was fine, and the issue had nothing to do with Pointer stuff
<FromGitter>
<johnjansen> @papierkorb https://crystal-lang.org/api/0.22.0/Number.html#static_array%28%2Anums%29-macro might be a handy starting point for a hack … `SIZE = sizeof(UInt16) * 2` works when i use that macro to create a staticarray
<Papierkorb>
johnjansen, that will work, yup. I did something similar in my code, `foo.as({{ @type }})` doesn't work, but if you enclose it in {%begin%}{%end%}, it works fine. Kinda funky how you can change the flow of the macro expansion vs. special-method resolution
<Papierkorb>
I mean good thing you can, but I wouldn't be surprised if others would find no solution there
<Papierkorb>
TL;DR: If macro code doesn't work, repeat adding begin/end until it works
<FromGitter>
<johnjansen> yeah thats kind of hard to explain even … its going to come up again … and again …
<oprypin>
johnjansen, OptionParser should be able to sort out `-lsA`
<Papierkorb>
macro Number.slice <- wat?
<FromGitter>
<johnjansen> @oprypin doesnt work from what i can see
<Papierkorb>
Surprised there's a special macro for that
<FromGitter>
<fridgerator> question about binding to a c library, only the `fun` definitions get bound?
<FromGitter>
<fridgerator> nvmd
<FromGitter>
<fridgerator> anyone here familiar with netcdf format?
hightower3 has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
mark_66 has quit [Remote host closed the connection]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 246 seconds]
rohitpaulk has joined #crystal-lang
balduin has joined #crystal-lang
<FromGitter>
<konovod> Actually, var `_` is already special - it can't be read. https://carc.in/#/r/2cxx
<hightower3>
Hiyo, what do I use in Crystal instead of Socket.gethostname?
<FromGitter>
<sdogruyol> that's still not available in STD
<FromGitter>
<johnjansen> ok, can someone point me in the right direction … ⏎ i want to read STDIN when my app starts, but exit if nothing is piped into it, as it stands it waits
<Groogy>
what's the crystal standard in project structure for files that should be distributed with the binary but is not source code or a binary?
<Groogy>
@johnjansen, #peak maybe?
<Groogy>
peek*
<FromGitter>
<johnjansen> tried that @Groogy … sorry
<RX14>
@johnjansen what's the usecase here?
<RX14>
you can detect if STDIN is a terminal with #tty?
<FromGitter>
<johnjansen> dont know if thats how it will be in the end … but yeah, kinda cool
<FromGitter>
<johnjansen> cron it and im almost done ;-)
<FromGitter>
<peterschols> Dear Crystalers, I wanted to let you know that we've just deployed our first Crystal app into production. The Crystal app is part of our genome analysis platform which is being used by geneticists worldwide to diagnose patients with rare genetic conditions. More info is available at http://www.diploid.com. ⏎ I want to thank all of you for developing Crystal, nurturing the Crystal community and last but
<RX14>
hightower3, time is precise to 1/10th of a microsecond
<RX14>
i.e. there are 10 time ticks in 1 microsecond
<RX14>
we've discussed nanosecond precision for Time but i'm not entirely sure it's worth it
<hightower3>
RX14, oh, of course, my bad. I was looking at the seeming unavailability of #usec or similar, to get the microsecond value
<hightower3>
but ticks/10 would sure work
<hightower3>
thanks
<RX14>
yeah it's kinda weird that it doesn't expose it
<RX14>
my latest PR actually adds Time::Span::TicksPerMicrosecond
<RX14>
so you should switch to ticks / Time::Span::TicksPerMicrosecond for portability going forwards
<RX14>
or at least leave a TODO
<RX14>
hopefully i'll get that change in next release
<FromGitter>
<fridgerator> @peterschols 👍
<Groogy>
can I from a value, access a subclass in it? I.e this is obv wrong but sense of what I am asking "obj.class::SubClass.new"
sz0 has joined #crystal-lang
<FromGitter>
<bew> Not sure it's possible, what's obj type(s)?
<Groogy>
Version
<Groogy>
class Version
<Groogy>
or wait no it's Struct nevermind
Ven has joined #crystal-lang
Ven is now known as Guest69722
Guest69722 is now known as Ven``
<FromGitter>
<paulcsmith> @peterschols That's awesome! Did you use Kemal?
<FromGitter>
<elorest> @peterschols That super cool.
<FromGitter>
<elorest> Any word on asterite disappearing from twitter yet? How are sourceforge donations split up now I wonder?
balduin has quit [Ping timeout: 258 seconds]
<Groogy>
hmm why can't I get a variable have less of a defined union type?
<oprypin>
> sourceforge
<Groogy>
i.e like an Array(Int32) become an Array(Int32 | Float64)
<oprypin>
Groogy, cuz nobody programmed that. and it's not obvious whether it even should be like that
<oprypin>
it can't become that because its memory layout is different, you'd need to copy it anyway
<Groogy>
hmm :/ THen I am curious how does the YAML::Any work?
<oprypin>
it has all those types programmed in in advance
<oprypin>
Groogy, from a value you cannot access a subclass in it
<Groogy>
yeah but I am trying to replicate similar behaviour, I've defined alias Type = Int32 | Float64 | String | Hash(Type, Type) | Array(Type) | Nil
<Groogy>
but it won't let me assign a Array(In532) to it
<oprypin>
anything preceding :: must be an uhh identifier starting with an uppercase letter
<oprypin>
Groogy, yes, it will not. as I was saying, these have an entirely different memory layout
<oprypin>
Array(Int32 | Float64) contains a sequence of 12-byte items typeid of 4 bytes and data of max(4, 8) bytes
<oprypin>
Array(Int32) contains a sequence of 4-byte items of data
<Groogy>
well it manages for String and array :/
<oprypin>
no it doesnt
<oprypin>
Groogy, anyhow, use [1, 2, 3] of Type
<oprypin>
or a = [1, 2, 3]; a.map &.as(Type)
<oprypin>
that will enable the expected memory layout, in the 2nd case by copying
<Groogy>
thanks
<oprypin>
Groogy, i keep blabbering about the memory layout - that's how i'm justifying the lack of this kind of cast, and why it seems to be impossible to reasonably implement, but i may just be missing something and i don't dismiss the possibility of this feature
<Groogy>
eh well it would be weird if it is an actual C style union in memory after compilation time
<Groogy>
I mean I rationalise it works like Templates, then you will just generate a new variant of the method on each type
<Groogy>
now to just convert it to YAML::Type, sigh
<oprypin>
Groogy, but hold on, you do realize that Crystal's unions are in fact exactly like actual C style unions in memory?
<Groogy>
the type unions?
<Groogy>
not the union unions
<oprypin>
yes
<Groogy>
I was refering to the type unions
<oprypin>
me too
<Groogy>
well that's kind of pointless?
<oprypin>
Groogy, uh these also store the type id. i forgot that it's not required to have that in C unions
<oprypin>
each type has a unique type id
<Groogy>
No type id's are for referenced objects only right?
<oprypin>
all types
<oprypin>
damn i gotta finish that article, now i have yet another thing to add to it
<FromGitter>
<renich> I think I've found a bug in playground. If you create a file in `playground/file.cr` and leave no new line at the end, when loading it through `crystal play > workbook` it will append "```" to the end of the last command.
<Groogy>
Eh you sure? Because I remember specifically reading about the SuperClass+ being the one with the type id?
<hightower3>
RX14, actually, looking at the microseconds thing, I basically need the microseconds value of Time.now.epoch_f (just the part after the dot)
<RX14>
Groogy, all unions (apart from Reference | Nil which is optimized as nullptr) are tagged with a type id
<RX14>
classes contain a type ID in their beinary representation too
<hightower3>
RX14, not sure how to best obtain that, e.g. if the #epoch_f gives 123.456789, I need "456789"
<RX14>
how else do you tell what the union represents
<Groogy>
until you add in polymorphism you can solve that by just solving variations of the functions. I just imagined every method in Crystal was a template function which would have the same effect
<Groogy>
which was why I thought the union of a SuperClass+ meant
<RX14>
what?
<RX14>
you realise which method to call is decided at runtime
<RX14>
not at compile time as with java and co
<RX14>
it's called dynamic dispatch
<RX14>
oh no
<RX14>
it's multiple dispatch
<RX14>
i'm clearly tired
<Groogy>
It doesn't do like D then which at compile times which methods need to be decided on runtime and which ones does not?
<Groogy>
i.e it will still resolve Int32.+ at runtime?
<RX14>
well yes of course
<RX14>
if there's no union it doesn't need to do multiple dispatch
<RX14>
and it's just a typical method call
<Groogy>
Yes same applies with how templates work in C++
<oprypin>
Groogy, you have to realize that C++ has nothing that's even close to Crystal's type unions
<oprypin>
other than actual unions, of course
<RX14>
doesn't C++ have tagged unions as a datatype in it's stdlib
<RX14>
i'd say thats clode
<RX14>
but obviously you need to dereference that manually
<Groogy>
It does, it's called templates, though they do not define specific types but it is possible to replicate similar behaviour in certain circumstances
<RX14>
so not close in utility
<oprypin>
Groogy, no, templates are not that
<Groogy>
You can get similar behaviour in C++ with templates is what I said
<oprypin>
you cannot
<RX14>
are you sure oprypin
<Groogy>
i.e I can create a function that will call the same function on vastly different types
<oprypin>
Groogy, and you have to know the exact type at compile time
<oprypin>
RX14, i am about 97% sure
<oprypin>
also no, c++ does not have tagged unions, you can just write your own adhoc type id as the first struct member
<RX14>
it doesn't have them as part of the language
<Groogy>
Yes? And the Crystal type inhference algorithm can deduce correct type from me just doing stuff like if var.is_a?(stuff)
<RX14>
but it's part of the stdlib
<RX14>
i'm pretty sure
<oprypin>
Groogy, so it can
<RX14>
yeah C++ will never be able to do that oprypin
<RX14>
if thats what you're saying
<oprypin>
and when it can't, e.g. when you have a variable of type (Array(Int32) | Int32) and call .to_s directly on it without is_a, that's when runtime type id checking comes in
<Groogy>
but you can reduce it to paths where the same function is being called where it is directly an int32 or an Array(Int32), how can it not reduce the type then like it does in C++? I.e generate the variations by itself like C++
<Groogy>
because that is what was happening for me
<Groogy>
right
<oprypin>
i have no idea what magical c++ feature you are talking about, you'd have to provide an example
<Groogy>
i.e the code I have written is qualified to work both with an Array(Int32) and an Int32, so for Crystal to allow me to just provide it with either an Int32 or an Array(Int32) and it should work
<Groogy>
but apparently it doesn't, I have to say it is a union of every type
<Groogy>
For C++ it would just have generated a variant of every instance that you call on it
<Groogy>
if it succeeds generating that is
<RX14>
yeah i'm very confused rn
<oprypin>
i'm convinced that only Groogy is confused
<RX14>
ah but i'm confused at what Groogy is confused about
<Groogy>
no
<RX14>
Groogy, what do you mean by "I have to say it is a union of every type"
<FromGitter>
<sdogruyol> lol :D
<RX14>
are you referring to crystal or C++ here
<Groogy>
Crystal
<oprypin>
Groogy, just provide any example where you think c++ does something that crystal can't, and we'll show you why that's not the case
<Groogy>
THe problem I had with YAML is that I had to make a Array(String) into a YAML::Type which includes the previous mentioned type
<oprypin>
(yes, c++'s runtime polymorphism may be more performant due to vtables, but that's about it)
<oprypin>
so why is it accepted as an argument if it's not a
<RX14>
there's an issue on this
<Groogy>
because is_a? is used to make the type more narrow I guess?
<Groogy>
ah
<RX14>
i think it's called covariance and contravariance
<RX14>
but i'm not sure if those are the right terms
<RX14>
is_a? uses the ivar definition of type
<Groogy>
it actually does a runtime check I guess
<RX14>
or actually no
<Groogy>
while the method is done in compile time
<RX14>
no not really
<RX14>
is_a? just turns into "is the type ID in this list" iirc
<RX14>
so its effectively compiletime
<RX14>
remember crystal has no vtables
<Groogy>
eh though it has to return true in runtime to know if that branch is to execute or not?
<Groogy>
if it is an ivar and don't know the value at compile time?
<RX14>
yes Groogy thats why i said it turns into a type_id lookup
<RX14>
the type_id lookup is at runtime
rohitpaulk has quit [Remote host closed the connection]
<RX14>
but the compiler knows the all the type ids which match
<RX14>
which means all the real logic is done at compile time
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
Ven is now known as Guest79280
Guest79280 has quit [Ping timeout: 260 seconds]
greengriminal has quit [Quit: This computer has gone to sleep]
<hightower3>
I have code like a, b = string.split(":"), but there might be no ":" in the String, in which case I get Index out of bounds error. What's the best/optimal way to prevent that? If there is no ":", b should be nil.
<Papierkorb>
Huh destructuring arrays?
<Papierkorb>
hightower3: Split, then check the arrays length, then fill a, b as wanted
<FromGitter>
<peterschols> @paulcsmith @elorest Thanks! ⏎ @paulcsmith We're not using Kemal for now, the Crystal app is used for backend genome analysis. We use Rails as a 'front-end' for the UI. We are looking into projects like Kemal or Amber though and we might use them in the future.
<oprypin>
interestingly enough the linking is broken
<Groogy>
it says it creates an array though?
<oprypin>
Groogy, indeed it does
<oprypin>
can do .to_h on it
<Groogy>
though all I want is to convert the key&values to values that YAML is okay with
<Groogy>
so would like it to remain a hash
<Groogy>
ah it's #select
<Groogy>
I think
<oprypin>
no
<oprypin>
obviously you'd need to make a new hash out of it (memory layout and all), and there's no direct way to do a conversion in one method from the standard library
<Groogy>
nah it's not aw :/
<oprypin>
you either do .map .to_h or you do it yourself in a loop
<oprypin>
for best performance `typeof(hash).new do |new| hash.each do |(k, v)| new[k] = v; end; end`
<Groogy>
hmm that's weird, my to_yaml has to be wrong then
<oprypin>
Groogy, easiest would be to pastebin everything as one file
<Groogy>
nah figured it out, the IO given to the to_yaml is literally the IO, I was expecting it to be a stream class from YAML that would parse the objects
<Groogy>
aaand that fixed it
Ven has joined #crystal-lang
Ven is now known as Guest24175
snsei has quit [Remote host closed the connection]
<FromGitter>
<elorest> What is the best way to add into a slice of bytes. It seems as if slices are a contant size where as an array lets you append.
<oprypin>
elorest, it's true, they are constant size
<oprypin>
you can gather data in an IO::Memory and then to_slice
<oprypin>
elorest, FYI arrays use a constant size memory region under the hood and just occasionally move to a new, bigger constant size memory region
<oprypin>
and IO::Memory is that array-like thing that you're looking for