freenode/#lisp - IRC Chatlog
Search
12:34:42
jmercouris
I saw this stack overflow answer: https://stackoverflow.com/questions/578290/common-lisp-equivalent-to-c-enums
12:36:35
jmercouris
is a function call significant overhead as compared to simply having a constant?
12:37:12
jmercouris
I ask because I'm hesitant to use a constant, as the implmentation may change, that data may end up being stored in a database rather than in a configuration file, or in the source code
12:41:14
phoe
jmercouris: you could define a pure function that accepts an argument and returns constant numbers
12:41:21
LdBeth
jmercouris: what do you want to do with enum? I think most of the time plain symbols just work
12:41:23
Bike
not that a function call is THAT expensive. but it will be more expensive. given that the operation of the function will be to look up a constant?
12:42:14
phoe
this will inline the constant and then allow the compiler to optimize the number into raw assembly
12:43:07
phoe
if you then need to change the implementation, declare the function notinline, recompile your whole codebase, replace the function body with something that e.g. fetches data from database and returns the same numbers
12:43:54
phoe
but the question is, do you absolutely need numbers in there? maybe keywords can be enough
12:47:47
schweers
The question is also: how often will this function be called? If it’s not in a tight loop my guess would be that you don`t have to worry about it.
12:48:16
schweers
Even if you need it in a tight loop, just bind a variable outside (it’s supposed to be constant anyway, right?)