freenode/#lisp - IRC Chatlog
Search
15:02:31
kuribas
I got this question on an interview: without using regexps, extract all numbers from a string. For example "123abc456" => (123 456)
15:02:49
kuribas
here is my solution: https://gist.github.com/kuribas/cd0f725b9de6ff909326ad2856441943
15:05:14
_death
the answer is: yes. read the parse-integer entry, note junk-allowed and the secondary return value
15:07:36
_death
if you want something closer to your haskell program, you can define group-by etc.. language is raw material
15:13:21
makomo
pjb: what is the difference between (position-if ...) and (position-if ... :start 0)?
15:17:10
pjb
com.informatimago.common-lisp.cesarum.list:nsplit-list-on-indicator is similar to your groupBy
15:19:38
_death
you can (loop for group in (group-by #'digit-char-p string) when (parse-integer group :junk-allowed t) collect it) .. just need to write group-by
15:23:16
pjb
kuribas: you should read: https://www.thocp.net/biographies/papers/backus_turingaward_lecture.pdf
15:25:02
pjb
You can see that you may easily implement a library of operators in lisp to use this programming style.
15:25:45
kuribas
pjb: ah I see. This video is also great: https://www.youtube.com/watch?v=XrNdvWqxBvA&t=47s
15:31:04
Beep-Lord
Anyone know how to get the address of a foreign function with cffi? I have used defcfun and want to get the pointer using the symbol used for defcfun.
15:43:08
_death
f-s-p is the primitive you're looking for.. it needs a string indeed.. with defcfun, the lisp name is arbitrary, and there can be multiple lisp names for the same foreign name
15:43:52
_death
so if you want you can maintain a mapping from symbols to foreign names and write something to lookup and call the primitive
15:50:28
_death
you can patch cffi's %defcfun so that it will attach a foreign-name property to the symbol.. or define your own defcfun of course
15:55:03
kuribas
version 2: https://gist.github.com/kuribas/cd0f725b9de6ff909326ad2856441943#file-all_nums-lisp
15:56:34
Xach
can anyone tell me why I get this error? http://report.quicklisp.org/2018-06-24/failure-report/gsll.html#gsll
15:58:33
pjb
kuribas: instead of (lambda (c) (not (digit-char-p c))) you can write (complement #'digit-char-p)
16:00:56
pjb
there's one in alexandria, and there's a composition macro in com.informatimago.common-lisp.cesarum.utility:compose : (compose sin cos)
16:04:12
_death
Xach: note comment https://gitlab.common-lisp.net/antik/gsll/blob/master/solve-minimize-fit/nonlinear-least-squares.lisp#L149
16:56:31
Ukari
is there a class or struct for representing nil? for example, (defmethod test ((x nil)) (print "nil"))
17:19:54
Beep-Lord
LdBeth, doesn't org-mode have a way to export to LaTeX? You could probably examine some of its exported code to see what it does with inline code.
17:49:42
makomo
Ukari: if you want to specialize on nil you can use EQL specializers: (defmethod test ((x (eql nil))))
17:52:13
Ukari
makomo, is it possible to write like this ? (defmethod test ((x (or null function))) (print "null or fun"))
17:53:18
makomo
Ukari: nope. a specializer can either by a CLOS class name or the special EQL specializer of the form (eql <something>) where <something> will be evaluated when the method is defined
18:00:12
pjb
Ukari: (defun test/null-or-function (x) (print "null or fun")) (defgeneric test (x) (:method ((x null)) (test/null-or-function x)) (:method ((x function)) (test/null-or-function x)))
18:03:43
makomo
Ukari: it's not that it doesn't support multiple arguments, it just doesn't support multiple *specializers*
18:05:49
pjb
(or x y) is a TYPE designer. There is no such thing for classes, (but perhaps, mixing subclasses: (defclass foo (a b) ()) but 1- it's not possible with built-in classes, 2- it's more like a AND than an OR.
18:08:34
Ukari
which is recommand to use when have multiple types? single defgeneric or multi defmethod?
18:09:19
makomo
Ukari: you need both a defgeneric and a defmethod. the example that pjb wrote showed an "inline" definition of a method using the :method option with defgeneric
18:09:23
pjb
If you have multiple types, you have to use TYPECASE (or CTYPECASE or ETYPECASE) explicitely.
18:11:23
Ukari
i found that it also supports struct and null in defmethod, are null and struct both a kind of classcase?
18:11:29
pjb
Class types are just a gateway between CLOS and CL minus CLOS, so that you can use TYPECASE with CLOS instances. But they're not useful otherwise. If you have classes, then just consider classes and do OOP. If you have types, then do usual procedural programming using typecase.
18:17:18
makomo
i'm not 100% sure how accessor (:writer, :reader, :accessor) properties are inherited
18:17:33
pjb
Ukari: but be careful when reading clhs, because the information is spread all over the place. For example, clhs defstruct says "defstruct defines a structured type, named structure-type, with named slots as specified by the slot-options." but in the description of the :type option, it also says: "defstruct without a :type option defines a class with the structure name as its name. The metaclass of structure instances is
18:18:18
pjb
Ukari: this means that not all "structures" are classes. (defstruct point x y) -> defines a type and defines a structure class. (defstruct (point :type vector) x y) -> only defines a type!
18:19:20
pjb
Ukari: this is why if you just say that you have a structure, and moreover, if you say that you have a structure TYPE, then you CANNOT use defgeneric/defmethod because you've not affirmed you had a structure CLASS!
18:20:08
pjb
ebrasca: you can definitely add accessors to slots. And also change the type (as long as you respect the Lyskov substitution principle).
18:22:07
pjb
ebrasca: everywhere you have an instance of a class, you must be able to substitute an instance of a subclass and it should still work.
18:23:02
makomo
ebrasca: but why exactly would you want a different accessor for the same slot? what's the rationale?
18:23:05
pjb
ebrasca: this means that if you change the type of a slot in a subclass, you must still be able to to store the all the values of the type defined for the slot in the superclass, and the reader should not return any value outside of that type.
18:23:49
pjb
This is why it is in your best interest to NOT specify any type to the slots of your superclasses or pre/post condition to methods of your superclasses!
18:24:56
ebrasca
makomo: ext2 https://wiki.osdev.org/Ext2#Superblock , ext4 https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#The_Super_Block
18:25:28
makomo
ebrasca: you'll have to explain that to me in the context of your CLOS model. i can't really go and read that
18:25:47
pjb
(On the other hand, if you specify types and pre/post conditions in the superclasses, and respect them in your subclasses, you benefit greatly from OOP; few people understand it, and end rejecting OOP entirely, because they've spend all their time kludging and hacking around this).
18:26:53
pjb
sometimes you need to enforce additionnal or different constraints, (but for additionnal constraints, you should just override the usual accessors).
18:27:22
pjb
But it's right that it may be a hint that you're doing something very wrong: using subclassing for implementation, instead of structurally!
18:28:30
pjb
ebrasca: don't look at what C coders wrote! They do horrible things, like reusing memory for different purposes, etc.
18:29:12
makomo
what pjb said ^. it doesn't necessarrily follow that the best model is ext2 <- ext3 <- ext4
18:30:03
pjb
Well, you can mount an ext3 device as an ext2, IIRC. The journal is stored separately, and it will be rebuild when you remount it as ext3.
19:33:28
Ukari
(defun test (&optional x)), how could i know the difference between (test) and (test nil) ?
23:09:49
drmeister
How does write-to-string decide what width of character string its supposed to write to?
23:38:22
pillton
aeth: Was this a question about specialization-store? "All that's really missing is a defmethod that supports inline and classes for keyword/optional (which iirc are not supported, possibly because of the ambiguity in a straightforward attempt)"
23:55:33
mega_beginner
Out of curiousity, is locality of reference a concern in lisp when writing code that usually requires it in C/C++/Fortran (insert "fast" language here) (such as matrix multiplication)?
23:59:40
mega_beginner
I guess I have a nagging misunderstanding of how things operate at a lower level in lisp short of dissassembling everything.
0:09:25
White_Flame
yeah, disassembly is great to learn from, especially when it comes to performance, or simple curiosity of how things are implemented
0:10:03
White_Flame
I have a (asm (..params..) ..body..) macro which disassembles a lambda with optimizations cranked, just to see what SBCL can pull off
0:12:33
mega_beginner
Next thing I'll have to read up on is incremental compilation, and how things are referenced in light of that technique (compiled to raw address label or hash table lookup for example). I have to leave though
1:18:39
epony
I'm interested at what point it starts getting "ecosystem" before other discussion points are closed.
1:19:18
aeth
makomo: Accessors aren't just methods defined by defclass automatically. They're anything with a reader and/or writer. CAR is an accessor and e.g. WITH-ACCESSORS should work with it.
1:22:41
pillton
aeth: Ok. The return type in specialization-store is needed to allow compile-time optimizations to occur when one store function is composed with another.
1:23:23
aeth
pillton: My original point in full, which I didn't communicate well (but no one was really responding to it and I didn't want to flood the channel with corrections) is that there are effectively three incredibly similar operations.
1:23:59
aeth
pillton: It's pretty easy to write a macro on top of defun to handle things that otherwise would require declare/declaim/etc. At the very least, it's the easiest of the three to do.
1:25:07
aeth
The thing that's missing, then, is CLOS defmethod-style dispatch that's "completed" with inlining and with full support for keyword/optional
1:25:59
pillton
This is where I get lost. specialization-store supports dispatch on optional and keyword arguments.
1:26:55
epony
a surgeon is called on an emergency, a relative is accepted in emergency in a different location