freenode/#lisp - IRC Chatlog
Search
11:52:47
kevingal
I'm trying to implement streams using macros. So I can write (scons (/ 1 0) empty-stream) and it'll expand to something like (cons (quote (/ 1 0)) nil).
11:53:50
kevingal
But of course I've found that this doesn't work when I do something like (scons (+ a b) empty-stream) because the "a" and "b" are no longer bound when I try to evaluate the head.
11:55:06
kevingal
Is there a way to capture the environment? Or is that a pants-on-head thing to do?
11:56:44
no-defun-allowed
Yes, usually you implement lazy conses with a macro that expands to something with (lambda () <form>) wrapping the car and cdr.
12:40:16
aggin
but when doing macroexpand-1 in the function, it gives an error before I can see the end result
12:42:20
phoe
the arrow expands into (AREF (LQUERY:$ DATA (CONCATENATE 'STRING ".cb-lv-scr-mtch-hdr a[href*=" QUERY "].text-bold")) 0)
12:42:47
Bike
oh, yeah, looking at $ there, it doesn't look like you can just put normal code in there?
12:43:39
Bike
i man, you're doing ($ (concatenate ...) ...), and it looks like $ does something with lists other than normally executing them?
12:45:07
phoe
yes, looks like $ does lots of stuff under the hood and it implements its own DSL in place of stndard Lisp
12:45:09
Shinmera
Lquery treats function names specially to avoid requiring you to prefix them all with the package name.
13:47:21
kslt1
I'm using emacs/SLIME/SBCL. I wanna use a testing framework for my project from the start. Are there any "survey's" of quicklisp installable testing frameworks I can take a look at?
13:47:47
Shinmera
Sabra said he'd make a survey some time, but I don't think he ever found the time to actually do it.
13:49:35
phoe
above that there's, in random order: fiasco, parachute, fiveam, prove, tens of other test frameworks that are more or less popular
14:25:41
MichaelRaskin
phoe: I am pretty sure I wrote assert-based example/test sets without defun, so _absolute_ minimalism is just assert
15:16:45
mfiano
FInd it odd that prove was deprecated in favor of rove, when rove doesn't even have all the testing constructs prove does
15:25:02
mfiano
I still use prove. I've tried other frameworks and had some bugs with false positives and never really needed anything more from prove. It does use ASDF in a deprecated way, causing warnings.
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