RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
alex`` has quit [Ping timeout: 244 seconds]
alex`` has joined #crystal-lang
<FromGitter> <bew> no, in crystal all types starts with an uppercase letter
<FromGitter> <DanilaFe> Interesting. It looks like even if I don't name them the same thing as they're called in C, there isn't a problem
<FromGitter> <bew> yes @DanilaFe the names of the structs and the fields inside the structs does not matter, what matters is the name of the functions that you binds to, the order for the parameters and the memory layout of the arguments (the order and the size of the structs fields)
<FromGitter> <Blacksmoke16> how would i check if typeof a variables is an array of strings?
<FromGitter> <Blacksmoke16> in a macro
<FromGitter> <Blacksmoke16> since you `can't execute Generic in a macro`
<FromGitter> <Blacksmoke16> `type.stringify == "Array(String)"`? :p
appocc has joined #crystal-lang
<appocc> hi . there
<appocc> is anybody here could helpme with a hash new method recursive override
<appocc> ??
<appocc> lol
<appocc> in Ruby i Had this:
<appocc> class Hash def self.recursive new { |hash, key| hash[key] = recursive } end end
<FromGitter> <Blacksmoke16> or i guess a better question, convert a string like `%(["foo", "bar"])` into type Array(String)
<appocc> not exactly... when I ser a value for this hash's instance, i want it to create a hash for it
<FromGitter> <Blacksmoke16> oops no sorry :p, was continuing my own question from earlier
<FromGitter> <Hamdan85> I'm actually running on the same here @appocc, having a hard time overriding stuff... specially Hashes
<FromGitter> <Blacksmoke16> isnt that the point of type safety? so that doenst happen
<appocc> anyone?
<appocc> lol... looking forward to learn overrides
<FromGitter> <Hamdan85> lol..... oops... got a compiler bug rs ⏎ BTW, gratz on the feedback from it... lol
appocc has quit [Quit: Page closed]
<FromGitter> <bew> @Blacksmoke16 that looks like a json array, you could use `Array(String).from_json(your_string)`?
<FromGitter> <Blacksmoke16> `Error in line 1: undefined method 'from_json' for Array(String):Class` nop
<FromGitter> <bew> well you jusy have to require json as you're doing dome json stuff
<FromGitter> <Blacksmoke16> oops
<FromGitter> <Blacksmoke16> yea that worked
<FromGitter> <aisrael> Hehehe
<FromGitter> <Blacksmoke16> :p
<FromGitter> <aisrael> I just did a quick try myself. Didn't realize `Array(T).from_json` could work.
<FromGitter> <Blacksmoke16> yea, TIL
<FromGitter> <bew> @asterite could you elaborate on `A little copying is better than a little dependency` ? I was thinking that it was 'always' better to reuse code if it's already well implemented? and also you get improvement and new methods for free without later copying. Where could be the problem? Thank you
DTZUZO has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<FromGitter> <sam0x17> does anyone know of a macro that will give me the name of a variable as string (that I could print and/or access from crystal code)?
<FromGitter> <bew> can you give a usage example? => how you'd use that macro
<FromGitter> <sam0x17> ```a = "asdfdsaf" ⏎ puts get_var_name(a) # should print 'a'``` [https://gitter.im/crystal-lang/crystal?at=5b5569e7f02a0977a3f2fffc]
<FromGitter> <sam0x17> my use case is writing a print/debug method for an AVL tree implementation
<FromGitter> <sam0x17> it probably won't work the way I want but this would be a step in the right direction
<FromGitter> <bew> https://carc.in/#/r/4kyz
<FromGitter> <sam0x17> thx so much
<FromGitter> <bew> :)
<FromGitter> <bew> nice! good luck with that
<FromGitter> <sam0x17> thx
<FromGitter> <sam0x17> @jspillers I'm up in providence, though I'm sure there are a bunch in NYC
alex`` has quit [Ping timeout: 264 seconds]
flaviodesousa has joined #crystal-lang
GoldenBear_ has quit [Ping timeout: 248 seconds]
Raimondi has quit [Quit: WeeChat 2.1: ¡Chau!]
alex`` has joined #crystal-lang
renzhi has joined #crystal-lang
<crystal-gh> [crystal] RX14 closed pull request #6432: Fix: private aliases at top-level not considered private (master...bug/5752-private-alias-top-level) https://git.io/fNlgo
<crystal-gh> [crystal] RX14 pushed 1 new commit to master: https://git.io/fNlbg
<crystal-gh> crystal/master d1ac793 Ary Borenszweig: Formatter: don't format code fence when language is not crystal (#6424)
cjd has left #crystal-lang [#crystal-lang]
<FromGitter> <Qwerp-Derp> would something like swift's way of accepting enums as arguments be a good idea?
<FromGitter> <bew> what it is?
<FromGitter> <Qwerp-Derp> so instead of typing a long name for an enum (e.g. `ThisIsAReallyLongEnum.weekday`), you just do `.weekday` and the type inference handles it for you
<FromGitter> <bew> since last release you can do `:weekday` :D
<FromGitter> <Qwerp-Derp> we can use symbols for that, so let's say I have an enum like `A::B::C::Enum::D`, I can just do `:D` or something similar
<FromGitter> <Qwerp-Derp> can you? :D
<FromGitter> <bew> yep
<FromGitter> <Qwerp-Derp> that's so cool
<travis-ci> crystal-lang/crystal#3817c7a (master - Fix: private aliases at top-level not considered private (#6432)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/407065226
<DeBot> https://github.com/crystal-lang/crystal/pull/6432 (Fix: private aliases at top-level not considered private)
<FromGitter> <bew> @Qwerp-Derp #6074
<DeBot> https://github.com/crystal-lang/crystal/pull/6074 (Explosive birth of automatic casts!)
<FromGitter> <Grabli66> Hi! I am getting that error on compilation. ⏎ And i cant repeat it in play.crystal-lang. ⏎ What to do? :) ⏎ ⏎ data = Bytes[0xCC, 0x80, 0x00, 0x00, 0x00] ... [https://gitter.im/crystal-lang/crystal?at=5b55acf1b2411177a265b0cd]
<travis-ci> crystal-lang/crystal#d1ac793 (master - Formatter: don't format code fence when language is not crystal (#6424)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/407066893
<DeBot> https://github.com/crystal-lang/crystal/pull/6424 (Formatter: don't format code fence when language is not crystal)
Ven`` has joined #crystal-lang
Ven`` has quit [Read error: No route to host]
Ven`` has joined #crystal-lang
<FromGitter> <Val> Is it possible to change `PROGRAM_NAME` at running time ?
<FromGitter> <bew> no
<FromGitter> <Val> thx
<FromGitter> <bew> it's a constant, and you can't re-assign a constant
<FromGitter> <Val> There is no other way to do so (changin program name at running time) ?
<FromGitter> <bew> not in the stdib at least, what's your usecase?
<crystal-gh> [crystal] j8r closed pull request #6110: Remove static linking for macos (master...macos-static) https://git.io/vphHX
<Yxhuvud> if you want to change program name, as in what it shows up as to other stuff (top etc), then invoking prctl with PR_SET_NAME is probably your best bet. Dunno if c bindings for that exist
<FromGitter> <S-YOU> ARGV_UNSAFE is changable if you want to pass it down somewhere.
<FromGitter> <j8r> @Val you could do `pointerof(PROGRAM_NAME).value = "name"` - potentially dangerous and not sure if it will do what you expect
<FromGitter> <Val> @j8r : ok thanks, I'll wait for more normal way to do it =)
<FromGitter> <Val> but the trick works well
<FromGitter> <Val> how can it be dangerous ?
<FromGitter> <straight-shoota> because you're not supposed to do that
<FromGitter> <straight-shoota> why do you want to change the program name?
<FromGitter> <straight-shoota> @j8r's suggestion is not gonna work anyway, because `PROGRAM_NAME` is a Crystal string initialized at startup.
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven`` has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4l12 why is the type a union while in the each block?
Ven`` has quit [Ping timeout: 260 seconds]
Ven`` has joined #crystal-lang
<FromGitter> <asterite> because the compiler can't know at compile-time what is `k`
<FromGitter> <Grabli66> @asterite Hi! Can you tell me why i got an error?
<FromGitter> <Grabli66> data = Bytes[0xCC, 0x80, 0x00, 0x00, 0x00] ⏎ ⏎ ``` ^``` ⏎ ⏎ in /usr/share/crystal/src/slice.cr:34: undefined constant T ... [https://gitter.im/crystal-lang/crystal?at=5b55ce4ef10ffa0b48a761de]
Ven`` has quit [Ping timeout: 248 seconds]
Ven`` has joined #crystal-lang
<FromGitter> <Blacksmoke16> hmm, fair enough
Ven`` has quit [Ping timeout: 256 seconds]
<FromGitter> <straight-shoota> @Grabli66 `data = Bytes[0xCC, 0x80, 0x00, 0x00, 0x00]` compiles
Ven`` has joined #crystal-lang
<FromGitter> <Grabli66> @straight-shoota Yes. But in simple program. I am thinking about how to repeat that error. I have many generics, blocks and other. I think it's cause of generics.
Groogy has joined #crystal-lang
<FromGitter> <Grabli66> Atlast, i can repeat it :)
Ven`` has quit [Ping timeout: 268 seconds]
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
<FromGitter> <straight-shoota> @Grabli66 reduced: https://play.crystal-lang.org/#/r/4l2f
<FromGitter> <straight-shoota> definitely looks like a compiler bug
<FromGitter> <straight-shoota> it works with `Slice[0xCC, 0x80, 0x00, 0x00, 0x00]`
<FromGitter> <Val> @straight-shoota : (back) I wanted to change PROGRAM_NAME because of a Process.exec call to reflect new effective program...
<FromGitter> <Val> It's quite easy in any language and in some case very useful
<FromGitter> <straight-shoota> examples for "any language"?
<FromGitter> <Val> Ruby ?
<FromGitter> <Val> Python
<FromGitter> <Val> C, you can pass new program_name at exec calll
<FromGitter> <Val> So replace "any" by "many" =)
<FromGitter> <straight-shoota> You should at least be able to do that either by modifying `ARGV_UNSAFE` or calling LibC.prctl with PR_SET_NAME as Yxhuvud suggested
<FromGitter> <Val> Ok, I'll try that
<FromGitter> <straight-shoota> You'll have to add the C bindings yourself, though
<FromGitter> <straight-shoota> and prctl probably won't work on all posix platforms... I'm not sure
<FromGitter> <straight-shoota> are you sure, Python supports this out of the box?
<FromGitter> <straight-shoota> I could only find https://github.com/dvarrazzo/py-setproctitle
<FromGitter> <Val> hum you're right, In Python that's not simple, like
<FromGitter> <straight-shoota> But the python lib has a nice cross-platform implementation
<FromGitter> <straight-shoota> Maybe that could be ported to Crystal and integrated into stdlib as `Process.name = ` or something
<FromGitter> <Val> Would be great for some usage
<FromGitter> <Val> But I know there are some priorities before.
<FromGitter> <Grabli66> @straight-shoota It works. But it generates Slice(Int32) and to generate Slice(UInt8) i must write Slice[0xCC_u8, 0x80_u8, ...]
<FromGitter> <fridgerator> Would it be possible to use this with a crystal binary? https://github.com/facebookincubator/BOLT
<FromGitter> <fridgerator> "BOLT can operate on any binary with a symbol table"
<FromGitter> <fridgerator> "current support is limited to non-PIE X86-64 and AArch64 ELF binaries"
<FromGitter> <straight-shoota> @Grabli66, yes that's expected
<FromGitter> <fridgerator> ok thanks
<FromGitter> <j8r> How can I enable PIE? `crystal build -Dpie` has no effect
jeromegn has quit [Ping timeout: 256 seconds]
ilovezfs_ has quit [Ping timeout: 256 seconds]
jwaldrip has quit [Ping timeout: 256 seconds]
danzilio has quit [Ping timeout: 256 seconds]
jwaldrip has joined #crystal-lang
jeromegn has joined #crystal-lang
ilovezfs_ has joined #crystal-lang
danzilio has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.1]
wontruefree has joined #crystal-lang
hightower4 has quit [Ping timeout: 276 seconds]
hightower4 has joined #crystal-lang
wontruefree has quit [Quit: bye]
rohitpaulk has joined #crystal-lang
wontruefree has joined #crystal-lang
wontruef_ has joined #crystal-lang
wontruefree has quit [Ping timeout: 248 seconds]
wontruef_ has quit [Quit: bye]
Ven`` has joined #crystal-lang
<FromGitter> <talbergs> Hi, I use JSON.mapping macro. Can I somehow provide defaults to objects not given in json string? ⏎ I could also parse a default json string and then merge both objects. Is such recursive merging possible somehow?
alex`` has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
wontruefree has joined #crystal-lang
<18WAA13EA> [crystal] sdogruyol closed pull request #5354: Fix the scope to look-up the constant as the receiver type of the macro (master...fix/crystal/lookup-scope-in-macro) https://git.io/vbnsz
<7GHABE94L> [crystal] sdogruyol pushed 1 new commit to master: https://git.io/fN89f
<DeBot> https://github.com/crystal-lang/crystal/pull/5354 (Fix the scope to look-up the constant as the receiver type of the macro)
<7GHABE94L> crystal/master 2aea034 TSUYUSATO Kitsune: Fix look-up-scope as macro defined type (#5354)
<DeBot> https://github.com/crystal-lang/crystal/pull/5354 (Fix the scope to look-up the constant as the receiver type of the macro)
bmcginty has quit [Ping timeout: 248 seconds]
bmcginty has joined #crystal-lang
<FromGitter> <bew> You can give a default value
<FromGitter> <bew> @RX14 should we tell people to forget about JSON.mapping and use the Serializable annotation method? Or do we keep talking about mappings for now?
rohitpaulk has quit [Ping timeout: 256 seconds]
wontruefree has quit [Quit: bye]
<FromGitter> <jwoertink> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b562f6426bfd636be43609e]
<FromGitter> <jwoertink> I have some code like this, but I get the error `Can't convert an empty NamedTuple to a Hash` at compile time
<FromGitter> <jwoertink> though, it should never be empty if it has a key.
<FromGitter> <jwoertink> Is there a way to handle this? Or do I just need to do something like `named_tuple.empty? ? a : b`?
<FromGitter> <talbergs> @bew yes im good with givin' default value. How do I do it? ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5b562fc9f10ffa0b48a8beea]
<FromGitter> <talbergs> @bew nice one, Im all into ⏎ ⏎ > forget about JSON.mapping and use the Serializable annotation ⏎ is that "annotation" on josn thing documented somewhere? [https://gitter.im/crystal-lang/crystal?at=5b5630aef9ffc4664bf94b3b]
wontruefree has joined #crystal-lang
<FromGitter> <talbergs> @bew ⏎ ⏎ > should we tell people to forget about JSON.mapping ⏎ See, I creaed low quality tutorial, as I'm learning - a writedown to my self. ⏎ https://medium.com/@animaacija/crystal-lang-hot-reloaded-json-config-7fab0de67732 ... [https://gitter.im/crystal-lang/crystal?at=5b5631ab4b880b3e6a43b528]
<travis-ci> crystal-lang/crystal#2aea034 (master - Fix look-up-scope as macro defined type (#5354)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/407301327
<DeBot> https://github.com/crystal-lang/crystal/pull/5354 (Fix the scope to look-up the constant as the receiver type of the macro)
<FromGitter> <bew> @talbergs no it's not really documented yet (well I thing I get my answer ^^)
Ven`` has joined #crystal-lang
<FromGitter> <bew> @talbergs you can read about that in the PR: #6082
Ven` has joined #crystal-lang
<FromGitter> <talbergs> found a bug (maybe) ⏎ `crystal eval "puts ARGV[0]" -- test ~/Documents/proj_WEB_PLAFORM master ⏎ Syntax error in eval:1: unexpected token: test`
Ven`` has quit [Ping timeout: 256 seconds]
<FromGitter> <bew> huh that's weird
<FromGitter> <talbergs> letme try other than `ziish`
<FromGitter> <talbergs> nono `shell` and `bourne again shell` says the same
<FromGitter> <talbergs> ^^
<FromGitter> <bew> ah, this works: `crystal eval "puts ARGV[0]" -- -- test`
<livcd> is asterite still working on crystal ?
<FromGitter> <j8r> @ livcd look at https://github.com/crystal-lang/crystal/pulse
Ven` has quit [Ping timeout: 240 seconds]
<FromGitter> <wontruefree> I just noticed we are merging more PRs and closing more issues then we are opening
Ven`` has joined #crystal-lang
Ven`` has quit [Client Quit]
wontruefree has quit [Quit: this is not the client you are looking for]
Raimondi has joined #crystal-lang
<FromGitter> <yorci> ```code paste, see link``` ⏎ ⏎ how can i solve that problem? [https://gitter.im/crystal-lang/crystal?at=5b565913e06d7e74099a0d63]
alex`` has quit [Quit: WeeChat 2.1]
<FromGitter> <idranel> Is there no way to get the IP address of an HTTP request? Have dug through the API at <https://crystal-lang.org/api/0.25.1/HTTP.html> but there isn't any mention of IP addresses... need to pull the addresses for a rate limiting experiment in Kemal.
<hightower4> idranel: yes, that's a long standing issue in Crystal. You can get the IP if you put a load balancer or something in front of the app and save the IP into some HTTP header
<hightower4> then read it off from there
<hightower4> (in e.g. haproxy you'd just add "option forwardfor" and you'd have the IP in the header X-Forwarded-For
<robacarp> is there a stdlib function to read a keypress rather than a whole string?
<robacarp> specifically without waiting for a newline
<FromGitter> <Timbus> HAven't tried, but if you set the terminal io handle to `.raw` that should work
<FromGitter> <Timbus> https://crystal-lang.org/api/master/IO/FileDescriptor.html#raw%28%26block%29-instance-method
<robacarp> @Timbus, nice. I was just searching IO for mode parameters. I think that works, thansk
<robacarp> ...heh...sure is easy to lock up your console with that, isn't it
<FromGitter> <Timbus> lol
<FromGitter> <Timbus> read each letter, in my experience it's the safest
<FromGitter> <Timbus> that or use liblinenoise/readline :p
<FromGitter> <Timbus> something like, uh ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ i guess [https://gitter.im/crystal-lang/crystal?at=5b56696763cf1636bde93ae2]
<robacarp> yeah, I just need to work on not swallowing ^c
<FromGitter> <Timbus> seems like you're on the right track then. good luck :D
<FromGitter> <bew> you'd better go with `IO#read_byte` not `IO#gets`
<FromGitter> <Timbus> seems fair
<FromGitter> <Timbus> hm. there really isnt a shard for linenoise or readline. that could be fixed if i get bored
<FromGitter> <Timbus> https://github.com/Papierkorb/fancyline just this
<robacarp> @bew read_byte vs read_char?
<FromGitter> <bew> depends what you want to do
<robacarp> currently, I'm asking .whitespace? and so on, which is easy with the char
<robacarp> but I haven't gotten to the control code thing yet
<FromGitter> <bew> what are you doing? an interactive program?