freenode/#lisp - IRC Chatlog
Search
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.
11:06:16
jmercouris
somehow deleting the key argument in request-resource-block causes the error to go away
11:25:17
trocado
(rename-file #p"test/current/" #p"test/123/") is saying it can't rename [current dir]/test/current/ to [current dir]/test/current/test/123/
11:28:45
Shinmera
"The primary value, defaulted-new-name, is the resulting name which is composed of new-name with any missing components filled in by performing a merge-pathnames operation using filespec as the defaults."
11:29:54
Xach
i think this is widely unexpected behavior, but it does allow some shortcuts if you have it memorized. like (rename-file "/My/cool/file/frob.lisp" "frob-backup") => "/My/cool/file/frob-backup.lisp"
11:32:24
Xach
it has internal logic at least. the problem with intuition and expectation is it's formed by whatever you learn first, and i learned a different style first (unix mv style).
14:25:53
srandon111
guys what is meant by "natural recursion"? and what would it be a "non-natural recursioN" ? i found a post on stackoverflow but wasn't able to understand still
14:30:31
dlowe
yeah, I would interpret as "solving a problem particularly amenable to recursion" but it's not a term of art
14:34:05
beach
I am sure if Daniel Friedman came up with those examples, he probably also supplied a definition of the term.
14:34:45
edgar-rft
-> https://stackoverflow.com/questions/32260444/what-is-the-definition-of-natural-recursion
14:38:05
phoe
it seems to be related to natural numbers, and the most natural operations on these: a check whether a number is zero, adding one to a number, subtracting one from a number
14:38:57
Bike
well i mean it's not actually natural number related https://en.wikipedia.org/wiki/Natural_transformation
14:40:26
phoe
if you want to add 1 and 2 in the natural form, you get the stack of (add1 (add1 (add1 0))) which is a Church-encoded 3
14:53:17
_death
(there is also a http://cmsc-16100.cs.uchicago.edu/2015/Lectures/04-natural-recursion.php )