freenode/#lisp - IRC Chatlog
Search
23:43:45
emaczen
Does the CFFI groveller parse each include file, find the struct definitions and then write the defcstruct forms?
23:47:40
jasom
emaczen: I think it writes a C program to print out size and offsets, then compiles and runs the C program.
23:50:11
emaczen
jasom: I wrote a tiny program to do what you are saying to find constants and the sizes of structs
23:52:02
jasom
emaczen: it can (non-portably, but usually works) be implemented as #define offsetof(st, m) ((size_t)&(((st *)0)->m))
0:12:52
jasom
cl-autowrap actually parses and extracts types and things but I didn't think the groveller did.
0:13:26
jasom
emaczen: C11 lets you do it, but most programs don't target that version yet so may not work in C11 mode.
0:16:19
jasom
emaczen: especially since many APIs define what fields there are and their types, but not their order.
1:09:02
emaczen
Bike: I don't see how sizeof and offsetof could distinguish between types with the same sizes
1:13:57
|3b|
at least i hope people wouldn't make APIs where something is a float sometimes or an int other times
1:16:07
|3b|
i'd expect most actual changes in struct definition per platform to be things like using different sized ints, assuming just taking native int size wasn't good enough
1:19:40
Bike
for the groveler you can specify the types in a struct. dunno if that's required, it's a &key
1:20:08
|3b|
looks like it does https://github.com/sionescu/iolib/blob/master/src/sockets/grovel.lisp#L89
1:23:20
|3b|
and cffi-grovel includes ctype https://common-lisp.net/project/cffi/manual/html_node/Groveller-Syntax.html
1:35:06
emaczen
Bike: I had written my own groveller minus the C structs a few weeks ago, and I just added the C structs
1:35:58
emaczen
I looked at the types of structure members earlier today when I was manually typing defcstruct and I noticed differences
2:38:16
russellw
what's the shortest way to add an entry to an alist? I mean, you can use a pair of cons calls of course, but is there a shorter form?
2:39:37
no-defun-allowed
(push (cons key value) alist) and (setf alist (acons key value alist)) are common
4:47:32
anamorphic
Is it possible to pass multiple values for a (setf foo) form? Something like this (defun (setf foo) (new-value) (multiple-value-bind (x y) new-value (list x y)))?
4:50:11
emaczen
anamorphic: It is also a good idea to write your own macros for when you wish to further customize what you want
5:02:44
aeth
(setf (foo) (values 1 2 3)) is very useful. it composes well with (setf (foo) (foo)) where (foo) is a function that returns multiple values
5:03:09
aeth
You can also do (setf (values x y z) (values 1 2 3)) which makes me wonder why you can't do that in let, which would make multiple-value-bind unnecessary
5:04:34
|3b|
you could add (function x) to that and get rid of flet, add (special x) and get rid of special declarations too :)
5:07:48
anamorphic
I did some reading... apparently there's a setf* in CLIM that does this for output record x/y position
5:09:15
aeth
Actually, I might get rid of define-destructuring-function, actually. It's just like define-function except the first argument is destructured, so (define-destructuring-function foo ((foobar baz) quux) ...) instead of (define-function foo (list quux) (destructuring-bind (foobar baz) list) ...)
5:09:36
aeth
But the whole prefix thing is an interesting idea, and I could just say (destructuring (foobar baz)) or something
5:12:04
aeth
anamorphic: Oh, and when you mix the multiple-value accessors like (setf (foo quux) (bar baz)) with symbol-macrolet/with-accessors you get (setf foo bar)
5:14:08
fiddlerwoaroof
The nice thing about a lisp is that the community generally doesn't have to accept your preferred syntax
5:18:10
aeth
anamorphic: symbol-macrolet is how with-accessors is (probably) implemented and is necessary if you want to use fancier accessors (such as aref)
5:18:33
beach
One major advantage of Common Lisp is that a serious project can choose the language for a long-term project, knowing that the standard will remain as it is, that the language won't evolve according to the whim of some benevolent dictator who is ignorant both when it comes to programming language design and compiler technology.
5:19:16
beach
... and that there are several implementations, free or commercial according to the needs of the project, that implement that standard.
5:19:46
fiddlerwoaroof
Yeah, I really wish more "modern" languages were implemented as compilers to CL
5:20:20
fiddlerwoaroof
ACL2, Shen, etc. show that this is possible and CL is a much nicer target than C or lower-level stuff, if you don't need performance
5:21:10
fiddlerwoaroof
(that is, if you're not in a domain where you need real-time guarantees, etc.
5:21:15
Jachy
That still wouldn't help much though when the younger languages update and make breaking or incompatible changes...
5:21:44
beach
fiddlerwoaroof: There are very few modern "languages", if by "language" you mean an independently published specification of the syntax and semantics of valid phrases, and the consequences of submitting invalid phrases to the compiler.
5:22:46
jackdaniel
Jachy: if your target language of compilation is CL nothing prevents you from putting different language versions in separate packages of the same image
5:23:32
jackdaniel
in that case you'd be able to have (say) python2 and python3 funcitons interoperate
5:23:38
beach
There are, however, plenty of "programming systems" without any attempt at a detailed specification, and certainly no specification of what will remain unchanged in the future and what might change at arbitrary times in arbitrary ways.
5:23:45
Jachy
(Just ran into that last weekend, some code in hip new lang I wrote from 3 years ago didn't run. The language designers put random() into a module.)
5:24:23
Jachy
jackdaniel: by the same logic I can always run an old VM with the old language version, CL as a target not needed.
5:24:47
jackdaniel
Jachy: that's not the same logic, because you don't have two runtimes in the same image
5:25:20
aeth
CL isn't a suitable compilation target for everything that you'd want to have in a language.
5:25:48
jackdaniel
I don't think CL would make a good compilation target, just commenting on Jachy remark
5:27:37
beach
It would probably be a better idea to generate Cleavir ASTs directly from the source language.
5:28:12
beach
A few new ASTs could be introduced where needed, but the bulk of the translation chain would remain the same.
5:28:54
jackdaniel
aren't Cleavir ASTs a subject of the same "beneloved dictator" syndrome you've mentioned before?
5:29:03
beach
That way, you would automatically get source tracking in the source language, and you would not have to debug your code in terms of Common Lisp target code.
5:29:42
beach
jackdaniel: It is not a language, and I don't pretend it is. It is a compiler framework.
5:31:02
jackdaniel
uhm, then why is it better to compile to AST of a single compiler which is designed for another language than to compile to CL which has numerous implementations?
5:31:46
aeth
You could compile to CL by having a series of extensions that the major implementations accepted. beach is right that debugging would be painful, though.
5:32:16
aeth
Afaik there probably aren't *that* many things that couldn't be added as extensions, it's just that it's a niche no one has really catered to.
5:34:20
jackdaniel
I can't be right because I didn't make any statement, just asked a question out of curiosity
5:35:26
fiddlerwoaroof
Racket has done a lot of work to figure out tracking errors in macro expansion to the source the programmer wrote
5:35:46
jackdaniel
compiling to *some* compiler IR is a common thing (LLVM is a common target for instance)
5:40:13
fiddlerwoaroof
I've been writing a lot of Clojure/Scala/Java for $work and not having to explicitly decode/encode values in ffi is the best part of the JVM
5:40:43
aeth
fiddlerwoaroof: notice that JVM languages with the best interop are written specifically for the JVM, though
5:41:15
fiddlerwoaroof
aeth: there's no reason why clojure couldn't be a library + readtable for ABCL
5:42:26
aeth
symbol case sensitivity and a separate nil from false tend to be noticable interoperability issues with other languages and CL
5:43:01
aeth
CL macros would be pretty hard or impossible to interface with from a CLFFI, especially ones like symbol-macrolet
5:44:02
fiddlerwoaroof
I've been doing a lot of work embedding Apple's Objective-C runtime in CL and a couple well-chosen reader macros make dealing with a case-sensitive language pretty painless
5:45:04
fiddlerwoaroof
_using_ macros from other languages would be tricky, but this is true of most of the "advanced" features of JVM languages.
5:48:43
aeth
I've been thinking about Scheme<->CL and I think the best way to handle CL things defined in Scheme is to assume CL is being written case-insensitively with automatic upcasing and downcase it. So if you define a Scheme CONS from CL, turn it into |cons| because it was probably written as cons and then upcased into CONS.
5:49:40
aeth
Going the other way could be trickier. You could just upcase |foo| into FOO but the Scheme could be written with case-sensitivity in mind.
5:51:24
fiddlerwoaroof
https://bitbucket.org/cowan/r7rs-wg1-infra/src/312606b342ba83fd099cc5719ae71fc9ada1890a/RedEdition.md?fileviewer=file-view-default
5:55:17
Jachy
fiddlerwoaroof: If it's so simple for objectitve-c I'm curious why ABCL and then later JSS lib still use strings to identify java method names...
5:55:29
aeth
e.g. doesn't look like this is a SRFI https://bitbucket.org/cowan/r7rs-wg1-infra/src/312606b342ba83fd099cc5719ae71fc9ada1890a/WG1Ballot8.md?at=default&fileviewer=file-view-default
5:59:48
fiddlerwoaroof
Objective-c does have the advantage that it's designed to be embedded into another language
6:00:42
fiddlerwoaroof
https://github.com/fiddlerwoaroof/objc-lisp-bridge#type-directed-objective-c-extractors
6:01:04
aeth
I could probably do Scheme via a reader macro because once there's a reader you just plug the reader into the reader macro
6:01:20
fiddlerwoaroof
I'm planning to eventually get rid of having to specify the type of each argument
9:31:39
zigpaw
nicely looking and there are great suggestions in the hackernews thread, lots of links I have tried on the projects sub-page doesn't work unfortunately.
9:52:47
jmercouris
Ok, I just checked the irclog link instead of the CCL one, seems the CCL one is not up- to date
9:53:03
jmercouris
There was some user who said something along the lines of using generic functions in scheme or something
9:54:15
jmercouris
this is the log I was looking at: https://gist.github.com/jmercouris/e04f787e088f9f3a14923077bbecbad5
9:54:51
jmercouris
and it seems that it was some time ago, as that is the end of log available on http://ccl.clozure.com/irc-logs/lisp/ for 2018-10-12
9:56:06
jmercouris
It seems like the more likely explanation now, people don't tend to use the word generic that often :D
9:56:27
jmercouris
I happen to have a freind who overuses that word, so maybe I am seeing things where they are not
9:57:41
jmercouris
that is something I do wonder about, what is the purpose of defgenric when defmethod will implicitly make a defgeneric?
9:58:38
beach
There is also some default given to your &key, &rest, and &allow-other keys that might be preferable to give explicitly.
9:59:11
jmercouris
What do you mean by that last part "you get to give your preferred method combination"?
10:02:36
beach
Here: http://www.lispworks.com/documentation/HyperSpec/Body/07_ffd.htm is a list of the built-in method combinations, but you can also define your own.
10:02:38
jmercouris
so why might you want to use :method to define a method against a generic function instead of doing it in a separate form?
10:03:35
beach
If you methods are trivial, like (defgeneric consp (thing) (:method (object) nil) (:method ((object cons)) t))
10:05:58
beach
Here https://github.com/robert-strandh/Eclector/blob/master/code/reader/generic-functions.lisp are some examples.
10:07:11
jmercouris
And in that case, I might naturally ask the question, why not forgo the defgeneric altogether?
10:09:42
beach
Here: https://github.com/robert-strandh/SICL/blob/master/Code/Cleavir/Input-output/io.lisp you have an example of the APPEND method combination.
10:10:08
beach
jmercouris: Because you may want to allow for the client to override the methods, or to provide auxiliary methods.
10:10:56
beach
jmercouris: In the example, the client is T. Typically, client code will define its own CLIENT object, and then override the default method.
10:11:23
beach
Or, if they are happy with the default action, they just don't define an auxiliary method.
10:11:48
beach
jmercouris: This is the very basis of programming with generic functions, allowing client code to adapt the way the module works.
10:12:30
beach
jmercouris: I guess your experience with object-oriented programming is from a language that does not use generic functions.
10:13:39
beach
But they are probably all based on the same principles, which are different from those of CLOS.
10:14:37
jmercouris
mostly because I made too many assumptions about that snippet of code, I assumed it was internal
10:14:46
beach
In all the other languages you know, client code would make a subclass and override that way.
10:15:16
jmercouris
In this case they would just specialize on the appropriate set of classes, right?
10:15:22
beach
No, that was the very client interface of Eclector, allowing client code to customize its behavior.
10:15:37
jmercouris
so they just need to write some new defmethods with the appropriate lambda lists, and they can change the behavior
10:18:16
jmercouris
That's what I've gathered as well, and on some intellectual level, I understand some of the details, and how it works, but I haven't really internalized it, and my thinking is still shaped for a traditional model
10:18:40
jmercouris
many years of java training has done me in, but I'm slowly changing my ideas about programming, I understand the process of "de-doctrination" takes time
10:19:24
jmercouris
I know for sure other parts of my mind have changed with regards to how I think about programming as a result of lisp, but I just haven't gotten deep enough into CLOS yet, to get that same effect
10:24:02
Jach[m]
jmercouris: I've only recently cracked open "Object Oriented Programming: The CLOS Perspective" and finding it helpful (plus the hardcover has nice cover art...)
10:24:48
jmercouris
Jach[m]: I'm in the middle of gentle introduction to common lisp, maybe when I'm through with that I can take a look, thanks for the suggestion