freenode/#lisp - IRC Chatlog
Search
4:58:20
nwoob
Just saw the erc-autojoin-channels-alist example and it was (("freenode.org" "#emacs"))
4:59:18
beach
The CAR of an element of an alist is the key and the CDR of an element of an alist is the value.
5:01:14
beach
So you could have ("freenode.org" "#emacs" "#sicl" "#lisp") in which case the value would be the list ("#emacs" "#sicl" "#lisp")
5:04:58
beach
You can also write ("freenode.org" . ("#emacs" "#sicl" "#lisp")) to emphasize that the value is a list. It's the same thing.
5:06:42
beach
nwoob: I think you need to look into how lists are represented as chains of CONS cells. Once you understand that, the above should be obvious.
5:11:58
beach
nwoob: Do you see how (a . (b c d)) and (a b c d), when read by READ, result in the same constellation of CONS cells?
5:18:45
beach
Then you see that the CDR (i.e. the value of the element) is the same in both cases, namely (b c d).
5:19:26
beach
So there is nothing special about it. Just that in this case, the value is a list rather than an atom.
7:21:54
didi
Is it possible to produce code at every function execution? For example, at https://paste.debian.net/hidden/1f98a75c the recursive LABELS function `sum' has an IF (a COND, really) that depends on the value of wrapping function `my-sum' parameter's `oddp'. The value of `oddp' has been fixed by the caller, so asking about its value at every recursion is unnecessary. I want to get rid of this IF. Maybe I can use some kind of local macro?
7:24:16
White_Flame
generating code at runtime involves sexpr lists as data, and a call to eval or compile
7:24:46
makomo
didi: you can't do it with a macro because macros work at compile-time, and at that moment you have no idea what ODDP is
7:24:57
White_Flame
in ye olde times, there were "fexprs" which were like macros but worked at runtime
7:25:29
White_Flame
which works perfectly fine if your lisp environment interprets sexprs, but doesn't fit with compiling implementations
7:27:30
White_Flame
in your specific example, didi, you could have sum-odd and sum-even that call each other, as 1- toggles between them. Only the entry point needs to test for oddp
7:28:45
pjb
didi: to do it automatically, you'll need some quite smart optimization in the compiler… (because you need to understand the pre/post conditions of the tests!
7:29:59
didi
White_Flame: Indeed, but I have a more complicated function on hold that needs to know the value of a parameter to decides how to iterate. Because it's in a tight loop, I might duplicate the function and change just where I have to, but I wanted to know if I could avoid it.
7:30:33
White_Flame
compile-time does have a lot of constraints, in not knowing what runtime values will be
7:31:09
pjb
So if you wanted the compiler to optimize your code, write it iteratively rather than recursively.
7:31:44
pjb
A good lambda-based compiler would do a good job with recursive functions too. (eg. if it's compiling with continuations).
7:35:55
didi
Yeah, look, SBCL has very similar functions for reducing from the front (`list-reduce') and reducing from the end (`list-reduce-from-end'). If it's good enough for SBCL...
9:07:01
no-defun-allowed
is there a function in CL that finds the duplicate elements in a list? eg (find-duplicates '(1 2 3 1)) => (1)
9:14:50
fivo
Is it possible to get the LAMBDA-LIST and the info like COMPILED FUNCTION shown by (describe 'symbol)?