freenode/lisp - IRC Chatlog
Search
9:24:38
no-defun-allowed
paule32: in common lisp, + at the start of an expression and + in the rest are not equivalent
9:25:36
no-defun-allowed
(+ ...) refers to the function +, whereas (... + ...) refers to the variable + which is defined by your REPL
9:27:21
Shinmera
please stop trying to help him, it is not productive. It's been close to two years of this guy getting advice in this channel and not heeding any of it
10:16:02
russellw
If I understand http://www.lispworks.com/documentation/lw50/CLHS/Body/02_dfa.htm correctly, 'x is equivalent to (quote x) but `x is /not/ equivalent to (backquote x) ?
10:17:55
russellw
sb-int:quasiquote ... guessing that means sbcl-internal, so the representation is purely an implementation detail?
10:19:18
Shinmera
The representation could be handled by a struct or anything, as long as the readably printed variant uses the standard backquote notation
10:33:49
White_Flame
the lack of specification also is a problem if you're walking through code in a macro
10:34:27
White_Flame
there's a fare-quasiquote package which overrides the backquote & comma and ensures it's nice nested sexpr lists for easier traversal
10:59:11
White_Flame
same thing if it's ,(foo bar) or whatever. you'd have to dig into the COMMA object
11:00:40
|3b|
it used to be, but there were too many edge cases when printing them nicely or something like that, so switched to structs
11:01:15
|3b|
(and if you don't care about printing them nicely, just expand to QUOTE, LIST, APPEND, etc
11:05:55
makomo
this post describes the pretty printing issue http://christophe.rhodes.io/notes/blog/posts/2014/backquote_and_pretty_printing/
11:16:08
jackdaniel
when I create a broadcast-stream with s1 and s2: (make-broadcast-stream s1 s2) and call file-position on it, file position of s2 should be returned, right?
11:16:31
jackdaniel
excerpt from the standard: " The functions file-length, file-position, file-string-length, and stream-external-format return the value from the last component stream."
11:23:01
jackdaniel
(a bit of context: ecl takes first component, so queried for a second opinion that it is wrong)
12:28:29
phoe
What is test-op supposed to do when a test failure happens in modern ASDF and Quicklisp configurations?
12:28:49
phoe
For example, when Quicklisp builds its systems each month, what should be done to make it know that there was a test failure?
12:54:38
oni-on-ion
does CLHS say something like "would be good idea for implementation [to implement] for debug/trace purpose"
15:24:58
_death
Demosthenex: yesterday I worked a bit on editor windows like you can see in the second demo.. still there's much more to do there. I think the next step is to add mouse support and moving/resizing windows
15:30:41
_death
I'm thinking a small demo application would indeed be something like a "turbo lisp".. with a repl and a file editor
15:41:01
Demosthenex
_death: all my usecase is about data entry forms.... i'm tinkering with trying to make some editing widgets
15:47:35
Demosthenex
_death: not laying the burden on you, i'm trying to see what i can come up with. i already got my async inputs and such going
16:07:01
phoe
I have a SBCL thread that just hangs with 100% CPU usage. Its backtrace shows pretty much nothing, https://plaster.tymoon.eu/view/929#929 - how can I debug it?
16:07:28
phoe
I want to figure out where exactly it is and what it's doing, but a lack of a backtrace makes it pretty hard for me.
16:43:02
Demosthenex
hrm, i found justification in format, but not how to replace the default padding char while using center ie: (format nil "~70:@<~A~>" "Whee"), but what if i wanted .'s instead of spaces?
17:30:50
makomo
for example, the same problem shows up in C++. you can either use iostreams and its text formatters, or you can use printf
17:31:41
makomo
it's much easier to localize a printf/format-like "template", rather than individual parts of something like the article's OUT
17:37:48
_death
makomo: with Lisp you can store forms.. also, format control strings don't solve the localization problem.. but personally I don't care for localization so..
17:41:33
_death
makomo: in fact with an OUT like construct you can provide more hints that can help with localization.. since you construct a language for writing things
17:42:26
_death
instead of being limited to the low level format control language that perhaps lets you do something like ~/
17:42:27
Demosthenex
https://bpaste.net/show/e9cd7a55a1e5 window and title in the first call to locked-write-string-at-point aren't found
18:07:00
_death
just to show an example of OUT hackery https://gist.github.com/death/4e273d14e671a3c64f3be10cab2aa1b2
18:17:35
pjb
_death: makomo: it's with the format specifier ~*, which allows you to use the arguments by index, instead of by order, so you can easily use format string in different languages, without changing the program and the order of the arguments. In different languages, the order for formating of various data elements into the language often changes.
18:18:30
_death
instead of comparing to lesser languages, why not compare to a lispy language for solving the localization problem
18:19:44
pjb
(format t (get-localized 'qualified-object-format-string) object color size qualifier) -> "La petite balle bleu" "The small blue ball"
18:22:31
pjb
It is funny, because one of the most advanced localization system, ie. NeXTstep/Openstep/Cocoa's one, isn't even able to do that!
18:25:52
_death
now instead come up with a lispy grammar for describing it.. (:object ball :definite t :adjectives (small blue))
18:30:19
makomo
_death: well, true, it doesn't solve it by itself, but it's much easier for a translator (the actual person doing the translations) to get context about what's being translated
18:32:29
makomo
_death: well, that horror from the article sure doesn't. but consider something like "there are ~a objects in the bag" or something
18:34:24
_death
no, that's the point.. the "use format strings for localization purposes" is just an opportunistic hack.. in lesser languages, it's easy to externalize strings, so they get used and a translator has to work with that
18:35:19
_death
so if you actually want to solve the problem, you find that you need more context and structure
18:44:04
TMA
there is more to localization than simple exchange of strings. -- consider that you need to adjust sizes (an "OK" can be much smaller than "Budiz"); there are other directions for text than ltr-ttb; you might want to adjust colors (because of the connotations) images and icons, ...
18:45:34
russellw
Is there a way to get CCL to exit when a script is finished? wx86cl -Q -b -l test.lisp doesn't do it
18:48:01
Demosthenex
i saw ~?, but was there a way use a variable in the same format string to dynamically change padding?
18:48:46
pjb
_death: of course, you would write(format t (_ "format ~A etc" "The message printed when so and so") …) and (format nil (_ "format ~A etc" "The label of the button to do this and that") …)
18:51:25
Shinmera
"In place of a prefix parameter to a directive, V (or v) can be used. In this case, format takes an argument from args as a parameter to the directive. The argument should be an integer or character. If the arg used by a V parameter is nil, the effect is as if the parameter had been omitted. # can be used in place of a prefix parameter; it represents the number of args remaining to be processed. When used
18:51:27
Shinmera
within a recursive format, in the context of ~? or ~{, the # prefix parameter represents the number of format arguments remaining within the recursive call."
18:52:21
pjb
you can provide or let the translator provide a set of functions to do the exact formating required in strange languages.
18:54:00
_death
pjb: like I said, the format control language is low level and barely extensible via ~/ ~? etc.
18:54:30
pjb
makomo: in CL, we'd write: (loop for i below 3 collect (format nil "There are ~a object~:*~P in the bag." i)) #| --> ("There are 0 objects in the bag." "There are 1 object in the bag." "There are 2 objects in the bag.") |#
18:55:40
_death
pjb: instead you can use the full power of lisp to make things easier to the (since "localization is more than translation" argument was made) localization mechanical turk
18:57:25
Blackbeard
ACTION sent a long message: < https://matrix.org/_matrix/media/v1/download/matrix.org/stZqJlsPlMtsLEZdQxkSDazj >
18:58:18
Blackbeard
is there a way that I can pass just a list '(".jpg" ".png" ".svg") and will apply search to f with every element of the list
19:04:14
pjb
_death: right. :-) (loop for i below 3 collect (format nil "There ~[are~;is~;are~] ~:*~a object~:*~P in the bag." i)) #| --> ("There are 0 objects in the bag." "There is 1 object in the bag." "There are 2 objects in the bag.") |#
19:05:07
_death
pjb: so now you have this "~[are~;is~;are~]" inline.. but it's a useful thing to have named
19:06:03
_death
pjb: and it really shouldn't, since stuffing everything into a string makes things cryptic
19:06:14
pjb
(loop for i below 3 collect (format nil "There ~/english-verb-conjugate/ ~0@*~a object~:*~P in the bag." i "to be"))
19:13:21
TMA
you do not want to rely on format's English support too heavily for localization. ~P works ok-ish for English but not for other languages
19:14:48
_death
it's true that error/etc. are burdened with format.. there's even simple-condition with :format-control and :format-arguments.. I use format here and there and when I don't want to depend on constantia.. but when things get too cryptic, I'll either use OUT or just Lisp with simple primitives
19:19:02
pjb
(loop for i below 3 collect (format nil "You have ~D cop~:*~@P of Emacs ~:(P running~)" i)) #| --> ("You have 0 copies of Emacs P Running" "You have 1 copy of Emacs P Running" "You have 2 copies of Emacs P Running") |#
19:22:56
russellw
I'm about to write a function to return the last element of an array. Obviously this is a very simple function, sufficiently so that it probably already has a common name. The most obvious name is array-last; is that's what it's usually known as?
19:23:57
pjb
russellw: how do you define the last element of #3A((((1 2 3) (4 5 6)) ((1 2 3) (0 0 0))) (((1 2 3) (4 5 6)) ((1 2 3) (0 13 42)))) ?
19:25:26
pjb
russellw: the problem is not that array, it's that you don't know how to define the last element of that array!
19:26:16
pjb
(defun last-element-of-array (a) (row-major-aref a (1- (reduce (function *) (array-dimensions a))))) (last-element-of-array #3A((((1 2 3) (4 5 6)) ((1 2 3) (0 0 0))) (((1 2 3) (4 5 6)) ((1 2 3) (0 13 42))))) #| --> (0 13 42) |#
19:26:40
pjb
russellw: that's beside the point. The point is that you asked for the last element of an array, not the last element of a vector or of a sequence.
19:27:08
pjb
russellw: my point is that if you are able to state clearly your requirements, then the code will generally follow easily.
19:28:00
pjb
russellw: alternatively, you could start speaking in lisp. and ask, How do I (defun last-element (x) (aref x (1- (length x))))? Oops, I answered in the question…
19:28:19
Shinmera
pjb: array-total-size would be a bit shorter and idiomatic than reducing array-dimensions.
19:28:41
pjb
russellw: sometimes, you don't know what english name to give to a function. Just start writting it: (defun foo (…) …) and once it's written you can usually find easily what to call it in english.
19:29:15
pjb
Also, for vectors, you can use length or (array-dimension v 0): you won't get the same result on vectors with fill-pointers.
19:29:29
russellw
pjb, er, if we are going to get snarky about exact wording, take a look at the question I asked, in which I observed that I have no difficulty writing the function; that part is very simple. I merely wanted to know whether it already had a common name. The answer to which was yes, thank you
19:30:30
pjb
russellw: I didn't want to get snarky. In this case, I would have said that obviously, a function to return the last element of an array should be named last-element-of-array.
19:30:56
pjb
Blackbeard: don't mix is- with -p. They're two different conventions for the same thing.
19:31:09
russellw
pjb, ah! Okay, while that's a little verbose for my tastes, it is a perfectly fair answer
19:31:43
pjb
russellw: you can stylistically choose: array-last-element. Or vector-last-element. Or just last-element, notably if that applies to sequences.
19:31:59
pjb
russellw: or you can write it as a generic function and have implementations for all kinds of collections.
19:32:53
russellw
(defun last-elt (s) (elt s (1- (length s)))); one of the things I like about dynamic languages is you get some degree of genericity for free
19:33:22
pjb
Blackbeard: member is nice. I often prefer to use FIND or even POSITION (for the side effect of computing the position if needed).
19:33:51
pjb
Blackbeard: member returns a tail of the searched list, so it may be ugly when printed (but otherwise, perfectly ok for the program).
19:34:35
pjb
Blackbeard: FIND has the advantage of returning the element in the list, as a prototypal form. This can be useful, if you want to normalize them.
19:35:56
pjb
Blackbeard: also, testing for the file type is a bad idea. You could check the meta data (prefixp "image/" (Content-Type file)). Or check the contents. (But this may require more I/O and computation).
19:36:48
pjb
In any cases, be prepared to have non image file names .jpg or something else, and to have png files named .jpg and vice versa.
19:38:34
aeth
russellw: You are probably going to have to inline it to get good performance with it, though. (1) trivial, (2) no reason to redefine it, (3) works on arrays or numbers (here, arrays). So it's a good candidate for inlining.
19:42:52
aeth
_death: Yes, if you wanted it to work on lists instead of 1D arrays (vectors) specifically, the ELT variant is bad. You would probably want an ETYPECASE to split it into two cases, one for lists and one for vectors. The compiler will probably optimize it out if it's inline
19:43:22
russellw
Right, in this case performance is not an issue, but will keep those considerations in mind if it becomes so
19:43:26
aeth
The important thing is that anything that's just a one liner with something like AREF (works on all arrays) or ELT (works on all sequences) or + (works on all numbers) can become a lot more efficient when inline.
19:44:38
_death
aeth: to keep it generic, you can just have (if (listp ...) (car (last ...)) (elt ...)) remember that type sequence is not necessarily type (or list vector)
19:45:52
pjb
That's because in (elt x (1- (length x))), we have to walks of a list. But only 2 O(1) accesses for vectors.
19:48:28
aeth
_death: I'd do it like this: (defun last-elt* (sequence) (etypecase sequence (list (car (last sequence))) (sequence (elt sequence (1- (length sequence))))))
19:49:26
fiddlerwoaroof
Blackbeard: That's a good way to start: assume that everything in the directory is an image and let the user pick one of them then, once you get that working, worry about filtering out non images.
19:50:51
aeth
_death: Numbers also have an efficient inline form that the compiler will generate (probably... obviously stuff like JSCL behave differently) if it has more type information
19:52:17
aeth
_death: e.g. (defun foo () (last-elt* (vector 1 2 3))) is about half the size in disassemble as last-elt* is if you inline last-elt*
19:53:39
aeth
And (defun bar () (last-elt* '(1 2 3))) and (defun baz () (last-elt* #(1 2 3))) are compiled to constantly return 3 in SBCL
19:57:52
fiddlerwoaroof
that would work, you might try this: https://github.com/Shinmera/trivial-mimes
20:35:16
russellw
I want to search a string for the position of the first character that is not a digit. Which function should I be looking at?