freenode/lisp - IRC Chatlog
Search
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
1:14:56
randyjohnson86
perhaps a controversial question, but how long would one normally say to become familiar with the general lisp syntax?
1:18:12
wavemode
once you start using it to make small projects you will pick it up like any other language's syntax
1:18:55
randyjohnson86
yes, I'm slowly working my way through 'a gentle introduction to symbolic computation' by touretzky
1:19:44
randyjohnson86
it's rather quite fascinating, but I still find myself making little things in python rather than practicing my lispcraft
1:21:23
Xach
I use lisp for small things because of the nicer support for interactive ongoing development and debugging.
1:24:31
no-defun-allowed
you can use lisp on the boat, on the house, on the pets, in the kitchen, there's nothing you can't do with lisp
1:30:58
randyjohnson86
I think it will take some more time to get into the rhythm of it, it's a lot to undertake in a few settings