freenode/#lisp - IRC Chatlog
Search
11:17:03
jackdaniel
when you acquire tao of programming you patiently wait for problems to fade away due to changed requirements, then you achieve the goal without even touching the keyboard ;-)
11:19:41
ogamita
(but then of course, it's Russian dolls: the internals are also decomposed into public API and clients, so you can test the internal APIs too).
11:20:54
ogamita
But the more internal the code, the more often it can change. The point of having API and distinguishing implementation from interface, is that you can change the implementation anytime, without breaking the rest of the program, since it only uses the public API.
11:21:19
ogamita
So if you test internal, as soon as you change it, you have to throw away the tests and write new tests for the new internals.
11:33:03
jmercouris
e.g. how can I go from (list :a "fish" :b "salmon") -> (list :a "fish" :b "carp")
11:36:27
shka__
alternative approach, sometimes usefull is to simply insert :b "carp" into front of the list
11:41:16
heisig
jmercouris: There is (let ((plist (list :a "fish" :b "salmon"))) (setf (getf plist :b) "carp") plist). But you are right, it is dirty.
11:51:42
beach
jmercouris: Since a plist is not an abstract data type, you should not expect anything better.
12:03:22
beach
What I am saying is that neither list not plist is an abstract data type, so you can't expect them to have identity-preserving abstract operations on them.
12:04:14
beach
Lisp provides excellent concrete data types, but you have to create the abstract ones yourself (mostly).
12:05:32
jmercouris
I don't get to choose the data type I'm working on without some complex transformations
12:05:33
beach
and a plist is but one possible concrete data type to build upon in order to create a dictionary ADT.
12:06:21
schweers
jmercouris: well, you could put the data into a hashtable or something similar, do your processing and create a new plist again (if needed).
12:07:26
heisig
jmercouris: The only reason to ever use plists is that their printed representation looks pretty. For anything else, use alexandria:plist-[alist,hash-table].
12:08:40
jmercouris
within the loop, my "product" is updated, but it is not updated within the products list...
12:09:29
schweers
I don’t think you can do that, as PRODUCT comes rom PRODUCTS. If you push to PRODUCT, that will not change the list PRODUCTS
12:10:03
jmercouris
so it stands to reason that modifying a PRODUCT within PRODUCTS will change PRODUCTS
12:10:41
schweers
If I’m not mistaken, PUSH creates a new cons, and sets the reference (in your case PRODUCT) to this new cell.
12:11:04
schweers
This will not change the list from which you are taking the list you are “pushing to”
12:12:19
schweers
you could collect the PRODUCT values into a new list, if you want to keep the rest of your code the same.
12:13:14
jmercouris
shrdlu68: pushing to the beginning of an alist when there is an existing entry with the same "key" means that the old key/value pair is still there
12:14:04
beach
jmercouris: What is the result of this code: (defparameter *l* '(1 2 3)) (let ((l *l*)) (push 234 l)) *l*
12:15:30
beach
jmercouris: Besides, you are not allowed to alter a list being iterated over in a LOOP.
12:20:16
beach
If TAX-PAYER inherits from PERSON then a tax payer (i.e. an instance of TAX-PAYER) is a person (i.e. and instance of PERSON).
12:20:19
schweers
beach: I’d like to thank you for your precise definitions. They may seem like nitpicking at first, but I am very glad you do this.
12:21:05
schweers
Of course it is, but not everyone knows all the details by heart (I certainly don’t).
12:21:25
jmercouris
I used to get angry at it, but I see the value in it now, at least within the context of a programming dicsussion, my significant other seems to disagree with regard to other topics...
12:21:28
shka__
shrdlu68: in this case list could be :initform '(:a "b") in defclass, and so it would be created during read time
12:23:50
beach
shka__: Which is why you hide the entire mutation behind an API so that you can make sure that the CONS cells you mutate are the ones you created yourself.
12:25:07
shka__
shrdlu68: lists are often created at the read time and also multiple lists tend to share tails
12:26:08
shka__
as beach said, if you need to mutate state you are better of making some kind of API
12:29:15
shrdlu68
I never thought about that, but I feel like this is a lesson about creating standard object...
12:51:19
jmercouris
so READ, it takes an input stream, so if you have a stream you have to make an input-stream and then pass it
12:52:08
jmercouris
sorry there was a typo above, I meant to say "so READ, it takes an input stream, so if you have a *STRING* you have to make an input stream and then pass it"
12:53:03
jmercouris
jackdaniel: ok, I read some misinformation on stack-overflow which made me not investigate, should have checked CLHS, thanks for tip!
13:00:18
jmercouris
and they come with corresponding functions/methods for manipulating those data structures
13:00:40
jmercouris
however I don't think there is a de-facto library, if there is, I am not aware of it, then again I'm not a good source, as I am not aware of a lot of things
13:08:49
larryba
is there a map function that only alters the elements, and leaves the data structure intact? so, if I pass a list, I should get list back. if I pass a string, I want string back
13:10:34
jackdaniel
doesn't he want something more like (prog1 sequence (map nil function sequence))
13:14:07
larryba
jackdaniel I don't know what that does, but based on my test with lists, shka__'s example works
13:18:25
larryba
(map (type-of input) ..) does that for strings, lists and vectors. which is good enough for me
13:19:24
jackdaniel
larryba: (map type function sequence1 sequence2 …) actually creates a new sequence which holds results of applying function to elements of enlisted sequences, it doesn't return sequence1 itself
13:20:55
margaritamike
What is the equivalent of the python request module for common lisp? http://docs.python-requests.org/en/master/
13:21:11
jackdaniel
maybe I've sipped to little coffee because it is still not clear to me what you are saying, I'll back off :-)
13:21:44
larryba
jackdaniel, if I pass it a list, it should return a list. if I pass it a vector, it should return a vector. etc. shka__'s solution does that, so all is good. :)
13:23:14
larryba
Xach, any reason to prefer that over (map (type-of thing) fun thing)? does it work with more containers?
13:25:25
jackdaniel
OK, word "identical" confused me, because function is not necessarily #'identity. 'of identical sequence type' would make it clear to me.
13:25:46
Selwyn
it is recommended as a catch all solution in 'Common Lisp Recipes' - admittedly published in 2015
13:26:16
splittist
margaritamike: what changes in the http protocol since 2017 are you concerned about?
13:27:32
Selwyn
margaritamike: in general, one can expect to use Common Lisp libraries not updated in that timeframe without concern, whereas this is not as common in, say, the Python world for various reasons
13:27:38
larryba
jackdaniel, (map (type-of input) (lambda (x) x) input) will return identical copy of input, in every regard. if compiler is smart enough, and input's type is immutable, it could even just return input
13:28:36
margaritamike
i'm cool with that, i just want to use what everyone else agrees on is considered the library to use for an http request library
13:28:40
larryba
(I guess none of the types that map supports are immutable, so that is just in theory)
13:29:02
jackdaniel
larryba: sure, that's why I've put there "because function is not necessarily #'identity", but I'll drop it, I know what you mean so there is no need to nitpick on my side ,p
13:31:19
Selwyn
i don't actually know of any others. i used the most basic functionality a couple of times without problems
13:32:01
larryba
shka__, lets say that, hypothetically, strings were immutable, map could just return input given (map 'string (lambda (x) x) input)
13:33:41
Selwyn
margaritamike: with regard to Python vs. Common Lisp, Common Lisp is defined with regard to a fixed standard since 1994 (?), whereas Python is not and changes over time.
13:34:22
Selwyn
this means that you can use Common Lisp code written portably some time ago without problems, whereas in Python there are the python2 python 3 incompatibility issues to start off with
13:35:08
marvin2
last time I checked most python programmers were still using 2.x, refusing to switch. not sure if that has changed recently
13:36:02
Selwyn
one of my biggest surprises when i started to use CL was that old code would simply run fine, i remember previously never having to rely on python code that wasn't updated in the last few months
13:36:59
jackdaniel
it is not as apparent thanks to Xach work to test at least briefly each QL release
13:38:58
Selwyn
jackdaniel: i am looking forward to try out mcclim on my new laptop when it arrives this week
14:56:51
ogamita
minion: memo for jmercouris: you can use sedit, the sexp editor. http://informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/sedit/index.html
15:00:29
ogamita
minion: memo for jmercouris: alternatively: (let ((plist (list :a "fish" :b "salmon"))) (let ((plist (list* :b "carp" plist))) (getf plist :b))) #| --> "carp" |# ; ie. functional style.
15:02:18
ogamita
beach: that said, person has two subclasses: moral-person and physical-person, so it'd be better if tax-payer was an OPTIONAL mixin… Just saying.
15:03:07
ogamita
or even, a reified association between a thug organization and a person, since a single person will often have to pay several thug organisation to avoid being molested.
15:04:36
ogamita
Some people, in particular biologists have used UML to modelize real systems (like, cell metabolism). Perhaps it'd be useful to study those models to give them as real-life examples :-)
18:28:13
pjb
So you could take the Molecule superclass, and its two direct subclasses Protein and Macromolecule.
19:03:44
asarch
Yesterder, TMA told me: "asarch: that does not mean that a function defined by DEFUN is unable to accept arguments of the desired type. it is just that there is no discrimination on the type of the passed argument, unless you write the discrimination yourself". In this context, what does "discrimination" mean?
20:05:58
dim
another term used for this concept is “dispatch”, in the context of generic functions and their methods
20:07:18
dim
asarch: maybe it's time for you to read http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html and http://www.gigamonkeys.com/book/object-reorientation-classes.html
21:35:22
pfdietz
In asdf, would it be considered better form to write a method for around-compile-hook, or call-with-around-compile-hook?
21:57:46
pfdietz
Does this combinator have a name: (c f g) ==> (lambda (x) (funcall f (lambda () (funcall g x))))
21:59:09
pfdietz
f and g are hook functions. They have no return value that matters. They're executed to set up an environment in which to call their arg, which is a thunk.
22:01:23
jackdaniel
back at the question about sequence copies: subseq guarantees a copy of the same type
22:11:05
xsperry
pfdietz, g has no return value that matters, yet you are passing the return value of g as a second argument to f?
22:12:04
pillton
xsperry: The function f may invoke the function argument to obtain the return value.
23:09:19
asarch
In fact, I wrote a shell script to render it into PDF: https://github.com/asarch/pcl