freenode/#lisp - IRC Chatlog
Search
12:43:21
xificurC
anyone knows an equivalent of `dirname $0`? I.e. finding the directory of the lisp file that is being loaded
14:15:44
klm2is
When I define a method in allegro cl with (defmethod foo ((x string)) (declare (ignore x)) (values)), I get a compiler warning for the variable x being used although it was declared ignored. Is this true of other implementations? Should it work this way?
14:17:08
Bike
"The expansion of the defmethod macro ``refers to'' each specialized parameter (see the description of ignore within the description of declare)." says clhs defmethod
14:17:10
klm2is
Makes sense. I was trying out cl-mustache and noticed that it has code like this in some places. I didn't know if that was an implementation thing.
14:19:14
klm2is
@Bike I read that, but I didn't know whether it's then required for the implementation to provide a warning.
14:21:06
Bike
it's not required to, but it's certainly allowed to, which is what you're concerned with, no?
18:13:25
pjb`
creating git repository should always be the first thing to do in a project (well just after ordering the t-shirts).
20:00:01
araly
hey everyone, I have a question, if I have a function like (parse-integer) which returns two values, the number parsed and the size of the string understood, how can I use both ?
20:29:24
aeth
That's not actually an exhaustive list. There's also (setf (values ...) ...) which is probably built on multiple-value-setq
20:37:44
aeth
If I used nth-value I'd probably wrap it in a trivial function just to make it more readable.
20:38:16
aeth
I bind all of the values and then discard the one(s) I don't use. Ideally, the compiler will optimize it to be the same as nth-value
20:39:00
araly
so where would I put my function that returns two values, at the place of "whatever" ?
20:40:22
aeth
It depends on what you're going for, though. If it's common enough just defining a trivial function is probably the way to go. e.g. (defun hash-table-value-exists-p (key hash-table) (nth-value 1 (gethash key hash-table)))
20:41:56
aeth
But imo you should either do a function wrapping nth-value or a multiple-value-bind that ignores the values you don't need because either will be more self-documenting than just using nth-value.
20:44:25
araly
well for this time I'm just using the second value of a function once, but I will turn it into a function if it turns out I use it again after
20:45:51
aeth
For very trivial functions that are small and probably will never change, you can declare them inline above the function definition, e.g.: (declaim (inline hash-table-value-exists-p))\n(defun hash-table-value-exists-p (key hash-table)\n...
20:46:11
aeth
So there's basically no reason not to use trivial functions when it makes the code better. It's very idiomatic.
21:04:21
stylewarning
Has anybody worked on or thought about being able to write small snippets of inline C code in Lisp?
21:11:13
MichaelRaskin
Cmera (or how is it even written) would even allow you to generate C from Lispy syntax
21:19:14
aeth
I generate a limited subset of GLSL from s-expressions. Nothing really stops me from finishing GLSL and then also adding what syntax C has on top of that.
21:20:53
aeth
The strings can even be made at compile time from the expressions. It would greatly complicate your build process, though.
21:23:36
aeth
It wouldn't be truly "inline" because the C compiler wouldn't be cooperating, unless you built the C compiler yourself, which is totally doable non-portably in SBCL.
21:24:22
stylewarning
I mean, sometimes it's annoying to write Lisp code that looks identical to C, except it's 10x more verbose and still less performant.
21:24:45
stylewarning
Maybe it would be nice to just compile a C function to some anonymous library and dynamically load it or something, I don't know.
21:25:09
aeth
Are the internals exposed by SBCL (e.g. define-vop) sufficient to write a C compiler with?
21:26:31
aeth
That would be an interesting alternative to relying on foreign C, although it wouldn't be portable.
21:28:25
aeth
I don't really have issues with verbose low-level CL, though. The thing that's the most verbose compared to C-style-syntax is probably aref, but I even have a with-accessors equivalent for that now in with-2D-array-accessors. https://gitlab.com/zombie-raptor/zombie-raptor/blob/184e235be3974ebc3b062b3fb94559c2e15797f9/util/array.lisp#L106-144
21:28:59
aeth
The result is something that's more verbose than using aref directly, but probably still more readable.
21:29:30
aeth
e.g. https://gitlab.com/zombie-raptor/zombie-raptor/blob/184e235be3974ebc3b062b3fb94559c2e15797f9/render/gl.lisp#L180-197
21:30:47
stylewarning
aeth: maybe because you don't read enough bitwise arithmetic and prefer things spelled out because a DSL doesn't make sense for you
21:31:47
aeth
stylewarning: well e.g. I prefer something like this for a common use case of bit operations: https://gitlab.com/zombie-raptor/zombie-raptor/blob/184e235be3974ebc3b062b3fb94559c2e15797f9/math/boolean-set.lisp
21:42:25
stylewarning
the fact of the matter is that C has a good DSL for many kinds of bitwise operations, and you can trust a C compiler to produce good code for those
21:42:41
stylewarning
this is also not to say that you can't write such in Lisp, which was what I was originally suggesting
21:43:21
stylewarning
pjb`: lisp is more mathematical, and hides the machine representation of data pretty well.
21:43:38
stylewarning
pjb`: C is consequently not very mathematical, and lets you interpret bits however you'd like
21:44:14
stylewarning
anyway, this is non-interesting, because it's a usual rehash of what everybody already knows
21:45:22
aeth
pjb`: There would be advantages to writing either C strings or s-expressions that trivially map to C-strings directly in CL source, which was the original point.
21:45:50
aeth
("C strings" as in strings of C, not the hideous representation of strings that C has.)
21:48:13
aeth
pjb`: I wonder if it would be better to back the C memory in an emulated C by CFFI's C array representation or by static-vectors rather than CL arrays. Then you get interoperability with C libraries, too.
21:49:15
aeth
static-vectors would work best, then, because you could trivally substitute normal CL arrays instead of using static-vectors, but share most of the code.
21:50:08
pjb`
My take is to shift the C environment into the lisp environment (and therefore uplift it to the same safety level as lisp).
21:50:27
pjb`
So you wouldn't do FFI, you would just compile the foreign C library with my future compiler and obtain lisp object code.
21:51:03
pjb`
aeth: what is C interoperability? As long as you have the C sources (which is the case most of the time), you could just recompile them in lisp.
21:52:17
aeth
One example is 3D graphics APIs as well as input/window/sound/etc. A lot of graphical CL apps use cl-opengl with cl-sdl2 for this reason, although in theory you could probably write directly to the OS APIs and bypass the need for something like SDL2 as a dependency.
21:53:10
aeth
A graphics toolkit ported to cl-opengl or (in the future) cl-vulkan could, if you don't care about not feeling native (and only macOS users seem to care about that), bypass most, but not all C.
21:54:13
stylewarning
pjb`: out of curiosity, have you written much code that has to process terabytes of numerical data in Lisp?
21:54:16
aeth
Alternatively, a future revision to the CL standard could include all of these OS APIs into the standard itself. Then the implementors would deal with it and anything written in CL itself would technically be pure CL without touching C APIs.
21:55:14
aeth
(Some things that require OS C APIs probably could be moved into the language, though.)
21:56:18
aeth
pjb`: In the near future you could compile, via a written-in-Lisp compiler, a Lisp-like language to SPIR-V and send that to the GPU. You'd still have to deal with the OpenCL/OpenGL/Vulkan/whatever API, though.
21:59:44
aeth
For the forseeable future, though, you'll want: access to some POSIX things not in the CL standard, access to the GPU, windowing/input, sound, and a few other things.
22:00:20
aeth
And if you want portability, on Windows you can't use the syscalls and expect them not to break. You'd have to use CFFI there.
22:00:30
pjb`
aeth: the only argument is proprietary binary libraries. The key word above was SOURCE.