freenode/lisp - IRC Chatlog
Search
11:44:06
phoe
Is anyone aware of some kind of server in Common Lisp that can accept an arbitrary number of TCP connections and pushes the messages it receives into some sort of queue?
11:44:37
phoe
I'm fed up with trying to write a robust one myself and I'd rather use a solution that doesn't break in subtle ways.
11:50:00
shka__
there are some tricky things in the API like dropping messages, high water marks but there is a plenty of people using this already so getting help should be simpler
11:50:34
pjb
phoe: Not at the level of TCP connection, but of IRC message, there's the botil example: https://github.com/informatimago/lisp/tree/master/small-cl-pgms/botil
11:50:51
pjb
phoe: https://github.com/informatimago/lisp/blob/master/small-cl-pgms/botil/design/f-botil.png
14:17:38
schweers
shangul: maybe you can create a large integer out of your fraction and emit it. placing the string "3." in front of it
14:20:15
jackdaniel
common lisp has bignums, *yes you can* ,) admittedly that depends how much memory you have on your system
14:20:53
White_Flame
if you multiply by 1000, for instance, then FLOOR it to an integer, the rendering of it might be "1234567" which would correspond to "1234.567"
14:21:54
White_Flame
that would be your input requirement, in this case "I want 3 decimal digits of fractional precision"
14:22:26
jackdaniel
shangul: I think you need to be more precise with "what you want" before anyone can give you better hints on how to do that
14:22:30
White_Flame
and you could go as high as you want, well beyond what built-in floating point gives you
14:23:35
White_Flame
the reason I asked about precision is that if your requirements fit in single or double floats, just use those
14:24:11
shangul
I'm trying to calculate Pi. I've written a function returning a fraction/ratio which is Pi but I'm not sure how can extract digits of Pi
14:26:48
shangul
White_Flame, the problem is that I don't know how many digits I want. In that case 1000 was just an example
14:27:06
White_Flame
however many iterations your calculation performs determines how precise it gets
14:28:24
schweers
This seems to be a case of not understanding the problem space well enough. This does not necessarily have to do anything with lisp.
14:28:59
White_Flame
well, with arbitrary precision floating point libs, there could be specifics about them
14:29:46
White_Flame
also, there are algorithms to calculate arbitrary decimal digits of pi, random-access style, iirc
19:22:31
Xach
skidd0: slot-boundp is a function, and follows normal evaluation rules. so to pass a name (represented by a symbol) you must make sure the argument evaluates to the right symbol. it's common to use ' for that.
19:23:02
Xach
(slot-boundp p 'google-product-type) might work if the current package is appropriate.
19:23:34
Xach
skidd0: no. p evalutes to the object instance. the second argument must evaluate to the name.
19:23:42
mfiano
No, it should be exactly what Xach wrote, assuming your slot name (not accessor) is GOOGLE-PRODUCT-TYPE
19:24:04
Xach
or to a symbol, rather - whether it's the right one depends on how the class is defined.
19:27:16
pjb
skidd0: (defclass point () ((x :initform 3) (y))) (let ((object (make-instance 'point))) (slot-boundp object (progn (write-string "what slot?" *query-io*) (finish-output *query-io*) (read *query-io*)))
19:28:16
skidd0
okay, got it working now, thanks. so the quote operator ensures i'm passing in the symbol google-product-name rather than evaluating google-product-name and passing the evaluation in?
19:28:33
mfiano
In Common Lisp, arguments to functions are evaluated before the function is applied to those values, so it's common to use QUOTE to prevent evaluation in this case, since you only want the name of the slot, not what symbol-value may be currently bound to the symbol.
19:30:08
pjb
(slot-boundp (make-instance 'point) (intern "X")) #| --> t |# (slot-boundp (make-instance 'point) (intern "Y")) #| --> nil |#
19:56:17
refpga
Hello, how can I convert a list of lists and atoms to a single list of atoms? like (5 (2 3) (45 7)) to (5 2 3 45 7). Earlier I was using (reduce #'append list) but that only works if all the elements of the list are lists.
19:57:40
mfiano
Keep in mind, a vectors are atoms too. If you would like it to flatten array elements as well, it requires a slight modification.
21:42:06
vms14
https://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html
21:42:38
vms14
I'm avoiding to use let, it's right to avoid using let and prefer optional arguments?
21:43:27
pjb
vms14: technically, for local variables you could use &aux, but let is more readable IMO.
21:43:55
pjb
vms14: I mean that &optional is an input to the function. You don't want the callers to be able to mess with your local variables (at least their initialization).
21:44:21
pjb
&aux is made for macros, to avoid having to parse the bodies for declarations and docstrings.
21:45:22
pjb
vms14: now, if you want to use an accumulator, you could use a local function with LABELS. But any non-mandatory parameter will be slower to process, so you definitely don't want them in "inner loops" ie. inner recursions.
21:49:06
aeth
vms14: In case it's unclear, then len you wrote shouldn't be exposed to the user. Just make it a second function (or an internal function with labels) and have the actual len only take in a list
21:49:21
aeth
This is a common pattern for tail recursive functions, which are more of a Scheme thing than a CL thing
21:50:37
aeth
vms14: This is how I implemented infix s-expressions (i.e. it's not "1+1" it's (1 + 1)): https://gitlab.com/snippets/1747132
21:54:33
aeth
It has been a while since I wrote that code but it looks like I handle nil by simply checking for the existence of tail before calling the next iteration
21:55:04
aeth
Instead of the more traditional way of having a case that handles endp (or null) at the top of a cond
21:56:23
aeth
I guess maybe I should handle the empty list at the top level (before the labels recursion) but that's not really an infix list if it's empty and there's no symbol. An infix list basically requires 3 elements as its minimum.
21:58:07
aeth
Well, speaking of reader macros... someone was talking in another Lisp channel a week ago about how C++ has the ugliest hello world so I reused my infix parser to make this: https://gitlab.com/mbabich/lisp-hello-world/blob/c45deaab9918285d3de43c52340100fef6591d15/main.lisp
21:59:12
aeth
I did it very quickly. With more time, I could probably make it semantically match C++ more (but then I'd have to relearn that part of C++ first)
22:00:24
aeth
All I did was turn that infix function into a macro (a one-liner) and then wrote a << macro in 10 lines and then wrote a reader macro in 11 lines
22:00:54
aeth
It didn't take m uch to turn parse-infix-list into a reader macro. https://gitlab.com/mbabich/lisp-hello-world/blob/c45deaab9918285d3de43c52340100fef6591d15/infix.lisp
22:01:23
aeth
Unfortunately, it's not portable because a Lisp implementation doesn't have to implement tail recursion... although I really hope you wouldn't blow the stack with a massive amount of infix.
22:04:33
aeth
refpga: get it to be printed to the SLIME REPL and then: right click and inspect or M-x slime-inspect-presentation-at-point or C-c C-v TAB
22:11:45
vms14
but I see there is usocket and should work on most implementations, so will make it more portable