libera/#commonlisp - IRC Chatlog
Search
8:30:09
Guest86
May someone take a look at https://plaster.tymoon.eu/view/3813#3813 and suggest something? :]
8:39:30
beach
If you want to try things interactively, I suggest you use the CLIM listener. Then you can just issue calls to drawing functions, using *STANDARD-OUTPUT* as the stream.
8:44:57
Guest86
beach thank you for your suggestion to use CLIM listener but I would like to figure out things this way for the time being.
8:49:10
pve
Hi! I'd like to wrap the lambda expression I give to make-method-lambda with symbol-macrolet, like (symbol-macrolet (...) (lambda (...) ...)), but apparently this can't be done. Is there some standard way that I could manually trigger the symbol-macrolet expansion and end up with a lambda expression that I could then give to make-method-lambda?
8:51:29
beach
Guest86: Normally, your pane will be erased for each command in the command loop, so you need to define yourself a display function in which you do the drawing.
8:58:11
jackdaniel
Guest86: try (clime:with-output-to-drawing-stream (stream nil nil :width 800 :height 600) (draw-line* stream 10 10 90 90))
8:59:14
jackdaniel
in principle you may return the stream from the body and use it later for drawing, but remember to call finish-output on the stream to ensure some actual output
9:01:11
jackdaniel
if you want to have the real frame, then set :display-time nil as the argument to the application pane, and define a method that performs drawing, then execute it with execute-frame-command (which is thread-safe)
9:04:07
jackdaniel
you need to go through execute-frame-command because this function takes care of potential race conditions
9:05:00
pve
ok, i tried instead to do (funcall (compile nil `(lambda () (symbol-macrolet (...) ,method-lambda)))) on the resulting method-lambda, and it seems I can make a method instance using that :)
9:05:15
Guest86
beach, jackdaniel you are too fast on your replies, thank you for, but I need some time to think (defclass my-stream
9:14:38
Guest86
beach >your pane will be erased for each command in the command loop, so you need to define yourself a display function in which you do the drawing. May you write an example code that defines a display function in which the drawing is done?
9:26:03
jackdaniel
there's that, and there is also a tool called grep to find numerous examples that make use of handle-repaint
9:28:45
Guest86
beach >That is not something you will need for most applications. May you give me an example of code that is being used in most applications then?
10:16:30
zest
when implementing a network protocol in common lisp, should one concern with using a library like fast-io? or just use the default common lisp I/O functions...
10:25:17
Gnuxie
the messages from IRC aren't making it here, my messages are making it through to there but not yours (see https://irclog.tymoon.eu/libera/%23commonlisp)
10:28:29
ogamita
zest: CL doesn't have network API, so you'd have to target some network API anyways. Most often, Gray streams are used to provide a kind of stream connected to the network, so you may use usual CL I/O operators.
10:29:10
ogamita
zest: but mind that while network API may provide something like a stream abstraction over their connection, it's not always entirely transparent, so depending on the application, you may prefer to use the network API directly. It depends.
10:31:32
ogamita
zest: I tend to use usocket as a portability library (combined with CL I/O operators when using streaming protocols).
10:32:36
ogamita
zest: note also how it depends on the architecture you choose: either multi-thread with usual control flow (and therefore blocking CL I/O operators), or event-loop based, with non-blocking I/O operators.
10:33:28
ogamita
zest: and, what I like most too, you may also implement a network protocol without using any I/O or network API. Just define your up and down API, and let the client hook them to actual I/O or whatever network API he wants.
10:35:13
ogamita
zest: this is what I did eg. in my telnet implementation: https://gitlab.com/com-informatimago/com-informatimago/-/blob/master/common-lisp/telnet/telnet.lisp
10:35:44
ogamita
https://gitlab.com/com-informatimago/com-informatimago/-/blob/master/common-lisp/telnet/telnet.lisp#L345
10:37:55
ogamita
(see test.lisp, it's a kind of mock test of telnet.lisp, which is 100% natural when you structure your code like this with clearly defined APIs and no dependency).
10:40:17
ogamita
zest: in https://gitlab.com/com-informatimago/com-informatimago/-/tree/master/clext/telnet there's a client for the telnet protocol package. (there may remain bugs in that client).
10:40:17
zest
ogamita: i understand what you mean, that was really helpful. I think I will go with your approach and leave the I/O and network for the client
10:42:26
zest
but should the parameters octet-vectors or streams? I know streams can be bufferred and that gives the client more room to play with performance but I also want to unit test my functions...
10:44:14
ogamita
Again, it depends on your requirements. For maximal portability, you may prefer octet-vectors, since that allows the client to use any kind of I/O it wants. On the other hand, indeed, using a streaming operators makes it simple and convenient (this is why eg. CLIM make the effort of using STREAM to let the application communicate with the GUI backend.
10:46:53
hamza
So anyways, in short I wanted to type variables inside my LOOP, I know I could extract it out to a let and then use that in loop typing that with declare, but is there a shorter way/
10:47:54
Guest86
jackdaniel>they are written so people can learn, that's literally their purpose. Well, let's take a look into A guided tour of CLIM Our first application chapter. We find how to define-application-pane and how to make-pane but when we arrive at using a method we can not figure out how it works with hello-world frame. At this point learning process
10:47:54
Guest86
comes to logical end. May be it is a time to revise the guide and examples as well?
10:54:07
ogamita
with a little script to pipe easily: #!/bin/bash \n nc termbin.com 9999 | tr -d '\000'
10:54:21
hamza
zest: I solved the problem in 5 minutes but couldn't optimize it. I am thinking of using primes then
11:01:04
hamza
1 thing is that divisor-count is MUCCCH faster now especially for even numbers, but p12 takes the same amount of time even after timing I know, kind of premature optimization
11:02:05
hamza
Running it, I ccouldn't get an answer under a minute or even after a minute lol so uhhhh probably need to change algo
11:02:53
zest
ogamita: thanks guess I'll go with streams since the protocol I'll use will do file transfers...
11:05:47
zest
hamza: A list wouldn't work, you need a hash-table since a hash-table's efficiency doesn't worsen with size
11:06:28
zest
hamza: I think if you wanted to, you could make a version of p12 that's 3 lines if you used pure recursion
11:23:50
beach
With every new candiate prime, you need to test all previously computed primes to see whether one is a factor.
11:24:21
beach
And it is best to do that from the smallest one, so that you are more likely to hit a factor and decide the candidate is not a prime.
11:27:02
beach
zest: You wouldn't attempt to access the already computed primes in some random order, so a list is just fine.
11:30:12
beach
Oh, maybe I didn't read very carefully. The task was not to implement the sieve, was it? Sorry!
11:30:28
hamza
wait so now that i got the divisors that are primes, now for every prime divisor i found i should go through the list and multiply by each one? and repeat that?
11:58:52
hamza
Actually divisor-count is MUCCHHH faster, However, again, it isn't able to catch all primes
12:02:55
hamza
Here is what I got, I could obviously optimize this ALOT but it doesn't need it getting the divisors of a really large number is sub millisecond
12:26:21
hamza
lol, I kept looking for faster divisor algorithm and they all decieved me because they calculated from 1 to sqrt of n but that missed some numbers!
12:27:10
hamza
I didn't realise that each of the numbers uptill sqrt n, n came in each one of those number's table
12:30:35
zest
loop exists for a reason and that is to stop people like write me from writing recursion functions
12:31:06
hamza
srsly, in the middle after learning haskell i wanted to write everything in recursive functions, turns out that's not always the best ;)
12:32:39
hamza
Uh the entire problem wasn't able to finish even after 1 and a half minute, so there is that. But here, I get the answer in .703 seconds