<FromGitter>
<Heaven31415> Wren is a scripting language and I'm planning to embed it's interpreter in my game
<FromGitter>
<girng> so it's kinda like lua?
<FromGitter>
<girng> that syntax reeminds me of crystal lol
<FromGitter>
<Heaven31415> Yes, but it's pure OOP and a bit faster than lua (not counting lua jit)
<FromGitter>
<girng> They have Fiber.yield hahhh
<FromGitter>
<Heaven31415> and they have blocks
<FromGitter>
<Heaven31415> I already successfully exposed some crystal classes and structs to this interpreter and everything works fine
<FromGitter>
<Heaven31415> even was able to use crystal file from Wren :P
<FromGitter>
<girng> what does weakref do in your ai carrier?
<FromGitter>
<Heaven31415> every unit in my game has ai and every ai has access to unit
<FromGitter>
<girng> "to unit" what's this mean?
<FromGitter>
<girng> what unit?
<FromGitter>
<Heaven31415> it's a base object in my game
<FromGitter>
<girng> ohhh
<FromGitter>
<Heaven31415> Ship is an example of Unit
<FromGitter>
<girng> so the WeakRef just store references basically?
<FromGitter>
<Heaven31415> exactly, but as it's name says it's a WeakRef
<FromGitter>
<Heaven31415> without it, unit points to ai, ai to unit
<FromGitter>
<Heaven31415> and garbage collector cannot clear it properly
<FromGitter>
<girng> interesting, in Godot engine there is a weak ref but i've never had to use it. i was just curious to see it used in crystal
<FromGitter>
<Heaven31415> Compiler will tell you
<FromGitter>
<Heaven31415> It told me everything about this problem :P
<FromGitter>
<Heaven31415> I didn't even had to think about it
<FromGitter>
<girng> LOL
<FromGitter>
<Heaven31415> It can detect this kind of problem I guess
<FromGitter>
<girng> Ayee. I think the compiler teaches me more than what I learned on my own rofl!
<FromGitter>
<Heaven31415> Ok, I'm mistaken, compiler didn't detect that
<FromGitter>
<Heaven31415> You will get a warning from GC when this kind of situation happen XD
<FromGitter>
<girng> Do you use enums in your ai?
<FromGitter>
<Heaven31415> not in my ai, but I have few of them in my game
<FromGitter>
<girng> ic, just curious cause of the enemy state. in that video i linked, he has patrol/chase states as enums
<FromGitter>
<girng> i'm gonna do patrol/chase/attack, and then refine attack, to make the engagement level higher for the player
<FromGitter>
<Heaven31415> sure, make a video or something when you are done, so people can see it :P
<FromGitter>
<Blacksmoke16> make a nested enum, then ested enum would switch to decimals 1, 2, 3.1, 3.2 etc /s
marmotini has joined #crystal-lang
<FromGitter>
<Heaven31415> @girng if you are on Ubuntu you can easily play my game if you want
marmotini_ has quit [Ping timeout: 246 seconds]
<FromGitter>
<girng> you can nest enums?
<FromGitter>
<Blacksmoke16> idk, prob not :p
<FromGitter>
<girng> lol :P
non-aristotelian has quit [Quit: non-aristotelian]
silmanduin has quit [Quit: WeeChat 2.2]
akaiiro has quit [Remote host closed the connection]
<FromGitter>
<girng> how many bits does a boolean take up compared to 1 enum property?
<FromGitter>
<girng> > An enum is a set of integer values, where each value has an associated name. For example: โ nvm
DTZUZO_ has quit [Ping timeout: 245 seconds]
<FromGitter>
<dscottboggs_gitlab> > how many bits does a boolean take up compared to 1 enum property? (in crystal lang)
<FromGitter>
<girng> can i initalize a class by a string?
<FromGitter>
<girng> that's in a variable
<FromGitter>
<girng> actually that might be a bad idea nvm
<FromGitter>
<girng> inheritance is powerful af
_whitelogger has joined #crystal-lang
ua has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
marmotini has quit [Ping timeout: 244 seconds]
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
sevensidedmarble has quit [Ping timeout: 276 seconds]
sevensidedmarble has joined #crystal-lang
<FromGitter>
<proyb6> We need more LibC function: strchr, strrchr
rohitpaulk has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
rohitpaulk has joined #crystal-lang
Raimondii has joined #crystal-lang
ashirase has quit [Ping timeout: 272 seconds]
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
ashirase has joined #crystal-lang
<FromGitter>
<yxhuvud> Proyb6: why? Are those not doing stuff that is trivial and without overhead to implement in pure Crystal?
<FromGitter>
<fusillicode_twitter> @vladfaust sorry for the bother but does validations actually support sharing validations (not rules, actual validations) across structs?
<FromGitter>
<vladfaust> Lol. Twitter asked to add a birth day to crystal jobs account. Quoting "even if it's your cat or business". I set Sep 22nd 2018 and now it's blocked: "Twitter requires all users to be over the age of 13 on order to create an account."
<FromGitter>
<fusillicode_twitter> Lol but don't worry Twitter is not alone. Apple requires that too even for companies accounts
<FromGitter>
<fusillicode_twitter> And in the same way, if your company is "too young" than you're screwed XD
<FromGitter>
<vladfaust> :(
<FromGitter>
<proyb6> @yxhuvud I was thinking whether I could extract part of the string without creating a new string in C โ โ ```result << full_url[5..-1] #Crystal code``` โ โ If that's possible in C lib strstr without the "needle" string in the haysack url. PHP strstr has a similar API ... [https://gitter.im/crystal-lang/crystal?at=5bcafd6d271506518d3fba48]
lele_ has left #crystal-lang ["Leaving"]
<FromGitter>
<bajro17> how to get only first character
<FromGitter>
<bajro17> I know I can remove it with "string".lchop and how to get it?
<FromGitter>
<fusillicode_twitter> wait how can it work?
<FromGitter>
<fusillicode_twitter> `subject.contact` should be `(Contact | Nil)`
<FromGitter>
<fusillicode_twitter> I mean if it is optional then it means that it can be `nil`
<FromGitter>
<ljuti> If the `Contact` object wasnโt properly built, the method would return `nil` or raise an exception actually, because `Contact` is required
<FromGitter>
<fusillicode_twitter> mmm
<FromGitter>
<fusillicode_twitter> well then in your specs you have 2 different contexts
<FromGitter>
<fusillicode_twitter> the happy path with the Contact
<FromGitter>
<fusillicode_twitter> the unhappy one without it
<FromGitter>
<fusillicode_twitter> I think that the type checks may be factored out in some setup helpers that you can use to model the 2 different contexts
<FromGitter>
<ljuti> Yeah
<FromGitter>
<ljuti> And maybe I shouldnโt peek into the other classes in specs that donโt concern the implementation of those classes :)
<FromGitter>
<fusillicode_twitter> true that ;)
rohitpaulk has joined #crystal-lang
marmotini_ has joined #crystal-lang
<Yxhuvud>
@proyb6: but strchr doesn't work on crystal strings (due to encodings and multibyte characters etc). They might work on Slices, but then it takes like 3 lines of code to reproduce the method without involving libc.
<FromGitter>
<proyb6> I see Bew mentioned Slices is not utf8 friendly, how do you suggest it can handle?
<oprypin>
why would it not be friendly
<oprypin>
what are you actually trying to do?
<oprypin>
2018-10-16 10:48:47 <bew> @proyb6 you can try using `Slice`, you can get a slice from a String with `String#to_slice`, but note that it'll not play nicely with UTF-8
<oprypin>
ok yeah, that's misleading
<FromGitter>
<proyb6> I have previously want to find if there is alternative to return only "proyb" to HTTP server response without creating new string? โ ```context.response << "/user/proyb"[5..-1]```
<oprypin>
(as long as you keep in mind that `$0` was actually removed, as requested there)
<FromGitter>
<Schniz> @straight-shoota thanks for the help with the nightly :) your script is awesome
<FromGitter>
<Schniz> also, @vladfaust I just made a simple redirection service for circleci artifacts, https://circleci-artifacts.now.sh/ - it should be easy to distribute documentation that is built using `crystal docs`
<FromGitter>
<dscottboggs_gitlab> oprypin I'm glad they removed $0 and kept $1...$N
<oprypin>
well it's $0..$N now :p
<FromGitter>
<dscottboggs_gitlab> well that's fair, it's not so confusing now
<FromGitter>
<dscottboggs_gitlab> wouldn't that cause weird bugs with stuff that was written where `$0==PROGRAM_NAME`?
<FromGitter>
<dscottboggs_gitlab> Is there a way to debug crystal code at all?
<FromGitter>
<proyb6> @oprypin How do you suggest about Slice?
<FromGitter>
<j8r> $1 could also be removed for Regexes, its a bit too magical
<FromGitter>
<j8r> Ans I don't know any other place where it's used
<FromGitter>
<dscottboggs_gitlab> Oh! actually, I got it working, surprisingly!
<FromGitter>
<dscottboggs_gitlab> I think the last time I tried to debug I got a weird bug that only showed up when I tried building the debug version and that's why I gave up but this time it worked
marmotini_ has quit [Ping timeout: 252 seconds]
<oprypin>
proyb6, you have not provided any appropriate use case for Slice
<oprypin>
please just use string
marmotini_ has joined #crystal-lang
<FromGitter>
<proyb6> That's the best suggestion to use string. Thanks!
Yxhuvud has quit [Remote host closed the connection]
<FromGitter>
<Heaven31415> @oprypin Hey, if an object foo, has an instance variable x, is it okay to access it like this? `foo.@x`, because it looks to me like direct of instance variable without need to getter.
<oprypin>
Heaven31415, it will work but it is not "okay"
<FromGitter>
<Heaven31415> it might break in the future?
<FromGitter>
<Heaven31415> or you just mean, that it's not the right way :P
<FromGitter>
<j8r> but that's not ideal to modify String's ivar
<FromGitter>
<j8r> There is no best solution for now :(
<FromGitter>
<Heaven31415> Will it be possible in the future or is it even wanted to add type restrictions to macros? So I can for example create a macro which will only take NumberLiteral and otherwise fail.
<oprypin>
Heaven31415, the macro type system is a bit too sketchy to have that work well. but nothing prevents you from writing your own check
<FromGitter>
<Heaven31415> Maybe standard library should have this kind of facility? Something like assert which will just ensure that you have a proper type of AST node.
<FromGitter>
<bajro17> is it possible to make array of touples with fixed size
<FromGitter>
<j8r> of course
<FromGitter>
<bajro17> how to declare array is this correct [] of Tuple
<oprypin>
[] of {Int32, Int32, String}
<oprypin>
as usual, maybe you want to share your end goal
<FromGitter>
<bajro17> I will when finish this router I want make it on my way
<FromGitter>
<j8r> do use you radix?
<FromGitter>
<bajro17> I know there is so much other but I want make my to understand how everything work
<FromGitter>
<bajro17> no I dont use radix I want my :D
<FromGitter>
<bajro17> to I can understand everything how work because I mostly do web development
<FromGitter>
<bajro17> its good sometimes use frameworks but if I want learn crystal good and do web I want know how every line of code work
<FromGitter>
<j8r> what do you use instead of a radix tree? Often its used in HTTP router
<FromGitter>
<bajro17> I build my own tree this is reason why all time ask about regex or some other silly things :D
<FromGitter>
<bajro17> also is it possible with tuple something like {...String}
<FromGitter>
<bajro17> to I can add how much I want strings?
<oprypin>
no, that's against the definition of a tuple. then you have to use an array
<FromGitter>
<dscottboggs_gitlab> > which will just ensure that you have a proper type of AST node. โ โ I feel like if your macro is this sketchy it shouldn't be a macro
<FromGitter>
<bajro17> no problem then array of array will do job
<FromGitter>
<dscottboggs_gitlab> Maybe you want StaticArray @bajro17 ?
<oprypin>
"add how much I want strings" - probably not
<FromGitter>
<bajro17> url can be like "blog/1/edit"
<FromGitter>
<dscottboggs_gitlab> sorry I didn't read close enough I thought you were talking about an array of fixed-length arrays
<FromGitter>
<bajro17> but also someone can be little crazy and do like "blog/post/1/comment/2/freakinguser/4"
<FromGitter>
<Heaven31415> @dscottboggs_gitlab Well I'm using macro[] as a syntax sugar for constructor
<FromGitter>
<j8r> @bajro17 for what do you use array of array?
* FromGitter
* dscottboggs_gitlab shrugs
<oprypin>
Heaven31415, why not just use constructor directly O_o
<FromGitter>
<dscottboggs_gitlab> I guess it could be either way
<FromGitter>
<dscottboggs_gitlab> but your example is a runtime error as opposed to a compile-time error
<oprypin>
dscottboggs_gitlab, the example is a compile-time error
<FromGitter>
<Heaven31415> You can construct with ordinary constructor too, it's a tad bit shorter with macro[]
<FromGitter>
<dscottboggs_gitlab> oh, that's really cool, I didn't realize you could raise a compile-time error in a macro, that makes a lot of sense
<oprypin>
Heaven31415, shorter does not mean better
<FromGitter>
<Heaven31415> and this class is heavily used that's why every letter count for me
<oprypin>
oh well
<oprypin>
but still, why check in the macro if you're gonna get compile time errors for wrong argument anyway?
<oprypin>
also like, it could just be `def self.[](x); return self.new(x); end`
<FromGitter>
<Heaven31415> This is really good
<FromGitter>
<Heaven31415> I was checking in macros to get a easier to read error message
<FromGitter>
<bajro17> @j8r to I can have something like router[["GET","blog/:id", "blog.show"],["PATCH","blog/:id/edit", "blog.edit"],["DELETE","blog/:id/delete", "blog.delete"]]
<FromGitter>
<dscottboggs_gitlab> why not just use JSON, YAML, TOML or a Hash representation of your endpoints and use the appropriate serialization?
<FromGitter>
<bajro17> @dscottboggs_gitlab I dont know what is faster I think array is faster then do extra jobs
<FromGitter>
<bajro17> with parsing
<FromGitter>
<dscottboggs_gitlab> you're probably right, but I think readability is more important than a minor speed bump for something that will only be parsed once
<FromGitter>
<dscottboggs_gitlab> this is actually one of my worries with this language, with how flexible it is, is that the code will often be obscured by strange syntactical choices like in C++
<oprypin>
not recommended but better than array of arrays: `[{"GET","blog/:id", "blog.show"}, {"PATCH","blog/:id/edit", "blog.edit"}, {"DELETE","blog/:id/delete", "blog.delete"}]`
<FromGitter>
<j8r> If possible. But here, there is a recurring schema: `http_verb`, `path`, `action`, and using schemas are more efficient
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter>
<j8r> the data can be more efficiently accessed by avoiding to search in an array
<FromGitter>
<bajro17> maybe this is best solution
<FromGitter>
<dscottboggs_gitlab> would SomeObject with `property` methods, or a namedtuple with the equivalent properties, be more efficient?
<FromGitter>
<j8r> and if `Route` is a struct, you'll save even more heap memory, and less work for the GC :)
<FromGitter>
<bajro17> I can to avoid declare method
<FromGitter>
<dscottboggs_gitlab> I thought class/Objects were more efficient than structs because the former were passed by reference an the latter by copy?
<FromGitter>
<bajro17> in documentation write better use struct when its possible
<oprypin>
dscottboggs_gitlab, there is no blanket reply. short story is that `struct` and `NamedTuple` end up being represented in memory exactly the same. avoid namedtuple if at all possible.
<FromGitter>
<bajro17> because its more efficient
<FromGitter>
<Heaven31415> because structs are allocated on stack if they are not in array or something similar as opposed to classes which are always allocated on heap which is slower
<oprypin>
`class` is passed by reference, and a reference is a level of indirection, it also requires allocation and garbage collection
<FromGitter>
<dscottboggs_gitlab> @bajro17 I like it, because if you wanted to be even more explicit you could use named arguments, or you could choose ordered for conciseness or efficiency
<oprypin>
`struct` is local and direct, but needs to be passed by copy
<FromGitter>
<dscottboggs_gitlab> oh I see
<oprypin>
choose whatever is appropriate.
<FromGitter>
<dscottboggs_gitlab> so most of the time for few properties a struct would be better but as it gets more complex it could be better to use a class?
<oprypin>
number of properties is usually not a good metric, and also if that makes you feel like changing from `struct` to `class` then maybe it should have been a `class` in the first place
<FromGitter>
<j8r> @dscottboggs_gitlab generally, that depends if you want to share a modifiable object.
<oprypin>
the way i approach it is just make it a class, unless i see "oh yeah, this totally feels like a struct". what this "feels" means, i cannot tell you exactly, but you know, `struct Point; property x, y; end` is the typical example
<FromGitter>
<j8r> on my side its not really common, so I nearly always use structs. But maybe yes in you case
<oprypin>
if it's mutable, can't be a struct
<FromGitter>
<dscottboggs_gitlab> > *<oprypin>* if it's mutable, can't be a struct โ โ ahhh I see
<FromGitter>
<dscottboggs_gitlab> I actually like that a little better than kemal's way of doing things where you have macros affecting a global value. this lets you have multiple routers if you want in one module.
<FromGitter>
<bajro17> this is simples code I can find
<oprypin>
i brought it up because most frameworks are insanely complicated
<FromGitter>
<bajro17> I just search some simple code to I can understand it much is possible
<FromGitter>
<bajro17> yes exactly so complicated
<FromGitter>
<j8r> @bajro17 i think there is something like a tree for routing, and then handle the verbs