freenode/#lisp - IRC Chatlog
Search
0:29:15
fouric
how can i check to see if a given generic function is applicable to a given object - without actually calling the GF?
0:33:05
pjb
(defmethod moo ((a integer) (b integer)) (+ a b)) (find-method (function moo) '() (mapcar (function find-class) '(integer string)) nil) #| --> nil |#
0:33:21
pjb
(find-method (function moo) '() (mapcar (function find-class) '(integer integer)) nil) #| --> #<standard-method moo (integer integer)> |#
0:46:06
Bike
find-method finds, well, specific methods. with pjb's example, if you tried it with (#<class fixnum> #<class fixnum>) it would find no method, even though the method on integers is applicable to fixnums.
0:46:21
Bike
there's compute-applicable-method, which gives you a list of methods given a gf and arguments
0:46:45
Bike
however, even if there are applicable methods, they may not be enough to form an effective method, e.g. if there are :around methods but no primary methods
0:55:35
fouric
which gets called on an object when it doesn't understand a message that was sent to it
0:56:13
fouric
i came up with https://gist.github.com/fouric/595724587ecf6021ad4cfce4facf63dd but i don't think it works entirely correctly
0:57:27
Bike
if you're already in no-applicable-method, you can assume the generic function isn't applicable, no?
0:59:52
fouric
if it doesn't, then we need to just call the normal ("primary"?) no-applicable-method
1:00:19
pjb
(find-method (function moo) '() (mapcar (function find-class) '(integer fixnum)) nil) #| --> nil |#
1:00:40
fouric
...and then reason i don't just invoke does-not-understand off the bat is because otherwise we'll recurse infinitely
1:03:41
fouric
i'm sorry, i still confuse "generic function" and "method" with each other because in other languages they mean the same thing
1:04:41
fouric
or, rather, a class either defines special behavior, or the normal CL machinery is used to signal that there's no applicable method
1:05:49
fouric
it could just be printed out, or maybe logged to a file, or maybe the reason the function was called was because RPC, and a response needs to be sent back over the network instead of signalling a condition locally
1:07:11
Bike
how would the system even get to no-applicable-method if there is a method matching the first argument?
1:10:26
Bike
let's back up another step here. the code you wrote is illegal. you can't specialize no-applicable-method on nothing like that, since it would override everything in the system.
1:11:14
Bike
then if you do, you could have no-applicable-method call does-not-understand. if does-not-understand is a normal gf and not one of your custom gfs, no-applicable-method in the case of lacking a does-not-understand method would not go into your method and there would be no recursion.
1:14:20
Bike
but in general i think you'll have to think this through more. multimethods and complex method combination make CL generic functions pretty distinct from the smalltalk object system...
1:23:43
fouric
Bike: it would override everything in the system, but only for classes that didn't have a does-not-understand method defined, and that should be OK, right?
1:24:17
Bike
i mean, consider if someone else wnated to do something like this, and you both tried to define an unspecialized :around
1:27:55
fouric
i don't quite understand how :before/:after/:around methods are combined with primary methods
1:28:48
specbot
Standard Method Combination: http://www.lispworks.com/reference/HyperSpec/Body/07_ffb.htm
4:15:28
didi
Has anyone played with the idea of a function returning a variable number of values? For example, a matching function might return (values x) if I ask for a single match and (values x y z) if I ask for three matches.
4:22:27
White_Flame
when receiving the values, you probably want to multiple-value-bind with &optional or &rest
4:23:03
White_Flame
other than that, I don't think there's anything abnormal about it. It's supported by the language
4:23:48
White_Flame
SBCL might whine about optimization issues with the number of values not being fixed, depending on your speed setting, but it'll deal with it
4:33:27
White_Flame
yep, but if you set speed 3, it whines about every place it can't fully optimize
4:35:26
White_Flame
wrote it a long time ago, not sure how accurate it is for current versions: https://pastebin.com/Rmyazt4z
5:19:40
pjb
didi: (ql:quickload :cl-ppcre) (cl-ppcre:scan "(a)" "hello a world") #| --> 6 ; 7 ; #(6) ; #(7) |# (cl-ppcre:scan "(a).*(b)" "hello a world before") #| --> 6 ; 15 ; #(6 14) ; #(7 15) |#
5:20:44
pjb
didi: there's no difficulty in writing such a function. But if the number of values is not known at compilation-time, then you will have to use multiple-value-list and cons a list!
5:21:42
pjb
(loop repeat 3 collect (multiple-value-list (values-list (make-list (random 10))))) #| --> ((nil nil) (nil nil nil nil nil nil nil) (nil nil nil)) |#
5:21:47
White_Flame
multiple-value-bind and &rest, if used immediately and not passed around, has the possibility of not consing
5:27:28
slyrus__
I'm looking for a lispy approach to "time travel" through a modestly-sized (read: small) data set, where I want to be able to see the "state of the (again, relatively small) world" at a particular point in time. Anyone have any suggestions?
5:28:13
slyrus__
beach has a library called Clobber that might be a good place to start, but I figured I'd see if others have dealt with this or similar problems before.
5:28:53
White_Flame
either that, or keep a changelist of undo/redo function objects that you can use to traverse time
5:32:51
didi
SBCL seems to not care about not receiving some values. (multiple-value-bind (x y) (values) x y) => NIL
5:33:27
White_Flame
" If there are more vars than values returned, extra values of nil are given to the remaining vars. " - clhs
5:34:37
slyrus__
thanks White_Flame. I also came across this: https://github.com/smithzvk/Versioned-Objects which sounded like it might be what I'm after.
5:58:40
White_Flame
when performance is critical in inner loops, and you're guaranteed to not to be dealing with numbers or characters
5:59:17
White_Flame
(unless the numbers are guaranteed to be fixnums, but even then I think ABCL doesn't guarantee that fixnums are EQ)
6:08:11
pjb
verisimilitude: EQ is an operator that serves only to detect whether an implementation copies integers and characters or not.
6:08:58
verisimilitude
If you wanted to be mean, didi, you could write Common Lisp that behaves subtly differently between implementations based on whether objects that happen to be numbers or characters are ever EQ.
6:11:41
verisimilitude
EQL is more complex, purely because it can't simply compare a combined tag and pointer value to arrive at its answer.
6:14:57
pjb
verisimilitude: but forgetting about EQ frees some neurons for better things, and you don't have to think whether you can use it or not when you write code, and you don't have to ponder whether something special occurs with numbers and characters when you read it.
6:15:09
verisimilitude
You'll mostly be using EQL, though, didi. When in doubt between EQUAL and EQUALP, just use EQUALP if you're too lazy to look at the documentation.
6:15:41
verisimilitude
Sure, but why are you using Common Lisp instead of something else, at that point, pjb?
8:08:36
White_Flame
let-me-google^Wcliki-search-that-for-you.com: https://cliki.net/site/search?query=csv
8:09:16
White_Flame
including the recommended pages, pointing to cl-csv: https://cliki.net/Current%20recommended%20libraries
8:09:31
shka__
White_Flame: do you understand question "what is the fastest correct CSV parser for CL?"
8:10:11
shka__
i know that clicki exists, i know that parser exists, i just want to know if there is something faster cl-csv
8:10:11
jackdaniel
as you have noted, "correct" doesn't have much sense, "practical" is better; and I daresay all published libraries are practical to some degree
8:10:36
jackdaniel
as of "spped" you should benchmark it instead of asking. someone may tell you "this is the fastest" - how do you know it really is? maybe he didn't mbenchmark?
8:12:31
splittist
presumably a csv library has to deal with arbitrary csv, but your problem domain is narrower, so you could tune your own for higher performance (whatever that might mean)
8:13:38
shka__
splittist: i actually need something general, but maybe i can investigate cl-csv performance
8:14:10
White_Flame
I guess if you read-line, then have each field be a displaced-array into that line, that could work
8:14:37
White_Flame
however, if you have quoted fields with embedded quotes, eg "foo \"bar\" baz", you'd still need to re-render that string
8:15:05
White_Flame
presumably copying out those fields is slow, but read-line might also be a performance pig. You'll have to profile
8:15:51
White_Flame
also if you have quoted fields with embedded newlines, that mucks with using read-line cleanly
8:16:21
jdz
Also the strings that are enclosed in double double quotes so that the double quotes inside don't have to be escaped?
8:16:57
shka__
furthermore, even if i read the whole file into string and build stream on top of that, it does not improve performance dramaticly
8:17:25
jackdaniel
shka__: you claim that it is not I/O bound, so what is the bottleneck? I don't see cl-csv::check-and-dispatch symbol in said package
8:18:40
shka__
jackdaniel: https://github.com/AccelerationNet/cl-csv/blob/3eba29c8364b033fbe0d189c2500559278b6a362/parser.lisp#L359
8:19:05
Jachy
shka__: You could try fare-csv and compare? I'm curious how slow cl-csv is compared to, say, Python's csv module.
8:19:12
White_Flame
jdz: in some data, we ended up using ASCII field separators from the 0-31 control group
8:19:50
White_Flame
Jachy: when doing some comparisons like that, you never know if the python module is implemented in native code, too
8:20:50
jdz
Oh, maybe what I remember is a field that starts with a double quote, which basically translates to it starting with three double quotes.
8:22:23
shka__
anyway, there is stuff like this https://github.com/AccelerationNet/cl-csv/blob/3eba29c8364b033fbe0d189c2500559278b6a362/parser.lisp#L69 that makes me think that there is some potential for performance improvements
8:23:23
White_Flame
I don't think too many people have had need for high-performance csv reading; sounds like you've got a niche to fill
8:26:12
White_Flame
of course, some of the other libs on cliki might be faster for lack of abstracted features
8:31:06
White_Flame
given that the regex should be able to give you the index of the last character of the match, from which you can parse the next field
8:33:23
White_Flame
of course, if the field starts with a doublequote you'd probably still have to search for embedded quotes and perform a transform
8:33:47
shka__
i will try to tune cl-csv first though, writing my own csv parser is considerable undertaking
9:32:27
scymtym
is there an easy way to use gitlab.common-lisp.net's mandatory two-factor authentication without a phone or additional hardware?