<crystal-gh>
[crystal] spalladino opened pull request #4091: Parse suffix if/unless in macros after macro var (master...fix/4087-parse_suffix_if_in_macros) https://git.io/vyYMK
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 260 seconds]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 260 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 246 seconds]
olbat has quit [Ping timeout: 268 seconds]
olbat has joined #crystal-lang
olbat has joined #crystal-lang
olbat has quit [Changing host]
VectorGraphics has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 260 seconds]
ssvb has quit [Read error: Connection reset by peer]
snsei has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 260 seconds]
snsei has quit [Remote host closed the connection]
sz0 has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
akwiatkowski has joined #crystal-lang
VectorGraphics has quit [Quit: Leaving]
Qchmqs has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Read error: Connection reset by peer]
pawnbox_ has joined #crystal-lang
Qchmqs has quit [Ping timeout: 260 seconds]
pawnbox_ has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
soveran has quit [Remote host closed the connection]
pawnbox has quit [Ping timeout: 264 seconds]
pawnbox has joined #crystal-lang
mark_66 has joined #crystal-lang
akwiatkowski has quit [Ping timeout: 246 seconds]
gloscombe has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
bjz has joined #crystal-lang
akwiatkowski has joined #crystal-lang
<FromGitter>
<crisward> Any way to get the last line of a file? can't see `File.tail`
theodorton has quit [Quit: theodorton]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
theodorton has joined #crystal-lang
theodorton has quit [Client Quit]
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 260 seconds]
theodorton has joined #crystal-lang
<FromGitter>
<lhz> @crisward: unless you have some special knowledge about the content, you'd most likely need to read each line from the start and discard everything except the last line read. for all you know, it could all be one long line.
soveran has quit [Remote host closed the connection]
<FromGitter>
<crisward> I'm creating the file, it's a log file and I just want to get the last line. I'm using ``tail -n 1 my.log``
<FromGitter>
<crisward> Hopefully someone here understands memory better than me. My crystal process, using GS.stats has a heap of 3mb. However if I use top, the RES column says 9mb and the docker container it's running in says it 9.8mb. If anyone can explain this I'd be very interested. What I suppose I need to know is how much memory is crystal actually using?
<FromGitter>
<crisward> Ok.. I think the heap = RES - SHR. Which would be about right
stennowork has joined #crystal-lang
bjz has joined #crystal-lang
bjz_ has quit [Ping timeout: 246 seconds]
<stennowork>
is the github user Nax in here? i have a question regarding something unrelating (i.e. the nethack dumplog patch and its inclusion in the official source)
<stennowork>
unrelated*
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Qchmqs has joined #crystal-lang
mgarciaisaia has joined #crystal-lang
mgarciaisaia has left #crystal-lang [#crystal-lang]
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 264 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
fazibear has joined #crystal-lang
stennowork has left #crystal-lang ["Leaving"]
akwiatkowski has quit [Ping timeout: 260 seconds]
pawnbox has joined #crystal-lang
<crystal-gh>
[crystal] asterite closed pull request #4091: Parse suffix if/unless in macros after macro var (master...fix/4087-parse_suffix_if_in_macros) https://git.io/vyYMK
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vy3et
<crystal-gh>
crystal/master f58fd86 Santiago Palladino: Parse suffix if/unless in macros after macro var...
pawnbox has quit [Remote host closed the connection]
<bew78>
so cool, thanks RX14 ! I've seen somewhere that a macro must contain all it's code, and cannot delegate code generation to kind of sub-macros (like compile time functions, called from macros..), do I understand it well ?
<RX14>
you can call macros from macros
<RX14>
but it's quite slow
<RX14>
as it runs in multiple "passes"
gloscombe has quit [Remote host closed the connection]
<RX14>
the entire macro expansions are just looped over, expanding macros, until they stop changing
<RX14>
so you can call macros from macros
<RX14>
but you can't write your own functions which you can use inside {{ }} or {% %}
<FromGitter>
<drosehn> @crisward : One cheaper way to implement your own `tail` would be to open the log file, use `seek` to position yourself near the end of the file, and then have a loop reading forward. Unless those reads start at position-0 in the file, you should assume that you're landing in the middle of a line. That means you must ignore everything before the first `\n` (unless you know that you're starting at position 0). Then just read
<FromGitter>
... forwards keeping track of the most recent line.
<FromGitter>
<drosehn> @crisward : Note that you'd first want to call `File.stat` to know what the size of the file is. If you're going to check the last 300 bytes of the file, then you want to make sure the file *has* at least 300 bytes in it!
<FromGitter>
<drosehn> @crisward : there are some other details I'm skipping over. I have not implemented `tail` in crystal, but I've done it in other languages.
<FromGitter>
<drosehn> (if the file has less than 300 bytes, then don't bother with the `File.seek` and just read the entire file)
<FromGitter>
<crisward> @drosehn thanks. Crystal seems to be adding more file methods. My use case is on a known file for now so shelling out is fine. I'll take a look at file seek though, sounds interesting.
<FromGitter>
<drosehn> I suspect that `tail` would be a method to add to FileUtils.
<bew78>
RX14: why can't we define our own {{ my_function }} ? You mean 'currently we can't do that' or 'we don't want you to be able to do that' ?
<RX14>
well it's kind of both
<RX14>
i don't think it's really neccesary
<RX14>
most of the time you can achieve it by pasing macro vars into another function
<RX14>
plus it acts as a natural limiter for macro complexity
<RX14>
i don't want crystal to turn into mostly macros
<RX14>
macros should be the exception, and magic should be limited
<bew78>
Ok I understand, thanks
<bew78>
I have another question, is there a way to re-open String to change the meaning of some operators, but only in a specific block?
akwiatkowski has quit [Ping timeout: 240 seconds]
<RX14>
not only in a specific block
<RX14>
also, what you want to do is magic
<RX14>
it just sounds super weird to me
<RX14>
if you want to change string ops in only certain places wrap string
<bew78>
yes ^^ I could but the native String won't be detected as my String wrapper...
<bew78>
like `"blabla" + "something else"`
<bew78>
I'd like to override the + here
<RX14>
why?
<RX14>
why would you want to do that?
<FromGitter>
<fridgerator> just make a new method
<bew78>
to make DSL in crystal for crystal..
<RX14>
well if it's a DSL it's describing something abstract
<RX14>
and therefore it shouldn't be a string
<bew78>
I agree the + is not very clear.. Using `"blabla" | "something else"` in a parser generator would lead to an object describing a string consumer that can parse either "blabla", either "something else".... I'd like to be able to do this
<RX14>
hmm
<RX14>
i'd try as hard as you can to wrap the strings
<bew78>
RX14: I tried simple stuff in macro (should be possible), but I get a weird error, the assignement doesn't work as I think it should... https://carc.in/#/r/1olt
soveran has quit [Remote host closed the connection]
ssvb has joined #crystal-lang
<bew78>
why does the value of the macro variable assignation is used as macro expansion content ?
Ven has joined #crystal-lang
<FromGitter>
<asterite> bew78: {{ ... }} will write the expression to the macros' output, you probably want {% ... %} here
<bew78>
Oh yes, RX14 said something about macro variables in {{ }}, then in {% %}, and I mis-understood.. thanks
bjz has joined #crystal-lang
<FromGitter>
<drosehn> Hmm. I tried `{% puts %line2 %}` and that also got the error about `undefined macro variable 'puts'`
<RX14>
because %line2 doesn't make sense in a macro
<RX14>
not really
<RX14>
i think it's doing weird things top the lexer/parser/compiler
<FromGitter>
<drosehn> I'm just guessing my way through this, because I don't really have a good picture in my head of what's going on. (which is my own fault. I haven't looked into macros all that much)
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<Papierkorb>
drosehn, I think you're just confusing the different run times. Macros are expanded (= run) at compile-time, at run-time they just don't exist anymore. Normal code runs at run-time, and is processed during compile-time. You can think of macros being a program on its own: It can't know what the value of `%line2` will be, that would require a time machine :)
michael_campbel- has joined #crystal-lang
michael_campbell has quit [*.net *.split]
akwiatkowski has joined #crystal-lang
bew78 has quit [Ping timeout: 264 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Papierkorb>
tekjar, the cursor is still after the written data. There are no two cursors for reading and writing, there's only one for both. Use #rewind before reading it back
<FromGitter>
<tekjar> Ohh. Thanks alot
<FromGitter>
<tekjar> Papierkorb
<Papierkorb>
Can I steal an object from the GC?
<FromGitter>
<drosehn> The few times I've wanted a macro in crystal, I could get it to do what I needed it to do. But when someone else comes up with a macro-related question, it's clear that I haven't really learned how they work. (but I'm heading to dinner right now, so there's no need to help me out)
<FromGitter>
<drosehn> The version of `macro something` that I posted earlier does what *I* thought that bew78 wanted to do, and makes sense to me. But I didn't understand asterite's comment that "you probably want {% ... %} here".
<FromGitter>
<drosehn> So I tried "{% ... %}" in what I assume asterite meant, and that didn't work.
<Papierkorb>
drosehn, do you know about templating languages like ERB or ECR?
<Papierkorb>
drosehn, in ERB (iirc), <% x %> runs `x` but doesn't output its value - That's our {% x %}. <%= x %> outputs the value of `x`, that's our {{ x }}
Renich has joined #crystal-lang
<RX14>
@spalladino you around?
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
theodorton has quit [Quit: theodorton]
pawnbox has joined #crystal-lang
soveran has quit [Ping timeout: 260 seconds]
<RX14>
nevermind, replied to the email
pawnbox has quit [Ping timeout: 264 seconds]
Renich has quit [Ping timeout: 264 seconds]
<FromGitter>
<drosehn> (I'm back from eating) I'm aware of templating languages like ERB, but I have never used them for anything.