<FromGitter>
<codenoid> hi, how to define json value inside crystal variable ?
<FromGitter>
<codenoid> `{"key":"val","key":"val"}` , yup, crystal doesnt support single quote `'`
<Papierkorb>
hash syntax is `{ "foo" => "bar" }` - Note the hashrocket
<FromGitter>
<codenoid> a json value
<FromGitter>
<codenoid> its a json
braidn[m] has joined #crystal-lang
TheGillies has joined #crystal-lang
rizo[m] has joined #crystal-lang
thelonelyghost has joined #crystal-lang
vegai has joined #crystal-lang
byteflame has joined #crystal-lang
Renich[m] has joined #crystal-lang
jplatte has joined #crystal-lang
watzon has joined #crystal-lang
sija[m] has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
w-p has joined #crystal-lang
onionhammer has quit [Quit: WeeChat 1.7]
onionhammer has joined #crystal-lang
hightower2 has quit [Remote host closed the connection]
<FromGitter>
<jwoertink> Has anyone ran in to any issues naming a class the same as something that's in the crystal stdlib?
<FromGitter>
<jwoertink> I have a crecto model named `Event`, but when I try and use it, I get `Event is not a class, it's a module`
w-p has quit [Ping timeout: 248 seconds]
<FromGitter>
<cevarief> Any update regarding to support multi threading (parrarel) ?
<FromGitter>
<jwoertink> The language isn't really moving that fast anymore. I doubt much progress has been made on that. There's this branch https://github.com/crystal-lang/crystal/tree/thread-support which hasn't been updated in a while.
<FromGitter>
<jwoertink> I would urge anyone that has experience with that sort of stuff to hop in and knock out some issues to help out :)
<FromGitter>
<johnjansen> @jwoertink you have named your model the same as a module from somewhere else ;-)
<FromGitter>
<jwoertink> haha. I know
<FromGitter>
<jwoertink> I want my model named `Event`
<FromGitter>
<jwoertink> because it's like things you go out and do, parties, concerts, games, etc...
<FromGitter>
<jwoertink> I had to namespace my model so it will work. Not horrible
DTZUZO has quit [Read error: Connection reset by peer]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Read error: Connection reset by peer]
DTZUZO has joined #crystal-lang
mike_ has joined #crystal-lang
mike_ has quit [Client Quit]
_whitelogger has joined #crystal-lang
rizo[m] has joined #crystal-lang
byteflame has joined #crystal-lang
<FromGitter>
<johnjansen> @jwoertink why dont you put all your models into a namespace so you can still use event … im assuming that wont break anything
<FromGitter>
<jwoertink> That's what I ended up doing
<FromGitter>
<jwoertink> it's a little annoying, but not horrible
<FromGitter>
<bew> I think you want `input: nil` in the process creation line
<linuksz>
input: nil works
<linuksz>
but why should it be nil when i want to use it
<linuksz>
?
<FromGitter>
<bew> it's kinda weird we know (it'll be changed soon), specifying nil will allows you to control the process. Using true will just let the terminal (where you run your program) interact witg the process, not your program.. (makes sense?)
<linuksz>
so it always controls the input, but when it's true, i can write text for dmenu from the terminal?
<linuksz>
and when it's nil, it can be accessed from the program?
<FromGitter>
<bew> Exactly
<linuksz>
can i do the same thing with the output of the program?
<FromGitter>
<bew> It'll be clearer when #4445 is merged
<Papierkorb>
... Or just `curl http://example.com` - Yes, with backticks.
<linuksz>
but why do the above example use a memory io
<linuksz>
?
<FromGitter>
<G4BB3R> What is the idiomatic way to transform (a | nil) into a ? I mean, giving it a default value if nil
<FromGitter>
<bew> It depends, how do you assign a ?
<Papierkorb>
G4BB3R, `a || "some default"`
<Papierkorb>
Watch out for when used on a `Bool?`
<FromGitter>
<Qwerp-Derp> Has anyone used libgen?
<bmcginty>
Qwerp-Derp: Yes. I couldn't get it to remove common prefixes from things, but that was my only issue.
<crystal-gh>
[crystal] RX14 closed pull request #4773: Expand: show expanded macro name and its location (master...feature/crystal-expand/show-expanded-macro-name-and-location) https://git.io/v7R44
<FromGitter>
<Qwerp-Derp> Hmmm, what do I put in the "descriptions" field?
<RX14>
you want to remove the first instance of angular.callbacks._0( not every instance
<RX14>
@codenoid ignore that error on crystal play
<RX14>
it is nothing to do with your code
<RX14>
it is broken
<FromGitter>
<codenoid> not about crystal playground
<FromGitter>
<codenoid> but about json parser and my json value
<RX14>
Unexpected char '/' at 1:36441 is the correct error
<RX14>
not that on in play.crystal-lang.org
<FromGitter>
<codenoid> i dont find anything
<RX14>
it's most likely an escaping issue in the string
<RX14>
yup
<RX14>
you need a %q string
<RX14>
so that backslash escapes are processed properly
<RX14>
it's literally because you pasted it into a string literal
<RX14>
that \ chars needed to be doubly escaped
<RX14>
or use %q
<FromGitter>
<codenoid> HAHHAAAA
<FromGitter>
<codenoid> IT'S WORK
<FromGitter>
<codenoid> YOU SAVE MY LIFE RX14
<FromGitter>
<codenoid> wait, i''l write some blog post
linuksz has quit [Remote host closed the connection]
<RX14>
what?
<FromGitter>
<krypton97> mvp
DTZUZO has quit [Ping timeout: 260 seconds]
<FromGitter>
<sdogruyol> Congrats @codenoid
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 260 seconds]
DTZUZO has joined #crystal-lang
<FromGitter>
<bew> bmcginty, about your issue with libgen not removing common prefixes, I just had the same and fixed it: you need a rename rule, that remove the prefix from the fun name
miihael has joined #crystal-lang
snsei has joined #crystal-lang
miihael has quit [Quit: Page closed]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
sz0 has joined #crystal-lang
hightower has joined #crystal-lang
hightower is now known as hightower4
greengriminal has joined #crystal-lang
hightower4 has quit [Ping timeout: 276 seconds]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
greengriminal has quit [Quit: Leaving]
<alex``>
How to get the API documentation for offline usage?
<FromGitter>
<bew> what are you waiting for? go ahead :D
DTZUZO has quit [Ping timeout: 240 seconds]
<FromGitter>
<fridgerator> the world is your oyster
DTZUZU has quit [Quit: WeeChat 1.9]
<FromGitter>
<Jeremy-Pichon> Hi guys, I hope you are all doing well! :) ⏎ I need some help about the langage. ⏎ Can we translate a String to Symbol ? ⏎ My problem is: I get a list of file in a folder, and I want to call the function inside (that have the same name of the file). [https://gitter.im/crystal-lang/crystal?at=59932a2b4bcd78af56477fef]
<FromGitter>
<Jeremy-Pichon> thanks for the answer
<FromGitter>
<johnjansen> You can't dynamically create symbols. When you compile your program, each symbol gets assigned a unique number.
<Papierkorb>
Jeremy-Pichon, there's no `#send` like in Ruby either. Use a `case` statement instead.
<FromGitter>
<Jeremy-Pichon> ok, thanks a lot 👍
saadq has joined #crystal-lang
sstory has joined #crystal-lang
sstory has left #crystal-lang [#crystal-lang]
<crystal-gh>
[crystal] txe opened pull request #4832: Win: define Win32 API functions (master...win-lib) https://git.io/v7Fcz
<FromGitter>
<LuckyChicken91_twitter> is there a method like .sub but that its adding something?
saadq has quit [Ping timeout: 240 seconds]
<FromGitter>
<bew> do you have an example input/output?
<oprypin>
LuckyChicken91_twitter, i noticed that last time you used sub(index, "") and you see it only as deleting something maybe? well obviously it doesnt have to be that way
<FromGitter>
<LuckyChicken91_twitter> okay
<FromGitter>
<LuckyChicken91_twitter> im still a bit conditined to ruby that you can do string[0] += "text" but unfortunately this doesnt work in crystal
<FromGitter>
<johnjansen> string[0] returns a char, not a string
<FromGitter>
<LuckyChicken91_twitter> i know
<FromGitter>
<bew> If I understand correctly, you want to insert some text at a specific position of the string
<FromGitter>
<LuckyChicken91_twitter> yes
<FromGitter>
<LuckyChicken91_twitter> excatly
<FromGitter>
<bararchy> btw, why don't we have `String#gsub!()` ?
<FromGitter>
<LuckyChicken91_twitter> yes! why?
<RX14>
strings aren't mutable
<FromGitter>
<bararchy> Oh
<FromGitter>
<LuckyChicken91_twitter> ouh
saadq has joined #crystal-lang
saadq has quit [Ping timeout: 246 seconds]
saadq has joined #crystal-lang
imusingnotepad has joined #crystal-lang
<oprypin>
LuckyChicken91_twitter, so, like, when you decide what you actually want to do, maybe you could ask that, instead of "how can I do this weird thing from Ruby"
<FromGitter>
<LuckyChicken91_twitter> okay will do this next time
<FromGitter>
<LuckyChicken91_twitter> but im saying sometimes "because this is not working: *Some code*" so that people better understand what im meaning
<FromGitter>
<sdogruyol> Ruby ❤️
<oprypin>
Ruby 😠
<FromGitter>
<sdogruyol> Woot
<FromGitter>
<LuckyChicken91_twitter> ruby is awesome
<FromGitter>
<elorest> Also love ruby and crystal.
greengriminal has joined #crystal-lang
<Papierkorb>
*cough* String#replace()
<Papierkorb>
Err String#insert
<FromGitter>
<LuckyChicken91_twitter> how could i check if theres an "ehh" at the beginning of the string "ehhweeheehh" with an if-query? because this is not working: `if mystring[0..2]=="ehh"`
<FromGitter>
<bew> you can use `String#starts_with?`
<FromGitter>
<LuckyChicken91_twitter> oh nice
<RX14>
not sure why your query wouldn't work though?
<FromGitter>
<elorest> Yeah you could but also that code you wrote does work. https://carc.in/#/r/2j8m
<FromGitter>
<LuckyChicken91_twitter> oh ehm..
<Papierkorb>
But use String#start_with? in any case.
<FromGitter>
<bew> @elorest Also works with a `Char`, => no String object allocation (https://carc.in/#/r/2j9d)
greengriminal has quit [Quit: This computer has gone to sleep]
<Papierkorb>
bew, Except for the additional branching in the string version, as for a string literal, there's no allocation happening
<Papierkorb>
bew, read that as "both are fine", neither allocate extra memory. The Char version is *sliightly* faster of course, but apart from that..
<FromGitter>
<bew> Papierkorb: even for the String object (a few bytes I now)
<FromGitter>
<bew> ?
<FromGitter>
<bew> yeah for sure
<Papierkorb>
bew, the String is constant and exists completely in the .rodata afaik, thus, no run-time overhead of it being there
<FromGitter>
<bew> I wasn't speaking about the bytes of the string, but the crystal-lang String object (which has a pointer to .rodata to the actual string)
<Papierkorb>
.rodata exists anyway and is just copied into memory by the ELF loader. Technically, it's slightly more involved than that. But before you notice that, you probably have many other things to optimize first ;) - String is pretty much a `Tuple(UInt8*, Int32)` in terms of size, so it's not even really a reference. Also one of the reasons you can't inherit from String.
<FromGitter>
<LuckyChicken91_twitter> who here is finding `.empty?` at a string unnecessary? because you can write `if string==""`faster than `if string.empty?`
<FromGitter>
<bew> @LuckyChicken91_twitter shorter, but nor necessarily faster
<Papierkorb>
No, String#empty? is fine and having to write `foo == ""` is crap.
<Papierkorb>
Not to mention consistency with other Enumerable types
<FromGitter>
<elorest> @bew good point.
<FromGitter>
<LuckyChicken91_twitter> oh so comparing `if string.empty?` and `if string==""` in benchmark then =="" would be slower?
<Papierkorb>
Of course.
<FromGitter>
<LuckyChicken91_twitter> aah okay good to know
<Papierkorb>
But that's not the reason for it. It's idiomatic to ask something if it's empty.
<Papierkorb>
It's less idiomatic to ask if something equals something empty
<FromGitter>
<bew> Papierkorb: in program.cr String is noted as inheriting from reference, then it's instance_vars are declared, but I can't find any other "weird" stuff about string.. can you give me some pointer on what is really special about it?
<oprypin>
bew, Papierkorb, so what's really happening with a string is it's a pointer to some bytes, the first 4 of which are size and the rest are contents - the "some bytes" can be in heap or rodata (not 100% sure)
<oprypin>
wow except it's not 4 bytes but 3*4 bytes {TYPE_ID, bytesize.to_i, size.to_i}
<FromGitter>
<tonobo> hiho, i've a question releated to compile time checks. It corrected that your doing such checks, e. g handling possible nil access? So if conditions on instance variables are not working, is there any possibility to skip this compile time check convert into runtime checks?
<Papierkorb>
oprypin: String stores the string data just after the three @vars. It doesn't have a pointer to it, as the address to it is really "pointerof(String) + 12 Bytes"
<FromGitter>
<bew> oprypin: I thing that only the content can be in heap or rodata, the rest (+ the pointer) is allocated by the GC with GC.malloc_atomic
<Papierkorb>
oprypin: And yes, the data can be anywhere. I expect the `@size` (which is the size in Chars) to be correctly initialized by the compiler, so it doesn't have to be written to (which would cause a segfault within .rodata) later on
<FromGitter>
<tonobo> oprypin: i know the situation but isn't quite inperfomant by allocation each on heap? what happens with arrays?
<oprypin>
tonobo, your worries are caused by some misunderstanding, there is no problem with this, in fact llvm probably eliminates this entirely
<FromGitter>
<bew> yeah I just got understood
<hightower2>
sdogruyol: there?
<RX14>
a string has no pointer
<RX14>
it simply has a header + data which are always contiguous
<oprypin>
well actually it does, a String is only a pointer
<oprypin>
to what you just said
<RX14>
it is a pointer
<RX14>
it doesn't HAVE a pointer
<FromGitter>
<bew> yep
<FromGitter>
<bew> very interesting
<oprypin>
indeed
<Papierkorb>
bew, that whole structure is placed in .rodata by the compiler (Well, the linker). The linker will then happily give the program a pointer to that data (it doesn't care what it is). That's actually what the linker's job is mostly about: Resolving such pointers (in linker-speak, symbols)
<FromGitter>
<bew> genius
<FromGitter>
<bew> you resolved my last question ;)
<RX14>
@tonobo are you talking about `if foo = @foo` ?
<oprypin>
RX14, yes
<oprypin>
bew, Papierkorb, another fun fact that i wanted to confirm before saying https://carc.in/#/r/2ja3 character-size is in fact calculated on first access
<FromGitter>
<tonobo> yeah
<Papierkorb>
This happens at link-time, that's (technically) after compile-time, but way before run-time: It's before the binary program is written to disk.
<RX14>
in that case, 99% of the time you're only copying a pointer
<RX14>
that's just a number
<RX14>
it goes in a register and so that will essentially be 0 cost
<oprypin>
well sure that's what i was trying to show
<RX14>
oprypin, it probably isn't optimized out over non-inlined function calls
<RX14>
because if the function call isn't aligned llvm likely can't say whether the call modifies the ivar
<RX14>
in that case it has to load again
<FromGitter>
<bew> so cool... I love crystal, it resolves a lot of amazing problems in a clean way, so interesting to read and to learn about them
<RX14>
String is the only thing I know which does that trick @bew
<Papierkorb>
Same
<RX14>
and it's kind of a pain because very string constructor has to recreate it's binary form from scratch
<FromGitter>
<tonobo> but if i just create a pointer, isn't is the same as using the orig pointer? because if the process A will free them and process B will access the data then i access a nil pointer?
<oprypin>
this is not really new though, i know that Nim has exactly the same implementation of string
<oprypin>
and probably many before it
<Papierkorb>
yeah
<RX14>
@tonobo if you use `@foo` you're loading the value of that from memory. That memory might be a pointer in itself, but it might not be.
<Papierkorb>
Why invent something new if a good approach has been battle-tested for ages. (Well, every approach has its own issues lul)
<RX14>
oh yeah it's nothing new
<RX14>
putting headers on strings has been around for ages
<Papierkorb>
Pascal did it ..?
<FromGitter>
<bew> yeah, personally I only know well Crystal, compilers and stdlib of all other languages are still blackbox (less and less over time though)
<oprypin>
Papierkorb, did pascal actually do that but with a 1 byte header?
<RX14>
bet they didn't support utf8 though
<oprypin>
lol
<Papierkorb>
oprypin: possibly. Never used pascal nor delphi heh
<FromGitter>
<bew> how many years have you been working with bytes & code & programming & stuff?
<Papierkorb>
Proc is fun too. And depressingly boring after you know the trick.
<FromGitter>
<bew> ahah
<Papierkorb>
Though works well and boring is kinda good in a sense
<FromGitter>
<bew> simple is better!
<FromGitter>
<akzhan> just found - search_index - I need to only one form of condition passed (>=).
<oprypin>
of course modern implementations of pascal have nothing to do with this
<Papierkorb>
oprypin: ... Who comes up with that
<Papierkorb>
> Like C's strings, it is also null-terminated, which meant that Delphi automatically appends a zero byte at the end (actually 2 zero bytes)
<Papierkorb>
Mh, who would use 16bit chars in the system API anyway?
<Papierkorb>
Oh .. Windows.
<FromGitter>
<tonobo> Could you explain why your doing it such diffenent as golang it does. Are there a mentionable difference between performance or are there security aspects?
<oprypin>
akzhan, sorry i missed your question. i was checking out this method just a few days ago, ended up with this strangely example https://carc.in/#/r/2iqs (with same example data, it seems :p)
<oprypin>
tonobo, doing what
<Papierkorb>
tonobo, "different" in which sense? Though in general, the design philosophies are completely different
<FromGitter>
<tonobo> Golang will panic if a nil pointer has been accessed?
<oprypin>
tonobo, and crystal will not let you do that
<FromGitter>
<tonobo> yeah
<FromGitter>
<tonobo> :D
<Papierkorb>
Wait, golang didn't fix the one billion dollar mistake?
<oprypin>
regardless of the actual article which may be baloney, there are some fun comments to read
<oprypin>
how did humanity arrive to this point
<FromGitter>
<tonobo> Are there some reasons why they won't to "fix" it?
<oprypin>
that would mean making a new programming language
<oprypin>
and they don't appear to be good at that
<FromGitter>
<tonobo> So its just a root decision fail?
<FromGitter>
<faustinoaq> oprypin, but they have a big team and resources 💰
<Papierkorb>
tonobo, that's not an easy task. I don't know Golang, but the type system is a central part of every language, and has to be carefully designed from the get go, as changes later can and will break things all over the place
<oprypin>
akzhan, but yeah your simple example shows the typical use case perfectly
<Papierkorb>
tonobo, imho the biggest plus of Crystal may look surprisingly simple at first: Union typing, that is, that you can allow a type like `String | Int32`, meaning "Strings and Int32s are fine, everything else is not". Now the creators added `Nil` to the mix, which is not nothing, but a real type. Unlike in C or Java, where you can still pass `null` instead of the pointer that was expected (Modern C++ enforces this too). And now suddenly that
<Papierkorb>
simplistic feature becomes a full-blown solution to the "one billion dollar mistake". Not so boring after all
<FromGitter>
<tonobo> yeah i like crystal , the ideas behind, the syntax, ruby :D
<Papierkorb>
It also saves us from cluttering our code with pesky `Just(x)` and other waste of bytes. Other languages like Java are broken by design w.r.t this particular problem.
<FromGitter>
<tonobo> i've wirtten multiple small golang projects. And you need to write specs which hopefully triggers all nil pointer exceptions. Back to my original question, are there any performance differences by not checking the nil pointer? E.g I'am easily able to write code without allocations on heap.
<Papierkorb>
It saves you a single branch per variable (more or less), which I wouldn't really count as such as most CPU branch predictors will catch that and make it an almost no-op. Though not having it at all makes it even faster ;)
<Papierkorb>
The real issue is that you're cluttering your source code, which (as all kind of clutter) makes it harder to read. Also, you can just forget to check for nils.
<FromGitter>
<tonobo> mhm
<RX14>
i absolutely agree that union types are the single most important feature in crystal
<RX14>
it enables the feel of duck typing when writing method bodies, in a compiled statically-typed langauge. which is something i've never come across before
<FromGitter>
<straight-shoota> @RX14 agree
<FromGitter>
<tonobo> Yes, looks great :D
<FromGitter>
<tonobo> I'm getting started right now with crystal and wan't to learn something about the internals.
<FromGitter>
<tonobo> Also great support, guys ! :D
<oprypin>
yeah +1 to "i absolutely agree that union types are the single most important feature in crystal"
<hightower2>
It's awesome
<FromGitter>
<faustinoaq> 👍
<FromGitter>
<tonobo> Why did you decide to a make garbage collected language, not as just does?
<Papierkorb>
*as Rust ?
<FromGitter>
<tonobo> yes :D
<oprypin>
tonobo, "because Ruby" can answer a lot of things
<oprypin>
without garbage collection everything becomes entirely different
<Papierkorb>
tonobo, I'm not a creator, but also, making a language (and/or environment) which automatically manages memory without a GC is hard. See Rust: They do it, which is impressive. But the price is that it becomes much harder to use.
<FromGitter>
<tonobo> Ok, you're right. Rust's borrowing feels strange by using it :D
<FromGitter>
<tonobo> Are there any issues open right now which recommends me to avoid crystal in production?
<oprypin>
probably. but people do it anyway
<FromGitter>
<tonobo> :D
<FromGitter>
<fridgerator> lol
<RX14>
don't use crystal in production when you've worked out foryourself when to use it in production
<RX14>
because if you're asking the answer is no
<RX14>
s/when/until
<FromGitter>
<tonobo> yeah
<FromGitter>
<tonobo> Thanks a lot guys :D
<FromGitter>
<crisward> @sdogruyol How's the survey gone... planning on publishing something?
greengriminal has joined #crystal-lang
<crystal-gh>
[crystal] oprypin opened pull request #4834: Fix parsing of '!=' after an identifier (master...not-equal) https://git.io/v7Fxf
alex`` has quit [Ping timeout: 246 seconds]
<FromGitter>
<faustinoaq> > Submissions will be accepted until around September 12th, 2017. ⏎ So, I think is not ready yet
justinmcp_ has quit [Quit: No Ping reply in 180 seconds.]