<BlaXpirit>
well yeah, but make sure you want an actual Proc in the first place. and do you mean it can be called with any number of arguments or exactly N
<bew78>
I want to make a function like 'func(something, &block)' and depending on 'something', there will be 1, 2 or 3 (or more) arguments given to the block
<BlaXpirit>
bew78, ummm so make 3 different ones?
pawnbox has joined #crystal-lang
<BlaXpirit>
i don't think a Proc should be involved here
<BlaXpirit>
u can make 3 methods with the same name, depending on the type of argument a different one will be called
<bew78>
the 'something' is a string, and after parsing the string, the block will receive a bunch of args
matp has joined #crystal-lang
<BlaXpirit>
that's.. not idiomatic
<bew78>
BlaXpirit: hum, I don't understand that word..
<bew78>
What do you mean ?
<BlaXpirit>
i mean maybe there's an approach that aligns better with the features of the programming language
<BlaXpirit>
maybe even your approach will just work, but i don't have time to try now
* BlaXpirit
leaves
<bew78>
I understand, thanks, I'll try
_jinks has joined #crystal-lang
jokke has quit [Remote host closed the connection]
jokke has joined #crystal-lang
bjz has joined #crystal-lang
_jinks has quit [Quit: leaving]
<bew78>
I've found a way by using an Array(String) as first block argument, and by using Block arguments unpacking (ex: 'func(something) do |(arg1, arg2)| end' ), I can get what I want
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<bew78>
BlaXpirit: do you think this aligns better with the features of crystal ?
<Papierkorb>
bew78: Could you describe what you're actually trying to do?
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
fp_preist has quit []
<bew78>
an argument parser that allow me to do: 'parser.on "set USER ACL", "Add/Change user rights" do |(user, acl)| #something end' given a parser configuration for USER and ACL so it'll match a specific regex..
<bew78>
Papierkorb:
<Papierkorb>
ah
<Papierkorb>
bew78: Mh yeah I think your argument unpacking approach is the best choice in this case then
<bew78>
cool, I'm on the right track then :)
<Papierkorb>
bew78: Maybe there's a way to do something like that though using macros
<Papierkorb>
I'm fiddling with that atm, but I don't see much wrong with having () either..
<bew78>
never really tried macro currently, I trying to get the most out no-macro code, but maybe there is a better way
<Papierkorb>
Tbh, Macros aren't that bad. They're quite powerful and .. well they can at least .. read like normal code
<bew78>
yeah true, macro are like 'next-level' for me, maybe later !
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
bew78 has quit [Ping timeout: 264 seconds]
soveran has quit [Remote host closed the connection]
<RX14>
@dipnlik crystalshards looks nicer, and seems to be better maintained
<RX14>
they both get the info from github API
<BlaXpirit>
dipnlik, 2nd is loosely based on 1st. 2nd seems uh... objectively better
<FromGitter>
<dipnlik> @BlaXpirit that's what I thought, but I wanted to hear it from the community, didn't know if for example .xyz was a lame ripoff or maintained by an evil person or something like that
bjz has quit [Read error: Connection reset by peer]
bjz has joined #crystal-lang
pawnbox has joined #crystal-lang
ruby_ has joined #crystal-lang
<asterite>
the second one is basically "I think the first one has an ugly UI, so instead of sending a PR or discuss this with the maintainer I'll just make my version and not even mention the original source or effort in my copy"... which is something I kind of dislike, but, well, we can't control everything out there... I personally use the first one, it feels faster for me and the UI is simpler so easier to understand
<FromGitter>
<sdogruyol> @asterite the first one is not maintained. So that's pretty much the reason we rolled out the 2nd :)
<FromGitter>
<sdogruyol> Meanwhile it's not easy to remember something.herokuapp.com
mark_66 has quit [Remote host closed the connection]
mark_66 has joined #crystal-lang
<RX14>
@sdogruyol did you try try to contact the crystalshards.herokuapp.com maintainer?
<FromGitter>
<sdogruyol> sure, my friend @f did
snsei has joined #crystal-lang
<asterite>
ah, i see...
snsei has quit [Remote host closed the connection]
Philpax has quit [Ping timeout: 272 seconds]
pawnbox has quit [Remote host closed the connection]
ponga has joined #crystal-lang
johnjansen has joined #crystal-lang
<johnjansen>
hi all, anyone know of an english language stemmer shard by chance?
mark_66 has quit [Remote host closed the connection]
<asterite>
(that is, if porter stemmer is good enough for you)
kulelu88 has joined #crystal-lang
<johnjansen>
thanks @asterite, i was just contemplating that
<RX14>
asterite, i don't know how i'm finding all these bugs recently but I suppose it's a good thing
<johnjansen>
@asterite, in looking at some stemming code i just tripped over this (what i think is a regex) shortcut from ruby … which isnt valid crystal … never seen the syntax before and not sure if its something you want to support
<johnjansen>
“Y” == ?Y
snsei has joined #crystal-lang
<johnjansen>
or is it ternary
<pabs>
johnjansen: it's a character test
<pabs>
johnjansen: ?X is a ruby shortcut for a character literal (in older versions of ruby it would map to the character's ordinal value, now it's just a one-character string of the character)
<pabs>
johnjansen: e.g., in ruby 1.8: ?x == 120, and in modern ruby ?x == "x"
<johnjansen>
thanks for that … i had figured thats what it was, but you never know whats hiding behind syntax like that, and in case you were wondering, its impossible to search for that kind of stuff on the interweb ;-)
<johnjansen>
just found this, which turns out to explain a bunch of other random stuff
<RX14>
and the rand() Int64 bug was found randomizing timespans
<RX14>
there should probably be a Time::Span.sample
<asterite>
Oh, so they are real bugs! I thought you maybe was browsing the source code and considered some possible cases...
<RX14>
which returns a point inside that timespan
<RX14>
but then again
<RX14>
that would have to be from now or ago
<RX14>
asterite, nope
<asterite>
In Rust one can random any value, I think they have to implement some kind of trait... it would be nice to have something similar in Crystal, don't know how yet
<RX14>
I encountered the JSON bug while writing stats for it
<RX14>
so I wanted an average files scanned per second in the last 10s, which was Infinity if there were no files scanned in the last 10s
<RX14>
Time::Span.zero should exist too :)
<RX14>
i forgot to add that to the issue tracker
<BlaXpirit>
asterite, I have implemented a random number generation library, I can help on this topic
ruby_ has joined #crystal-lang
<BlaXpirit>
that was for a different programming language, but I was able to generate random numbers of any type and any range. and well, for objects, they should just do it themselves
<asterite>
BlaXpirit: nice!
<BlaXpirit>
what's the problem with just making a `random` class method
<asterite>
Yes, that's another approach. I think the use cases for random are pretty limited, like, mostly primitive types, time spans, but I don't know what else
<RX14>
well
<RX14>
you could assume the interface is
<RX14>
to_i
<RX14>
and new(i)
<RX14>
then take a random using those numbers
<RX14>
for ranges you would convert top/bottom to numbers
<RX14>
then rand in the range
<RX14>
then create a new with the random number
<RX14>
but maybe thats a bit clunky
<RX14>
.random would probably be nicer
<BlaXpirit>
ow, so the standard library uses rand % max
<RX14>
oh wow
<RX14>
thats not particularly random
<BlaXpirit>
and it will be problematic in a multithreaded environment
<BlaXpirit>
seems like array.shufle use the global instance
<BlaXpirit>
ah no, it's configurable, sorry
<BlaXpirit>
still maybe the default instance should be thread local
<crystal-gh>
[crystal] asterite pushed 2 new commits to master: https://git.io/vPJUq
<crystal-gh>
crystal/master 34689cb Ary Borenszweig: MD5: some renames
<crystal-gh>
crystal/master c79f583 Ary Borenszweig: Fixed #3360: incorrect type flow regarding unreachable and '&&'
<BlaXpirit>
anyway... once upon a time i implemented a way to avoid the imprecision of rand % max
<BlaXpirit>
aaand i still can't be sure it's right
<BlaXpirit>
at least it's quite easy with the limitation of uint32
<BlaXpirit>
but limiting the RNG to uint32 is no good in the first place
<RX14>
you can create a uint64 rng from 2 uint32s
<BlaXpirit>
that's... not right
<RX14>
why?
<BlaXpirit>
you meant to say a random number probably
<BlaXpirit>
oh wait, yeah, it is right but that's not the point
<RX14>
why not?
<RX14>
i mean
<BlaXpirit>
i mean that some random number generators spit out 64 bit numbers, some spit out 8 bit numbers
<BlaXpirit>
but standard library forces it to 32
<RX14>
it's probablt got a rubish cycle size for a uint64 rng
<RX14>
but there we go
<RX14>
it would be nice if syscalls weren't so expensive, so we could just use kernel random
<BlaXpirit>
been there, done that
<BlaXpirit>
but yeah, it's for special uses only
jinnguyen has joined #crystal-lang
<jinnguyen>
hi anyone using kemal at a production level ?
<RX14>
yes, a few
<RX14>
but i wouldn't recommend it unless you're a crystal expert already
<jinnguyen>
I'm consider using it for some of my next api
<RX14>
i mean, it's basically just kemal'c creator which uses it in prod
<jinnguyen>
what would you recommend ?
<RX14>
i assume you're new to crystal?
<jinnguyen>
i'm new, just a week
<jinnguyen>
been tinkering with kemal for some day
<RX14>
you're going to have to upgrade your codebase through breaking changes every crystal release
<RX14>
you're going to encounter bugs
<RX14>
if you're ok with that, then sure
<RX14>
it'll work great once it works
<jinnguyen>
I see crystal as pretty fast, promising
<RX14>
do you need fast? what's your data volume?
<jinnguyen>
a few ten GBs though...
<jinnguyen>
i mean my DB :D
<RX14>
per what? what does this API do?
<RX14>
oh
<RX14>
i meant sort of requests per second
<jinnguyen>
it's now around ~ 2k
<jinnguyen>
for a product search
<RX14>
well, it does sound like the kind of problem crystal would be good at
<RX14>
but if you do it, be prepared to jump ship
<jinnguyen>
i'm using crystall http request to couchbase since there is no driver yet
<RX14>
if you can, start with only a small bit of crystal
<jinnguyen>
get 10ms repsonse from db to client
Jomakasi has joined #crystal-lang
<BlaXpirit>
well things are not that bad, after all old compiler versions are not going away
<BlaXpirit>
but they can be insecure, you can't be sure about this aspect
<RX14>
BlaXpirit, yes but the point is that we're not production ready or stable
<Jomakasi>
hello
<RX14>
sticking to an old compiler release is like sticking your head in the sand
<RX14>
Jomakasi, hi
<jinnguyen>
oh are you a crystal founder @RX14
<RX14>
nope
<jinnguyen>
yep
<RX14>
i've been here... maybe a year?
<RX14>
hmm
<jinnguyen>
I read the protel been using crystal at product level
<BlaXpirit>
jinnguyen, that's the company where creator of kemal works
<BlaXpirit>
as mentioned previously
<jinnguyen>
oh... okay
<RX14>
hmm, looks like around august 2015 i came here
<jinnguyen>
so he must be an expert to control his codebase :)
<jinnguyen>
what do you guys doing with crystal ?
<jinnguyen>
just asking for ref :D
<RX14>
it's justa hobby for me
<wmoxam>
^^ same
<RX14>
well, i don't have a job anyway... so
<RX14>
i'm a student
<jinnguyen>
oh cool
<jinnguyen>
is crystal near it 1.0 yet ?
<RX14>
probably not
<RX14>
there's quite a todo list
<jinnguyen>
60% ~ 70% maybe ?
<RX14>
and honestly I don't want to be releasing a 2.0 less than 2 years after 1.0
pawnbox has quit [Remote host closed the connection]
<RX14>
jinnguyen, maybe about there
<jinnguyen>
yep im spending 1hr each day for this ^^
<BlaXpirit>
jinnguyen, i'm just porting some libs to write games in crystal. hopefully that will be a thing some day
<jinnguyen>
oh game server or desktop :D
<BlaXpirit>
i mean like normal games with graphics, not a server
pawnbox has joined #crystal-lang
ponga has quit [Quit: Connection closed for inactivity]
<jinnguyen>
yep
<wmoxam>
BlaXpirit: what libs are you porting?
<BlaXpirit>
well one is very much done, the other just need a bit of docs
Ven_ has quit [Read error: Connection reset by peer]
Ven_ has joined #crystal-lang
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vPJsQ
<crystal-gh>
crystal/master 4b02fe5 Ary Borenszweig: Time: fixed bug introduced in 0.19.0 with a small typo
Ven_ has quit [Ping timeout: 244 seconds]
pawnbox has joined #crystal-lang
Ven_ has joined #crystal-lang
Ven_ has quit [Read error: Connection reset by peer]
kulelu88 has joined #crystal-lang
<asterite>
RX14: i would still recommend using and trying crystal, it's one of the best things to keep pushing the language forward
<RX14>
asterite, yeah of course
<RX14>
I would use crystal in production
<RX14>
because I know I can handle it
<RX14>
but i don't really want to recommend it to others
pawnbox has quit [Ping timeout: 272 seconds]
Ven_ has joined #crystal-lang
<RX14>
asterite, will you be releasing 0.19.3 this friday?
<asterite>
Yes, most probably
<RX14>
nice
<johnjansen>
@asterite ive done a quick and dirt port of a ruby based stemmer to crystal, just an FYI, thanks for the suggestion, thats one under my belt
<asterite>
johnjansen: I saw it, just downloaded it and ran the specs :-P ... that was fast!
<asterite>
johnjansen: how was the porting?
pawnbox has joined #crystal-lang
Ven_ has quit [Ping timeout: 264 seconds]
<johnjansen>
pretty easy, the apis were so closely matched there wasnt much trouble with that, the tricky part was all the unusual references to global variables which i havent to be honest seen before like $` for eg, i wound up with irb and playground up side by side to resolve the differences
<johnjansen>
the specs were also an almost direct port from the ruby library, so presuming its complete and correct, then we are all good
<asterite>
Yeah, they look correct :)
<johnjansen>
there is alot of tidy up which could be done, but otherwise im happy for today … its a rush job as i have a rush project which i decided id do in crystal
<asterite>
I think the missing bit is $`, there was a discussion on our issue tracker about that... can't remember whether we decided it was a good idea to port the concept or not
<johnjansen>
its part of a classifier im re-writing …
<asterite>
Nice!
<johnjansen>
on that note, do you know much about kemel-klassify
<asterite>
No idea
<johnjansen>
i know its meant to be a port of a python tool (which BTW is slower than anything ive seen before_
<johnjansen>
ok no problem, cheers
<johnjansen>
this might be a dumb question, but any likelyhood of implementing destructive versions of some of the string methods etc, like chop! and gsub! etc …
Ven_ has joined #crystal-lang
<asterite>
johnjansen: not really, mutable strings have a lot of problems
<johnjansen>
fair enough ;-) its not such a burden, just thought id ask
<FromGitter>
<drosehn> In my own programming style, I prefer to use the more readable method names off of $~, instead of the 1-character special variables. So $~.pre_match instead of $`.
eizua has quit [Quit: Leaving]
Ven_ has quit [Ping timeout: 244 seconds]
<FromGitter>
<drosehn> It's probably true that part of the reason I do that is that I'm also prone to saving away one regex-result while doing a second regex. So ` somestr =~ /a/ ; sav_res = $~ ; rem = $~.post_match ; rem =~ /b/`, and then I use both save_res and $~ at the same time.
<johnjansen>
@drosehn the $` doesnt work in crystal anyway
<johnjansen>
i didnt know about $~
<johnjansen>
so thanks
<FromGitter>
<drosehn> Given that habit, it seems goofy (to me) to use $` for post_match of $~ at the same time as using sav_res.post_match.
<FromGitter>
<drosehn> I know that crystal doesn't have $`. I'm just explaining my own coding style in response to @asterite saying that he couldn't remember if the crystal developers had decided that it should eventually be added. (someday... :smiley: ). In my case, I'd prefer to go without any of the special $-variables which are shortcuts for methods of $~.
<FromGitter>
<drosehn> ... but that's due to the coding style that I prefer when writing ruby.
<johnjansen>
totally … in several years of ruby i havent tripped over those till today, and honestly there are far more explicit ways of doing the same thing
<johnjansen>
the guys who’s code im porting obviously knows what he’s doing, but it was very hard to find reference to the shortcuts he used, which made the port slower than it could have been (since i had to trap a bunch of variables, inspect them and then run them through the code to see what the result was)
Ven_ has joined #crystal-lang
Ven_ has quit [Read error: Connection reset by peer]
<johnjansen>
BTW @drosehn thanks for the $~.pre_match that enabled me to tidy up a bit in this case
<FromGitter>
<drosehn> That's what's nice about "just chatting" about code that you're working on. You never know when helpful tips will pop up!
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 244 seconds]
Ven_ has joined #crystal-lang
Ven_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
pawnbox has quit [Remote host closed the connection]
<FromGitter>
<raydf> Hi @johnjansen, are you gong to share the code so we can learn from the porting process?
<johnjansen>
hi @raydf feel free to fork and submit any changes you make to crystal-stemmer … it was a very easy port in truth, especially with the help of everyone here