<gluon>
the typical cases of recursion, if the replacements list is empty, just return the original string, if the replacements list has only 1 pair inside, apply string-replace a single time with that, or else call string-replace-multi again with the rest of the list
<gluon>
works great in my code where i need to replace some html entities like for instance " with " or & with &
<gluon>
not a lot of substitutions
asymptotically_ has joined #racket
asymptotically is now known as Guest58286
asymptotically_ is now known as asymptotically
Guest58286 has quit [Ping timeout: 260 seconds]
lockywolf__ has joined #racket
lockywolf_ has joined #racket
lockywolf__ has quit [Ping timeout: 244 seconds]
orivej has joined #racket
Fernando-Basso has quit [Remote host closed the connection]
<tonyg>
srandon111: yes, it does. Building it is pretty slow though
<tonyg>
(because the pi is slow)
orivej has quit [Ping timeout: 258 seconds]
orivej has joined #racket
<srandon111>
tonyg, are there more minimalistic builds of racket ?
<srandon111>
tonyg, also is there a way to convert a racket application to an executable ?
<srandon111>
like exe or a linux binary file ?
lispmacs has left #racket ["rcirc on GNU Emacs 26.2"]
dimitarvp has joined #racket
dimitarvp has quit [Quit: Bye]
<soegaard>
srandon111: On download.racket-lang.org choose the distrubution "Minimal".
urbanslug has quit [Ping timeout: 248 seconds]
urbanslug has joined #racket
enderby- has left #racket ["Using Circe, the loveliest of all IRC clients"]
<srandon111>
soegaard, ohh i didn't know!! Cool!!
<bremner>
srandon111: you can make executables with "raco exe", but they are not as lean and mean as some scheme variants like chicken can managage
niceplace has quit [Disconnected by services]
niceplace has joined #racket
notzmv has quit [Read error: Connection reset by peer]
<srandon111>
bremner, but at the end... my customer would need racket to execute it right?
niceplace has quit [Disconnected by services]
<srandon111>
also bremner is there only a single graphical library in racket ?
niceplace has joined #racket
<soegaard>
srandon111: If you use `raco exe` then the necessary binaries are included, so your customer won't need to install racket.
niceplace has quit [Disconnected by services]
niceplace has joined #racket
niceplace has quit [Disconnected by services]
<soegaard>
There is a single GUI in the sense that `racket/gui` is cross platform. But it uses Cocoa on mac, gtk(2?3?) on Linux and Windows(?) on Windows.
niceplace has joined #racket
niceplace has quit [Disconnected by services]
niceplace has joined #racket
iyzsong has quit [Ping timeout: 276 seconds]
Arcaelyx has joined #racket
<srandon111>
soegaard, ok what about Qt or if someone wants something different?
<soegaard>
I don't know of any QT bindings.
<srandon111>
ok ok thanks..
dustyweb has quit [Ping timeout: 276 seconds]
<srandon111>
soegaard, how can i do async network programming in racket ?
<soegaard>
tonyg is the expert on that :-)
<soegaard>
You can use threads and use asynchronous channels to pass messages.
<dzoe>
soegaard: packed bits into fxvector did the trick
<srandon111>
soegaard, ok so but can i also do 3d programming with racket ?
<dzoe>
Tonight I will implement a merge sort for that a try to paralelize it using futures
<soegaard>
srandon111: Yes. There are bindings for opengl. Do you happpen to know opengl already? If so you can use it in the same manner as you do from C.
<soegaard>
dzoe: fun problem - impressed you got it working. The dataset sounded very large.
<soegaard>
srandon111: However I recommend looking into pict3d.
<soegaard>
If you use DrRacket you can see the results in the repl (and rotate everything).
sagax has joined #racket
lockywolf_ has quit [Ping timeout: 258 seconds]
lockywolf has joined #racket
ziyourenxiang has quit [Ping timeout: 245 seconds]
acarrico has joined #racket
<srandon111>
soegaard, drracket to me seems more like a sort of demo playground... probably is misleading... sorry for the dumb question, but other then educational purposes, can racket be used for serious programming ?
<srandon111>
sorry i am new to racket
<bremner>
srandon111: everybody has a different definition of "serious programming". What is it that you want to do?
<soegaard>
Don't underestimate DrRacket. There is a lot of neat features. But use it for racket only.
Sgeo has quit [Ping timeout: 245 seconds]
<srandon111>
soegaard, i do not underestimate it... but the text editor is limiting if you are used to vim
<soegaard>
The only thing that's on par when it comes to editing Racket is Greg's racket-mode for Emacs.
<soegaard>
True.
<soegaard>
One really nice feature of DrRacket is that when you get an syntax-error, the offending expression is hightled automatically.
Sgeo has joined #racket
<soegaard>
Could be a great project though - writing a proper racket mode for Vim?
niceplace has quit [Quit: ZNC 1.6.5+deb1+deb9u1 - http://znc.in]
urbanslug has joined #racket
urbanslug has quit [Ping timeout: 272 seconds]
urbanslug has joined #racket
manualcrank has joined #racket
<soegaard>
Curious: What editors is people using for non-racket related stuff?
urbanslug has quit [Ping timeout: 268 seconds]
<dzoe>
soegaard: emacs for everything local here, remotely mostly joe (with emacs bindings)
urbanslug has joined #racket
ubLIX has joined #racket
orivej has quit [Ping timeout: 245 seconds]
<dzoe>
soegaard: So with in-place merge sort (that extracts keys from the packed bit-value) I can sort the created 134M combinations in about 50 seconds on my laptop, totalling 3 minutes for solving the whole problem.
<soegaard>
impressive
<dzoe>
About 1G RAM used for the combinations and another 1G used as scratchpad for sorting.
<soegaard>
Not too bad.
<dzoe>
I find impressive how fast I got it working in Racket.
urbanslug has quit [Ping timeout: 268 seconds]
<dzoe>
I really got used to thinking very "high-level" (yes, scheme is addictive in general :) )
acarrico has quit [Ping timeout: 246 seconds]
<dzoe>
But this boils down to arithmetic optimisations I was programming in the 90's (software 3D renderers in C)
<soegaard>
I had similar experiences when I was obsessed with the problems from the Euler Project.
urbanslug has joined #racket
<soegaard>
The problem sizes were *just* big enough, so brute force couldn't be used.
<soegaard>
Finding symmetries or better representations were often the key to solving the problems.
urbanslug has quit [Ping timeout: 245 seconds]
urbanslug has joined #racket
orivej has joined #racket
<srandon111>
soegaard, i am learning racket can you help me with something? i was trying to implement as exercise a push function... i tried to do (define (push x list) '(list x))
<srandon111>
so i would expect to pass two parameters and return a list with x appended to list but it doesn't work
<srandon111>
what am i doing wrong?
<soegaard>
First: In Racket we don't change a list, but make a new one.
<soegaard>
So (cons 'a (list 1 2 3))
<soegaard>
will construct a new list (a 1 2 3)
<soegaard>
The original list (1 2 3) is part of the list (a 1 2 3).
<srandon111>
ok but actually what is my software doing? why it is not attaching the variables as cons.. ?
<soegaard>
So if have
<soegaard>
(define a-list (list 1 2 3))
<soegaard>
then (cons 'a a-list) will construct the list (a 1 2 3)
<soegaard>
however if we evaluate a-list we still get (1 2 3)
<soegaard>
So if you want the variable a-list to refer to the new list,
<soegaard>
you will have to use set!
<soegaard>
(set! a-list (cons 'a a-list))
<soegaard>
will construct a new list, and the make a-list refer to the new list.
<soegaard>
Now can we write push as:
<soegaard>
(define (push x a-list) (set! a-list (cons x a-list)) )
<soegaard>
?
<soegaard>
No.
<soegaard>
Each time push is calle the names x and a-list are bound to new values. So setting a-list inside push can not be seen on the outside.
<soegaard>
So what we do?
<soegaard>
When we write (push! x a-list) we mean (set! a-list (cons x a-list))
<soegaard>
So since we can't use a function, we will have to use a macro.
<soegaard>
(require syntax/parse/define)
<soegaard>
(define-simple-macro (push! x a-list) (set! a-list (cons x a-list)))
<soegaard>
It means that whenever we write, say, (push 42 my-list) we mean (set! my-list (cons 42 my-list))
<soegaard>
In languages where lists are mutable, pushing is simpler. One changes the list value that contains the elements.
<soegaard>
In languages where lists are immutable one can't change the existing list - one must create a new list.
<soegaard>
And at the same one must remember where the new list is.
<soegaard>
An alternative is store the list in a mutable container.
<badkins_>
gluon: re: your pasted code earlier, I think you can just remove your middle case (lines 8-11) with no adverse effect, right?
badkins_ is now known as badkins
<badkins>
maybe you were wanting to skip a function call for efficiency?
<gluon>
badkins: yes yes, i realised that soon after :)
<badkins>
ok :)
<gluon>
the recursion handles it already
<gluon>
i was never good at recursion, coming from imperative languages
<gluon>
but i'm liking it more now that i'm learning racket
<gluon>
reading a book about haskell and racket's online documentation taught me a lot about it
<gluon>
badkins: that said, i think it's actually better for performance if it stays there
<gluon>
because it avoid recursively calling the function on that particular case
<gluon>
but you're right, logically it's redundant
<gluon>
avoids*
<badkins>
I'd be curious about how much better. With the middle case, you have a call to eq?, and I wouldn't think the extra call to string-replace-multi is much slower than that i.e. a function call either way
<gluon>
good point
<gluon>
i should learn more about debugging and profiling in racket
<erkin>
Don't forget that premature optimisation is the root of all evil. ;-P
<gluon>
ahh, handy
<badkins>
what erkin said :)
<gluon>
:)
<erkin>
raco profile and raco check-requires are pretty nifty though.
<erkin>
I still need to get into errortrace.
<gluon>
i'm getting into contracts now
<gluon>
i mean, i already obey them, i want to impose them on my code as well
<erkin>
I found myself putting "raise-user-error" in edge cases in the code when I realised I should use contracts.
<erkin>
For instance, you can make your recursive factorial procedure check to see if the input value is inexact or negative on each iteration, or you can forbid it from taking anything but non-negative integers in the first place!
<dzoe>
soegaard: You were right - fixnums helped in all three stages: creating the combinations (packing everything into 63bits reduced memory usage and using unsafe-fx (via filtered-in require) sped up everything),,
<badkins>
srandon111: I have Racket running on a Raspberry Pi - if you're going to build it, I recommend using "built packages" and use the -j flag to use as many cores as your Pi has
<dzoe>
soegaard: sorting stage is the same - puting all indices into fixnums and following fx+, fx<, fxquotient ... the same
<srandon111>
ok thanks badkins
<dzoe>
soegaard: and for filtering unique combinations, the fixnum implementation is almost instanteous (like 3-4 seconds for my 134M records with about 70M unique).
<dzoe>
soegaard: but the most surprising is that replacing (for/fold ...) with custom (let loop (...) ...) sped up the initial combinations generation about 10-fold.
<badkins>
Hmm.... now I'm wondering how the Racket on Chez will affect running on the Pi. I guess I should see how well Chez runs on it.
<soegaard>
impressive speed up
<dzoe>
So now I am down to 1m9s on my laptop, which basically lowers my urge to parallelize the whole thing :)
ng0 has quit [Quit: Alexa, when is the end of world?]
<dzoe>
Also I am pretty sure, that futures won't do the trick with fxvector - as it would recognize the parallel access to it as future-unsafe operation ..
<soegaard>
dzoe: One thing that helps the speed of for/fold and frieds is to be explicit: use in-range, in-list, in-vector instead of using the implicit equivalents.
<dzoe>
So the other option would be places and shared-fxvector
<soegaard>
But `let loop` is of course the best way to control everything yourself.
<dzoe>
soegaard: it was (for/fold ((acc 0)) ((i 27)) (if (bitwise-bit-set something i) (+ acc somethingelse) acc))
<dzoe>
But the truth is I also replaced the bitwise-bit-set with explicit bit and (fxlshift bit 1) at each iteration
<dzoe>
I assume most of it then got optimized to a few machine instructions.
<soegaard>
I am a but unsure whether an explit 27 has a speed penalyt, but I would use (in-range 27) if speed is important (but you can check the expansion)
<soegaard>
penalty
<dzoe>
It's on my TODO list - which has (once again) grown quite a lot solving this ;)
<soegaard>
Are you using any non-Scheme features? It would be fun to see how fast it runs in ChezScheme?
<dzoe>
What do you mean by "non-Scheme"?
<soegaard>
Racket functions not in Scheme.
<soegaard>
for loops etc
<dzoe>
I am 99% sure, my programs are SICP2-compatible
<dzoe>
A few (for ((num maxnum)) ... are in the code now, but could be easily removed.
<dzoe>
And only in one case it is in the critical path.
<soegaard>
I am almost positive that ([num maxnum]) is slower than ([num (in-range maxnum])
<dzoe>
Btw, another impressive thing is the garbage collector. At least in 7.3 (didn't test anything else) it actually releases the memory back to the operating system.
<dzoe>
So after generating (1G), sorting (another 1G) and filtering unique combinations, the memory used is roughly (* 8 number-of-records) which is amazing.
<soegaard>
But since your program is plenty fast - no need to rewrite!
<dzoe>
Well...
<dzoe>
This is for 27 input numbers.
<dzoe>
For every single input more it will take rougly twice the time.
<dzoe>
And of course, when discussing how many inputs it might get, it ranges from "never more than 20" (cough, cough, already 27) to "maybe 30 or 40".
<srandon111>
it is a vimcmdline with support for racket so basically it is like using drracket but straight from vim
<srandon111>
cool
<soegaard>
srandon111: Try it. Then try out DrRacket and racket-mode and compare.
<soegaard>
One thing to look out for: When you have an error - can the editor open the file and go to the position in the file automatically?
<srandon111>
soegaard, i already tried it... it works
<srandon111>
flawlessly
<srandon111>
soegaard, i don't know about this... but already the fact of being able to send lines to the repl and have an immediate response is cool
<winny>
is there a list of fields for info.rkt? I know there is the documentation about get-info and info.rkt, but only the info.rkt documentation mentions a handful a fields
<soegaard>
winny: I think info.rkt documents how info files work - but the package manager uses info.rkt so the fields actually used are documented there.
<soegaard>
I have often looked at the wrong place in the docs.
<winny>
lmk if anybody figures out where that is :)
<winny>
I needed to look harder under the search results for info.rkt, maybe I should open a PR to add see also links to the relevant links for the info.rkt documentation
<winny>
thanks, this clears some things up =)
<soegaard>
+1 for a link from the info page to the other pages
<winny>
I see the link in the second link you shared to the link I shared now, that's a great start
ziyourenxiang has joined #racket
dustyweb has joined #racket
srandon111 has quit [Remote host closed the connection]
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sagax has quit [Ping timeout: 246 seconds]
badkins has quit [Ping timeout: 258 seconds]
sagax has joined #racket
acarrico has joined #racket
dmiles has quit [Read error: Connection reset by peer]