freenode/#lisp - IRC Chatlog
Search
18:16:45
Bike
it won't work, just to skip ahead a bit. case keys aren't evaluated so they aren't macroexpanded.
18:21:45
jackdaniel
historical note: define-symbol-macro was added for compatibility with islispa long with the lambda macro
18:25:22
jmercouris
backing var is in a separate package so that you can't just setf it to like a new value or something?
18:28:31
_death
no, the backing var is just to provide a storage place.. the point is that with (deflex foo 42) (defun tofu () (* foo 2)) (let ((foo 123)) (tofu)) => 84
18:31:42
jmercouris
so using deflex is the closest you could get to a constant in something like CL?
18:32:58
_death
here's a toy I wrote some years ago https://gist.github.com/death/51c42a208445cd797b119aadf30c0245
18:41:12
jmercouris
we used to use a database for bookmarks for example in Next, but found saving SEXPs to a file much more flexible
18:42:34
_death
sqlite is not a traditional database management system (see https://www.sqlite.org/whentouse.html ) .. how were sexps more flexible?
18:49:20
jcowan
and so is ASN.1 BER if you ignore the schema part of it, which has most of the complexity
18:51:36
jackdaniel
not using a database for data managament is a bad practice, *especially* that there is such great solution as sqlite
18:52:57
jackdaniel
having all in plain text as sexps gives you initially impression, that you do not have to update the schema, but then when you need to update it (i.e you change the format and you update on a system which already runs), you lose big
18:53:48
jmercouris
you don't need to update it, you can have migrated and unmigrated data in the same file
18:53:59
aeth
text is for configuration, not data... you have to manually migrate if you put it in s-expressions... or, I guess, version it
18:54:05
jmercouris
and when you do need to update it, well you would be writing SQL transformations anyways
18:54:49
jackdaniel
this is an example where a difference between "simple" and "easy" is very apparent
19:04:23
buffergn0me
Another plus for s-expressions in files is less dependencies - the code and data will be easier to read and the system to run 20 years from now
19:09:29
_death
if you have a flat file of sexps, then looking up the value for a particular variable would be slow
19:10:20
_death
these arguments are age old.. when I wrote this defpersist toy, I chose sqlite because it worked well with my perceived use cases
19:11:32
jackdaniel
and before dbm there were text files, and before that there were sheets of paper ,)
20:58:51
adam4567
My .sbclrc contains quicklisp's location ".quicklisp/setup.lisp"..etc, that seems OK
20:59:03
adam4567
-rw-rw-r-- 1 adam adam 3985 Mar 19 23:56 /home/adam/.quicklisp/local-projects/cm/cm.asd
20:59:36
adam4567
Unhandled LOAD-SYSTEM-DEFINITION-ERROR in .. : Error while trying to load definition for system from pathname /home/adam/.quicklisp/quicklisp/: Can't LOAD a directory: #P"/home/adam/.quicklisp/quicklisp/".
2:26:41
elderK
The reason I ask, instead of just using symbols, is that for efficiency, I'd like to represent something as a 2D array. Say, a transition table.
2:38:52
conjunctive
Hi all, just released a Huet-style zippers library for CL: https://github.com/conjunctive/zip
2:39:05
conjunctive
Also, working with FSet has been fantastic! Coming from Clojure I felt right at home.
2:50:16
elderK
pjb: If using a case statement, would this require translating the integer back to a symbol, and such
3:00:07
adlai
elderK: if you want to roll-your-own, i recommend an eq table from symbols to numbers; anyone concerned about the backlinks deserves the algorithmic complexity.
3:01:00
pjb
elderK: defconstant defines constant variables. Theorically, they could be implemented as symbol-macros, but implementations define them natively, to be able to detect bindings at compilation time, and for keywords.
3:02:37
pjb
elderK: well, defining constant variables as symbol-macro wouldn't let you prevent binding them.
3:02:54
adlai
elderK: instead of a 2D array containing symbols designating the elements within the enum, (make-hash-table :test #'eq) for mapping symbols to offsets within the array; then, you don't even have to allocate that array if it's prohibitively large.
3:05:22
elderK
adlai: I'd rather avoid a hashlookup every time I need the integer value of some symbol.
3:05:44
elderK
I need to learn more about the case form. Are the things it matches against even evaluated?
3:06:09
pjb
elderK: you have to define boundaries, outside of which the symbols are used and inside of which the integers are used.
3:07:09
pjb
elderK: If you define constant variables, they have to be defined at compilation-time, so you can use them with #. in case forms processing the integer values.
3:07:37
pjb
In all cases, I don't see the point of using a hash-table, conversion functions can just use case.
3:14:26
adlai
elderK: if you'd like to reoptimize an eq hashtable once you're convinced that the enum's membership set has settled, you can verify that hash-table-count and hash-table-size are sufficiently far apart, and then call rehash; however, this is all an implementation detail, and your enum lookups should happen at compile-time
3:16:27
adlai
myeah, there's no cl:rehash, although the desired side-effect is to rebuild the hashtable, without another call to make-hash-table, so that optimizers who pay attention to the membership set have an opportunity to work
3:19:17
Bike
each case has a list of keys that are checked against with eql. if a clause key is T or OTHERWISE it's a default. if a clause key is some other object that counts as a list of one object. that's about it.
3:21:16
adlai
maybe elderK is just asking "how is case implemented, when i reserve the right to use as many distinct keys as the size of some mystery 2D program text"
3:22:05
Bike
it means it can be compiled into a jump table sometimes. that's nice. but it's fundamentally a pretty static operator.
3:23:23
adlai
elderK: you may find the string-case macro implements exactly what you didn't think you were asking, if you want the enum members to exist at runtime
3:25:42
Bike
so that's how cl:case works as well. C does have a more expansive concept of constant expressions, though.
3:27:10
adlai
there is a string-case library that builds a table from strings at compile time, and evaluates the key at run time, although it is not supposed to be abused as a replacement for enumerations
3:28:08
adlai
elderK: in your example, the symbol foo might never be evaluated after the compiler hits defconstant
3:29:08
Bike
the macro trying to evaluate the keys would be a problem because A) it needs a list, and B) case is actually used with literal unevaluated symbols a fair bit
3:29:20
Bike
might be interesting to think about an expansion of what constant expressions are good for, tho
3:29:47
elderK
:( So, what's the idiomatic equivalent to a C enumeration, and switching on enumerants? Or using those enumerants as indices?
3:31:18
elderK
So then, if I want to have a mapping between symbols and integer indices, I need a map of somesort.
3:32:00
Bike
yeah. well, just define a symbol->integer function that everything uses, and stress about the best way to implement it later
3:34:31
Bike
if the implementation evaluates defconstants at compile time, as most do, that works fine. if you wanna be paranoid you can put an eval-when on
3:57:59
aeth
elderK: The most idiomatic equivalent to an enum is a member type, e.g. (deftype color () '(member :red :green :blue)) (typep :red 'color)
3:58:45
aeth
Of course it doesn't actually have an (accessible) associated number until you define an ECASE that maps it to a number, as Bike said.