freenode/#lisp - IRC Chatlog
Search
4:59:32
aeth
earl-ducaine: If you put more than 5 functions in an flet, you probably want to start referring to other functions within that same scope, which labels permits and flet does not
5:02:00
jack_rabbit
If you are doing that, is that not usually a use-case for a separate file for organization rather than flet-ing?
5:04:52
pjb
Depends. The point of flet and labels is that you actually write closures, not mere functions.
5:07:02
aeth
jack_rabbit: Consider repeated calls to a function with a lot of arguments, where a lot of the calls have arguments in common. Creating closures with flet/labels is one way to simplify this code.
5:12:58
aeth
And in this case, labels is better than flet as soon as you have enough to see an even larger pattern.
5:47:28
jack_rabbit
What about passing a data structure around to capture the state rather than relying on closures or passing a bunch of individual values?
6:02:26
aeth
Common Lisp is definitely a language where there's a dozen roughly equivalent ways to do anything
6:14:47
aeth
In this case, I'm drawing shapes, and I decided in the shape API to go with lots of arguments rather than having lots of temporary point objects.
6:15:56
aeth
I probably went overboard and have too *few* objects in the current API, though, so it's a bit messy. I got rid of some of that by using matrices in places.
7:11:55
fiddlerwoaroof
Is there a generic way to get a value for CONCATENATE's first argument that matches the type of the first of the sequences you're concatenating?
7:14:14
fiddlerwoaroof
No, the issue is that the type it gives is too specialized: it includes the length of seq1
7:15:19
fiddlerwoaroof
in the case of vectors, it would have to be (vector (+ (length seq1) (length seq2)...))
7:16:47
aeth
Looks like the perfect use for this library: https://github.com/markcox80/specialization-store/
7:20:53
aeth
(defspecialization foo ((v1 simple-vector) (v2 simple-vector)) (concatenate 'simple-vector v1 v2))
7:21:12
aeth
Well, you probably want that inlined because it's trivial and unchanging and the inline will probably be more efficient.
7:21:32
fiddlerwoaroof
speed doesn't matter too much, and there's a reasonable mapping from class -> result-type
7:21:57
aeth
fiddlerwoaroof: but CLOS generics do not dispatch on types and the classes aren't (afaik) portable, so that's not useful for numbers or sequences, hence specialization-store
7:22:33
aeth
Actually, just noticed, in my foo example, you could probably macroify it to generate all the functions
7:23:04
fiddlerwoaroof
e.g. LIST is a class: http://www.lispworks.com/documentation/HyperSpec/Body/t_list.htm#list
7:23:25
fiddlerwoaroof
As is VECTOR: http://www.lispworks.com/documentation/HyperSpec/Body/t_seq.htm#sequence
7:24:26
aeth
If they have to match in type (but you'd have to generate a name instead of foo): `(defspecialization (foo :inline t) ((sequence-1 ,sequence-type) (sequence-2 ,sequence-type)) (concatenate ,sequence-type sequence-1 sequence-2)))
7:24:43
fiddlerwoaroof
But, it makes more sense to me, just to have a simple function that goes from thing -> symbol
7:26:31
aeth
like (simple-vector 3) -> (simple-vector *) and (simple-array single-float (3)) -> (simple-array single-float (*))
7:27:34
fiddlerwoaroof
Yeah, on sbcl there is the added wrinkle that it's possible for something besides LIST and VECTOR to extend SEQUENCE
7:28:43
aeth
lazy sequences, immutable sequences, very niche sequences like perhaps ordered hash tables or whatever.
7:38:15
aeth
I think for 1D simple-arrays it's always going to be either the cadr (simple-vector) or the caaddr (everything else) so that's just three cases: list, simple-vector, simple-array
7:39:42
aeth
And then I think it's the caddr for the other kinds of vectors (vector whatever-type size)
7:42:57
fiddlerwoaroof
I probably should put this into my utility library, because it's something I've often wanted
7:46:19
aeth
Something like this: (let ((seq (make-array 2 :element-type 'character :adjustable t))) (etypecase seq (list 'list) (simple-bit-vector '(simple-bit-vector *)) (bit-vector '(bit-vector *)) (simple-vector '(simple-vector *)) (simple-array `(simple-array ,(cadr (type-of seq)) (*))) (vector `(vector ,(cadr (type-of seq)) *))))
7:47:28
aeth
the cadr will get the type for simple-array and (not simple) vector, with vector having to come last because of all of the special vectors
7:56:53
aeth
(type-of "hello") => (simple-array character (5)) ; in SBCL with *print-case* as :downcase
7:57:09
fiddlerwoaroof
So, I'm going to go the prescriptive way: you do a typecase and put the most specific types first
7:59:34
fiddlerwoaroof
You could even support extensible sequences by falling back to a generic function call
8:02:02
aeth
Although I think the macro on top of specialization-store implementation quickly becomes more concise than the typecase approach
8:16:17
aeth
well, someone finally noticed a few months ago that almost every post to paste.lisp.org was spam because the captcha was ridiculously weak, like 012354 in a monospace font you can probably parse automatically.
8:16:57
aeth
Pretty much every no-registration thing is full of spam, and a lot of registration things, too. e.g. just about any mediawiki has to deal with tons of spam accounts spamming things
8:17:38
aeth
what I think it should do is require bot-based authentication since the main use is for IRC
8:18:04
aeth
so /msg some-bot please and it'll give me a URL that creates a session, no registration required, but if I spam they'll trace it to my IRC nick. And it's too complicated for general spam bots to bother with
8:19:00
aeth
I think that's simple enough that I could write it in a weekend or so, depending on what system the site uses
10:01:37
francogrex
https://codepaste.net/56qjnv in that snipper, on line 6 when I (cffi:foreign-free buf) which I suppose I should, the results are not maintained anymore, when I remove that, I have what I need. but