freenode/#lisp - IRC Chatlog
Search
20:29:08
pjb
(let ((direct (list 1 2 3))) (let ((rev (reverse direct))) (list direct rev))) #| --> ((1 2 3) (3 2 1)) |#
20:32:51
pjb
vtomole: not more efficient. If you use them when you should not, you will spend more time debugging your code than you will be able to recover ever in processing time.
20:38:00
pjb
vtomole: basically, the only safe circumstances, is when you're mutating a list that you've just constructed, so you're sure there's no other references to these cons cells. If you use it on function parameters, expect pain.
21:05:28
Kundry_Wag
Hey, this question uses Clojure but I'm posting it here since it's actually applicable to any Lisp
21:05:34
Kundry_Wag
I have a question about simulating certain aspects of a type system. There's a Clojure library called Schema that can (among other things) check the inputs of functions. For example, using Schema, one could define a Foo model - basically, a map that has some mandatory keys such as Bar and Baz. So if you define a function to have Foo as input, as in
21:05:50
Kundry_Wag
then when a-function is called, it'll check if the input matches the declared type.
21:05:51
Kundry_Wag
The thing is that if you get `obj` and, say, add other key and value to it with `assoc`, Schema won't complain, as it just checks `a-function` input:
21:05:58
Kundry_Wag
That's because Schema can't just guess that the thing we are adding a key/value must remain a Foo (if that's our goal).
21:06:00
Kundry_Wag
My question is: is that assumption true? Is technically possible to create a library that if a modified obj is always a Foo inside the function? Perhaps using some magic macrology?
21:14:26
Bike
(defn a-function [obj :- models/Foo] ...) means it takes one argument called obj, which is a Foo?
21:14:42
Bike
you'd have to do some pretty fancy stuff, yeah, to essentially use a different function also named 'assoc'
21:15:45
Bike
given that you could use a nonconstant key, something would have to be prepared to check validity at runtime.
21:17:52
Kundry_Wag
Bike: From the Clojure docs: `When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the mapping of key(s) to val(s).`. So if a-map is {:key1 :value1}, then (assoc a-map :other-key :other-value) would result in {:key1 :value1 :other-key :other-value}
21:20:24
Kundry_Wag
Bike: Oh, I see. If I understand correctly, the function definition (defn) could be a macro that would replace the built-in `assoc` to a different version of it
21:21:38
Bike
relatedly, given that clojure is actually making a new map, the assoc call isn't actually violating the restriction
21:23:44
Bike
you'd want to define a-function's return type, or use something like lisp's THE to type the value
21:30:24
Kundry_Wag
Bike: That's covered by Schema (in Clojure). I didn't know CL had a built-in way to do that, though
21:33:35
Bike
and to be quite honest, rather than having 'alist but restricted to using these keys', i'd probably rather have a class
21:35:03
Bike
type stuff gets much easier if you restrict the possible restrictions to be easy stuff like that
21:42:20
Kundry_Wag
Bike: Sure. But it think that would be possible in CL because it can mutate the object from the class. Not sure how that would work in Clojure, where you usually apply a pure function and get a new obj, as you noted
21:44:52
Kundry_Wag
It has records, which are somewhat analogous to classes: https://clojure.org/reference/datatypes#_deftype_and_defrecord
23:28:43
comborico1611
I'm trying to find the connection to the word apropos, and its namesake function. Any ideas?
1:35:58
karlosz
well, it looks like this particular issue was fixed in the latest commit to quicklisp
1:50:09
clintm
Is clisp the one that gets updated by loading new code into a previous revs image? I remember reading about a CL that did that as opposed to building a new image like sbcl.
1:51:29
Zhivago
I wouldn't recommend it these days. Image building is pretty much something that was useful until dynamic linkage became available.
1:52:12
theemacsshibe[m]
image making is nice tbh, i use it to distribute lisp programs to non-lisp users
1:53:06
Plazma
while not the same, smalltalk also uses images (that are pretty easy to build/strip down) which is a cool concept I think still, even if it's a bit dated
1:54:12
theemacsshibe[m]
it's possible to mess (especially with -g) with but not as good as having sources
2:09:39
karlosz
its whole existence was ttying to move away from the CMUCL style build to the reproducible build we all know and love
3:04:14
loke
Bike: Oh it does? I tried it a few moenths ago, and back then Drmeister said it was planned but not working yet.
4:24:13
aeth
Does anyone else use a macro as the way to access things to avoid potentially dozens of exports in a package? What I've been doing is a with-foo-accessors that places the accessor symbols in the package specified at the definition of that macro and also can add a prefix (for the case of structs with conc-name not set to nil).
4:25:03
aeth
I find that this greatly simplifies things because then I only need to export the with-foo-accessors macro and/or a macro that indirectly uses that macro.
4:26:59
aeth
e.g. (with-foo-accessors ((foo foo)) foobar ...) would macroexpand to (with-accessors ((foo the-package-containing-foobar::foobar-foo)) foobar ...) in the most complicated case (where it's a struct with prefixed accessors)
4:44:08
aeth
My macro, in case anyone's curious: https://gitlab.com/zombie-raptor/zombie-raptor/blob/ec47910d88254d0c6a0e8c0a33aa33c7d4037513/util/util.lisp#L247-260
4:44:36
aeth
destructuring-lambda is just a lambda that does a destructuring bind on its one argument. It's surprisingly common. In fact, I just now noticed the pattern in define-accessor-macro
5:09:42
aeth
loke: Otherwise the macro will produce something whose API is (zombie-raptor/util/util::foo)
5:33:15
aeth
loke: I use #.(symbol-name ...) pretty much everywhere instead of hardcoding the symbol as a string of upper case characters
5:38:49
aeth
I know it's essentially pointless, but at least to me it feels better to not hardcode the assumption about the reader that will almost certainly be valid. Perhaps this could be turned into something more concise?
5:42:31
aeth
But... I suppose I should be using &environment env instead of assuming intern without that argument would work correctly
8:00:01
scymtym
shka: glad you like it. but i have to learn more CLIM or get somebody to help out to make it less horrible to use