<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`
<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
<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
<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…]
<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.
<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>
<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>
<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
<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?
<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