libera/commonlisp - IRC Chatlog
Search
11:36:06
cpli
if i have to efficiently convert between syms and numeric values, is an alist a good idea?
11:37:06
cpli
^ this snippet currently creates one large case statement which sbcl nicely compiles into a lut
11:48:47
pjb
cpli: I use (ecase expr (#.+foo+ +foo+) …) ; in both cases, you need to wrap the the defconstant in eval-when :compile-toplevel (or compile and load them separately first).
11:50:51
cpli
pjb as in you create a list of 2-element lists as a toplevel compile-time constant and then use a macro?
11:54:04
pjb
You may use a macro. In that case, you can generate both the defconstant and the functions to convert using the values directly. See for example: https://gitlab.com/com-informatimago/com-informatimago/-/blob/master/common-lisp/cesarum/utility.lisp#L389
12:01:29
beach
cpli: It is recommended to use '() to initialize the lexical variable to the empty list.
12:02:25
beach
cpli: And the use of KEY as a Boolean is a violation of the rules suggested on page 13 of the LUV slides.
12:05:53
beach
cpli: And for a large number of values, I might have preferred a hash table. For a small number of values, it doesn't matter much whether you use a CASE form (not a "statement") or alist.
12:07:43
jackdaniel
on the other hand the implementation may generate better optimized code form a CASE form compared to using a hash table
12:08:26
jackdaniel
(in fact I think that sbcl indeed does something special when cases are numbers)
12:08:46
splittist
cpli: you are receiving symbols and run time, and need to turn them into integers?
12:08:58
beach
Sure, you may want to program specifically for one implementation if you really need top performance.