libera/commonlisp - IRC Chatlog
Search
3:26:18
semz
Oh no, that's not what I meant. The type itself is used for optimization in various declarations, but I'd like to give it a name so that it can be easily changed, rather than writing (integer 0 18743218) everywhere.
3:31:24
semz
beach: It's number crunching, so there's a pretty big performance difference (~3x) when I can get away with fixnums
3:32:15
aeth
Personally, I like picking the smallest subset of fixnum and making it a type for numerical code.
3:32:41
aeth
The compiler can help check some additional assumptions... and some optimizations would only apply if it can stay a fixnum, which very small integers can more easily do
3:33:38
aeth
s/the smallest subset of fixnum/the smallest subset of fixnum that the code can get away with using, usually rounded up to a power of two,/
3:34:04
beach
semz: You can use a trick we have used many times for other reasons. You duplicate the code (in a macro obviously), so that the expansion is `(if (typep x 'fixnum) (progn ,@body) (progn ,@body))
5:47:56
opcode
what's considered idiomatic for mapcar'ing a function that takes an argument? I.e. if I have a gargantuan list of strings and I want to apply (uiop:split-string) to them, what's the, um, "lispiest way" of doing that? I guess I could just use (loop)?
5:52:01
beach
MAPCAR is fine if you already have the function defined, but becomes less convenient when you have to create an anonymous function.
5:52:01
opcode
i have this friend who thinks people who use LOOP are heathens but I rather like it lol
5:54:07
opcode
yeah, I guess I was just wondering if there was a cleaner approach I hadn't considered. I'm coming from C# and friends so I'm used to writing for/while loops like they're going out of style
5:54:50
White_Flame
opcode: where is your parameter coming from, and does it change per iteration step?
5:56:52
opcode
may I suggest adding it to the lisp cookbook, which for someone like me is a great resource
5:58:49
White_Flame
I also made do-hash, do-alist, do-plist to have inline bodies as well, syntactically avoiding the lambda form, but those don't collect results
6:00:10
White_Flame
my do-mapcar also supports skipping items, as well as creating multiple output list items for a sinlge input item, though without those it'd be tiny
6:01:23
White_Flame
(defmacro do-mapcar ((key-var &rest lists) &body body) `(mapcar (lambda (,key-var) ,@body) ,@lists))
6:05:09
opcode
it sounds pretty awesome, you should definitely submit a PR to the lisp cookbook folks. As for me I just shoved a lambda in there since my use case is fairly trivial, but I'll keep an eye out for do-mapcar
6:06:18
White_Flame
I don't think alexandria is about purely syntactic conveniences? it's a deliberately conservative library
6:07:49
White_Flame
it's just alexandria's stated scope, as to not be an unbounded kitchen sink library
6:09:42
opcode
White_Flame: the cookbook is basically a repository of "good ways to achieve XYZ" for people like me who aren't familiar with the ecosystem. You come from, say, Go where json parsers and http clients are built into the std library, and you want to know what a reasonably-popular library is without just googling around randomly, then you check the cookbook
6:11:30
Nilby
If you find typing lambda's tedious, try my favorite macro: (defmacro _ (&rest exprs) `(lambda (_) (declare (ignorable _)) ,@exprs))
6:15:47
opcode
I try to avoid writing macros if at all possible, purely for my own sanity when it comes to the inevitable debugging phase
6:16:03
White_Flame
I like the dolist syntax, putting all the header stuff including params, then leaving the rest of the form for the body
6:17:46
Nilby
I know I'm foolish, but I like implicit pararms. I sometimes wish the whole program was implicit.
6:20:39
paule32
in context of "eval" - the javascript people have supported this as keyword, but nobody of them say that is good practise to use this
6:22:30
paule32
i wonder me, why it give so many ai models, but ai is essential easy, if you step behind the idea
6:23:26
paule32
like the universe - the sense of life - the sense is: "make love" - god say it "make love, and grow"
6:29:14
White_Flame
stating the essentials is easy, if you're speaking words to a human who already experiences the deep implication of the words. But those statements are not fully self-explanatory and are not codable
7:27:34
Duuqnd
So, I'm making a command-line program in CL (sinful, I know). Is there a way to replace SBCL's own command-line arguments without changing the C code? I kinda don't want SBCL's usage text to come up when a user wants help about my program.
7:28:15
hayley
You could change the toplevel function to your own, and have it detect --help and similar.
7:28:39
jackdaniel
Duuqnd: for somewhat systematic approach for building cli tool check out the library net.didierverna.clon
7:29:02
Duuqnd
What would I need to do in the toplevel to stop SBCL from using the arguments? Just change the posix-argv variable?
7:33:23
jackdaniel
it works without cffi, it is needed only when you expect colored output (if I remember correctly)
7:36:38
Duuqnd
madnificent: --script is nice and all, but I'm hoping to have my program just be an executable and work as is expected.
7:41:31
madnificent
certainly possible. i vaguely remember having some scripts running on SBCL or ECL in binary form. i'm fairly sure i didn't distribute them. you could also start with a shebang and move to a binary later when you need it.
7:42:06
jackdaniel
madnificent: I've linked a library that automates all that in a systematic fashion, there is no need for a duct taping
7:44:45
Duuqnd
I was reading some parts of the Clon source to try to figure it out and I saw a comment that reads (paraphrasing a bit) "When a standalone executable is dumped, [only user-level options being present is] always the case" but that doesn't seem to match what I'm experiencing.
7:45:22
madnificent
jackdaniel: yeah, it's mentioned on the cliki page too. it was my impression that it felt too heavy right here.
7:48:40
pve
Duuqnd: If you use sb-ext:save-lisp-and-die, then you should provide your own toplevel function, like hayley suggested
7:50:18
Duuqnd
I'm doing that, yet when I type "--help" it's SBCL's usage message that shows up instead of mine.
7:52:21
jackdaniel
Duuqnd: I think that clon expects you to call a function clon:dump or something like that
13:16:12
JeromeLon
I want to find, remove, and return the first element of a vector that matches a predicate. DELETE is *so* close, but it doesn't return it. I could FIND and DELETE, but that's duplicating the work. The only solution I found is POSITION, followed by (DELETE-IF (lambda (x) t) seq :start position :end (1+ position)). This last bit gives me nausea. Can anyone suggest something less ugly?
13:17:02
JeromeLon
(I do know that delete does not garantee that my original vector contains the result)
13:23:44
JeromeLon
Bike: thanks! And thanks for suggesting replace, I'll use it instead of the DELETE, to change the original vector, it brings several improvements
13:46:41
Krystof
(defun find-remove-and-return (vector predicate) (let (result) (delete-if vector (lambda (x) (when (funcall predicate x) (setq result x) t)) :count 1))) ;?
14:05:52
Colleen
Function array-utils:vector-pop-position https://shinmera.github.io/array-utils#FUNCTION%20ARRAY-UTILS%3AVECTOR-POP-POSITION
15:08:23
JeromeLon
Shinmera: Thanks! I feels like a basic need, indeed. I see why you need this lib in several projects
15:10:16
Shinmera
not covered by the docs, but it also has a * variant that is O(1), but changes order of elements.