libera/#commonlisp - IRC Chatlog
Search
2:02:12
shunter
Quick question on WITH-XYZ macros that bind VAR -- is it recommended to declare that VAR has dynamic extent? VAR shouldn't be used outside the body anyways, so I think it fits with what dynamic extent is supposed to be, right?
2:03:07
shunter
It shouldn't, because the meaningful resource is closed by the time execution leaves the body
2:04:47
shunter
Very much like a with-open-stream: `(let ((,var (wl-display-connect ,@args)) (unwind-protect (progn ,@body) (wl-display-close ,var)))
2:05:55
Bike
if the value is actually inaccessible than using dx is fine. unless wl-display-connect inlines to something special, i doubt the declaration will really do anything, though.
2:52:00
Bike
it'll make your code very confusing, as it will mean calling a function alters the global definition of some other function.
3:03:47
dbotton
First in clog lingo - When you instantiate an instance of a clog panel there is an on-setup handler, so in that handler I want to sometimes define a function. - so in CL lingo - this is a function say create-panel generated by the builder that includes code by the user to run each time create-panel is used. So wanted to understand potential pitfalls if they add a defun
3:05:15
dbotton
As I can say have a canvas, draw a circle when created, then reuses the same code in say the on-click
3:05:48
Bike
well having code that messes with the global environment is messy for the same reason messing with the global environment usually is.
3:10:38
Bike
rationale what, in the standard? defun is just a normal form, so there's no reason to disallow it anywhere, and no specific rationale for allowing it anywhere
3:33:42
emacs-dwim
nij-: Of course, CL has: *evalhook* *applyhook* *macroexpandhook* #'evalhook #'applyhook.
3:40:37
dbotton
Bike, this seems interesting as a result - (defmethod draw ((obj (eql panel)) circle-color) nil) if I want a more JavaScript style of OO to place the defmethods in the create function.
6:03:06
hayley
I heard *eval-hook* was removed as it did nothing in compiled code, making it rather awkward.
8:31:49
pve
Hi, if I nreverse a vector with a fill pointer, will the result also have a fill pointer?
8:37:20
phoe
sbcl, ccl, ecl, abcl, clisp, lw, acl all pass (let ((v (make-array 5 :initial-contents '(1 2 3 4 5) :fill-pointer 3))) (assert (eq v (nreverse v))))
8:38:41
phoe
so, yes, all implementations mutate the vector in-place rather than constructing a new one
8:39:52
phoe
pve: if the returned vector is EQ to the original one, this means that it has a fill pointer, and by common practice you can depend on this
8:53:27
jackdaniel
truth to be told implementing reverse usually involves (nreverse (copy-sequence seq)) unless you are a masochist
9:19:17
phoe
Shinmera: nope, I am too lazy to do this, I just type the following in my repl: sbcl ccl ecl cmucl abcl clisp acl
9:19:52
Shinmera
phoe: you might want to do it though, it's quite convenient for exactly that https://github.com/shinmera/cl-all
9:20:48
phoe
Shinmera: yes, I am aware; I just can't do it at the moment since my will and strength are going elsewhere
11:11:48
pjb
pve: "whereas nreverse might modify and return the given sequence." "For nreverse, if sequence is a vector, the result is a vector that has the same actual array element type as sequence." "For nreverse, sequence might be destroyed and re-used to produce the result. The result might or might not be identical to sequence." " When sequence is a vector, nreverse is permitted to re-order the elements of sequence in order to produce the
11:13:09
pjb
pve: you can do: (let ((r (nreverse v))) (unless (eql r v) (replace v r))) to reverse the fill-pointed vector in-place.
11:15:20
pjb
shunter: a typical case, is (with-input-from-string (*standard-input* "foo") (read)) or (with-output-to-string (*standard-output*) (print 'hi))
11:15:59
pjb
shunter: the macro should let the user declare the variable special if wanted, but by default, it should be lexical binding.
12:38:43
_death
although NREVERSE entry hints at what it's permitted to do to a vector, I'm not sure it's ok to assume that you can pass it (after destruction) to REPLACE as a target, if NREVERSE did not return it.. in any case seems bad style
13:00:45
Nilby
I'm pretty sure one can make an extensible sequence in sbcl which would violate the assumption that nreverse returns the original.
13:33:02
_death
good, you took the bait :)... we can start with make-array's :initial-contents parameter... it can't take multidimensional arrays
13:35:22
_death
second, (coerce (make-array '(3 3) :element-type 'single-float :initial-element 1.0) '(simple-array t (3 3))) fails though the single dimension case is ok
13:35:23
Nilby
:initial-contents is perplexing. I feel like what's the point if you have to make it be a list?
13:37:21
_death
third, there's no standard readable printed representation for specialized arrays (other than strings and bit-vectors).. so if you print them readably, an implementation can signal an error or use nonportable syntax (like sbcl).. so if you wish to print some piece of code readably, you need to be aware of this pitfall and act accordingly
13:39:15
Nilby
I agree coerce could be a lot more coercive in many cases. One might wish it was generic.
13:41:41
Nilby
I've too gotten bitten array (non-)readability. I sometimes feel like arrays should have more subclasses and the simple ones should always work, for things like coercion and readability.
13:44:43
Nilby
displaced arrays are sometimes troubling, but I still like them. I feel like for things that could prove it okay, a displaced-subseq could make a lot of things quicker.
13:45:45
_death
in code that cares about performance, though, I often need simple arrays and displaced arrays become much less useful
13:46:31
emacs-dwim
_death: sbcl's printed arrays are portable readable though, just not portably printable?
13:47:35
phoe
emacs-dwim: (let ((v (make-array 5 :initial-contents '(1 2 3 4 5) :fill-pointer 3)) (*print-readably* t)) (prin1-to-string v)) ;=> "#(1 2 3)"
13:47:51
_death
emacs-dwim: no.. it looks like #A((3) SINGLE-FLOAT 1.0 1.0 1.0) which is not standard syntax