freenode/#lisp - IRC Chatlog
Search
15:36:45
kevingal
Is there a way to define self-referential lexical variables? I'm trying to define an infinite stream in terms of itself, which worked with DEFPARAMETER, but when I try to use LET or LET*, I get an unbound variable error.
15:37:26
kevingal
E.g. (defparameter ones (stream-cons 1 ones)) is the infinite stream of 1s (example from SICP).
15:38:16
phoe
I think you might need to quote ONES in there and explicitly call SYMBOL-VALUE on it when you want to retrieve the value
16:01:55
Bike
also, it will hang if your definition doesn't delay the use of itself, so don't do that.
16:02:18
Bike
i'm pretty sure i wrote something like t his years ago for this exact purpose and then never used it for anything
16:02:53
kevingal
Hmmm, (let ((ones (stream-cons 1 ones))) ones) actually works. I'm trying to debug why my more complicated example is failing.
16:04:24
Bike
that really shouldn't work. is it possible you have ONES defined as a global variable?
16:05:27
Bike
my thing works on (letrec ((ones (scons 1 threes)) (threes (scons 3 ones))) ones), neato
16:06:24
Bike
oh, and bonus tip: you can do (makunbound 'ones) to make something stop being a global variable
16:08:52
kevingal
Thanks for the tips! I would normally give them earmuffs but I was copying from SICP :D
16:14:53
kevingal
phoe: the SYMBOL-VALUE approach didn't work, I'm afraid! (scdr (let ((wuns (scons 1 (symbol-value 'thingy)))) wuns))
16:15:18
kevingal
So do I understand correctly that the variable is only available for capture within the body of the LET?
16:15:55
Bike
also, symbol-value is about dynamic variables, not lexical variables, so it's probably not relevant to your question.
16:22:57
Bike
top level definitions can be recursive, obviously. for recursive local definitions you can't use LET since it doesn't make the bindings available to the value-forms.
16:23:26
Bike
LETREC does, but it doesn't exist in the common lisp standard. instead you have to use labels, which is similar, but only allows binding functions.
16:41:22
Nilby
letrec etc is not needed for this, cons-stream is just a macro. you just have to make delay/force which could most simply be quote/eval or quote/symbol-value.
16:46:16
kevingal
Howso? My stream-cons / scons macro expands to a cons with both of the elements wrapped in a lambda.
16:47:53
kevingal
I initially tried using quote, but that didn't capture surrounding variables so this gave an error: (let ((a 1) (b 2)) (scons (/ a b) the-empty-stream).
16:51:00
pjb
kevingal: but yes, there's no let form in CL that evaluate the initialization form in a scope where the variable is defined. We'd have to write a letrec macro…
17:20:39
pjb
shka_: (loop for i below 10 do (with-simple-restart (continue "continue") (if (zerop (random 2)) (invoke-restart 'continue)) (princ i))) #| 25679 --> nil |#
21:29:56
jmercouris
there is no way to safely call C right? because CFFI relies on the C code returning successfully right?
21:30:50
White_Flame
maybe launch a C thread and wait for its return as a side effect somewhere, with a timeout that blows away the thread?
21:32:20
moon-child
if the c lib allocates, you need some way to figure out what it allocated and copy it through
21:32:50
White_Flame
all depends if the C return value is standalone, or if you need C's side effects
21:33:23
White_Flame
even in a separate process, C could kill the lisp process, unless you make it under another user with low permissions etc
21:37:20
Nilby
It's just difficult. You have to setup up memory barriers, page tables, processor rings, interrupt tables, etc.
21:39:04
jmercouris
I'm talking about within the realm of realistically possible for a single programmer to achieve
21:41:08
Nilby
Right. I think that's the nicest way for Lisp to call C, since then you can use the Lisp debugger and tools.
21:44:44
Nilby
I think the free Lisps could do a better job of making calling C safe. The commerical Lisps seem to do better.
21:50:26
moon-child
I think there was another c compiler written in lisp. Not sure how much progress it had made. The mezzano thing I know was mature enough to run quake
22:08:00
moon-child
I think that was it. Given some of the TODO items, it looks less far along than I thought
1:29:10
pjb
Josh_2: well, I don't know about sly, but if a swank server is running, you connect to it with M-x slime-connect RET
1:30:12
pjb
Of course, if there's no swank server listening, the only solution would be to do a gdb attach to the frozen emacs process, and to try to locate and use the socket connected to the image.
1:31:31
pjb
Josh_2: if this problem occurs often, you could prepare by running multiple swank servers in the lisp image, or some other listening server.
1:39:33
pjb
If it's still connected to emacs, as I said above, you can use gdb to attach to the frozen emacs, try to locate the socket and close it.
1:42:08
pjb
Instead, launch your lisp images separately, run a swank server in it, and use slime-connect instead of slime.
1:42:54
Josh_2
pjb: I will do that, I have been meaning to create a deploy system for this. Lesson learned
2:13:10
Josh_2
I export a macro called 'pkv' from my main package and in a sub package, I use this macro extensively, this package has (use <main package>) in its defpackage, why am I getting an error telling me that pkv isn't defined?
2:16:00
Bike
well, from that description it should work, so clearly there's some devil in the details
2:55:40
White_Flame
if you just C-c C-c an expression, instead of C-c C-k'ing the entire file, it might not have actually run the in-package. I've hit that on simple files
2:59:07
White_Flame
it's weird not to load the full contents of a package before loading another one, though
3:13:10
White_Flame
restarting fixes a lot, but doesn't always tell you where the problem is, especially if it's dynamically munged