freenode/#lisp - IRC Chatlog
Search
10:05:11
adip
Hi, could you explain what's wrong with this example? https://ideone.com/1i1fEv Why does compiler complain about undefined variable n ?
10:26:01
adip
no-defun-allowed: I've learned some. What's wrong with that example other than wront variable in third line?
10:31:27
no-defun-allowed
And well, unless your goal is to make people retch, it's usually a good idea to make sure your code is formatted well. Not only is it a sign of politeness, it also makes people usually quicker to respond as they can read nicely formatted code easier.
10:32:11
makomo
adip: if you're using Emacs + SLIME, just run "slime-reindent-defun" to indent the top-level form you're currently in
10:33:53
no-defun-allowed
https://lisp-lang.org/style-guide/ is a little long, but has good examples.
10:38:52
adip
next serious question, Is there a step by step debug mode for sbcl or clisp? something similar to gdb?
10:48:38
adip
it kinda works :D. One last question, for now. How can I make my f function to actually return calculate value... https://ideone.com/hZ3zYc
13:13:56
jmercouris
so in a defpackage you can export a bunch of symbols, that's fine when you load a package
13:14:26
jmercouris
how can you export more symbols from a package when you've already loaded a package?
13:14:49
jmercouris
or for example, if you delete an export symbol in the defpackage it will complain
13:41:30
pjb
jmercouris: (in-package "BAR") (defpackage foo (:use cl) (:export foo1 foo2)) interns the symbols bar::foo, bar::cl, bar::foo1 bar::foo2. If you then (use-package "FOO"), then bar::foo1 and bar::foo2 collide with foo:foo1 and foo:foo2!
13:42:11
jmercouris
try this (defpackage :xyz (:export :fish)), then evaluate (defpackage :xyz (:export :salmon))
13:42:16
pjb
Indeed, it's easier. In defpackage, all the symbols are actually symbol name designators, ie. string designators, so you can use characters, symbols, keywords, or just strings!
13:45:06
pjb
For example, you could first (delete-package "XYZ"), but when doing so, you might get the debugger invoked with restarts about what to do for the packages that used the old package.
13:45:39
pjb
I have a com.informatimago.common-lisp.cesarum.package:delete-packages that recursively deletes a packages and all its dependent packages…
13:47:21
pjb
The point here is that you are mutating a lisp image. defpackage is not designed specifically for package mutation: using it on a package that already exists gives the implementation dependent effects you are seeing. Instead of using package macros, use package functions such as export import use-package unuse-package to mutate the lisp image.
13:47:51
pjb
OR, use asdf to load the packages.lisp file once to define the package once, and reboot a fresh lisp image when you change the package.
13:48:24
pjb
OR, wrap your second defpackage in a handler-bind that will select the right restarts automatically.
13:48:49
pjb
Note that you need either an AI, or using input to specify the right restarts to select automatically!
14:02:08
Xach
jmercouris: It would be nice to have something that did "make the package definition be exactly this"
14:05:08
jmercouris
swank does some stuff to the lisp image when it gets the idea of re-evaluating a form containing a defpackage
16:48:11
flip214
If I need a function on the host and in javascript, how can I tell Parenscript to provide both?
16:48:26
flip214
a (PS (DEFUN ...)) results in a string that's to be sent to the client only, right?
16:50:55
flip214
Bike: well, things like (AREF) and (1+) etc. are the same, for many practical purposes.
16:51:43
Bike
or do some nonsense with #. or macros to avoid actually having it twice in the text, yeah
16:52:12
Bike
i mean, if you have (defun foo (x) x), that's fine in both parenscript and the host, but they go through different compilers, no?
16:52:20
flip214
well, of course I can read the source file at compile time to get the javascript string, and let it be read via ASDF as usual
16:52:43
flip214
Bike: I've got some functions (and a few constants etc.), and I need to have them both in the server and the client.
16:53:14
Bike
just have the code twice, i think. there's like, hardly any relation to having code in parenscript and having it in the host.
18:42:59
fiddlerwoaroof
I believe there's a surprising amount of overlap between parenscript/lisp that makes it somewhat feasible to share code between the languages
18:44:18
fiddlerwoaroof
flip214: one thing you could do is put all the common functions into their own files, include them with asdf and then serve them with a handler that loads them at runtime (or compile-time via macros)
18:45:54
fiddlerwoaroof
something like: (ps:ps (asdf:find-component (asdf:find-system :fwoar-lisputils) "hash-functions"))
18:46:19
fiddlerwoaroof
you'd have to make sure that you have defined a JS "runtime" that conforms to your expectations, though
19:33:27
borodust
hi Xach, any news about PGP support for quicklisp dists? are there a rough ETA around?
20:16:57
buffergn0me
flip214: it me, new nick, but it's true I have only started hanging out on IRC again recently
20:18:43
buffergn0me
You can have a macro that takes a defun (or a body of code) and returns it as-is for CL, and generates the appropriate code to say "also compile these forms with PS and put the result wherever JS is supposed to go"
20:20:53
buffergn0me
Or you can have a separate file(s) for shared code, that just goes in the ASDF definition, and then also gets compiled with PS with whatever tooling you have set up to compile/concatenate/serve etc JS
20:32:36
Grue`
sharing code between Lisp and Javascript? Sounds like the job for cl-clojure-template ;)
20:38:14
Grue`
ecraven: https://stackoverflow.com/questions/44698426/how-do-setf-works-under-the-hood
20:39:51
Grue`
interestingly setq also uses setf expansions, because a symbol-macro can expand into a generalized reference
20:40:35
ecraven
hm.. so defsetf "just" associates the setter with a getter, and the macro expansion of setf then uses that setter?
20:45:34
flip214
buffergn0me: do you have an example? didn't see that kind of code sharing in the docs.
20:46:43
Bike
ecraven: defsetf and define-setf-expander and so on fundamentally just define how setf forms macroexpand
20:47:23
flip214
in ITERATE, can I have some more variables stepped with a generator automatically? something like this:
20:48:00
flip214
(ITERATE (generate element in list and el-car = (car element) and el-cdr = (cdr element)) ... (next element))?
20:48:58
Grue`
ecraven: there can be "setf expanders" defined for various functions, and also there exist functions named "(setf foobar)" that are also used by setf
20:51:12
Grue`
ecraven: http://clhs.lisp.se/Body/05_ab.htm this should be a complete list of how setf decides what to do with its first argument
20:51:57
buffergn0me
flip214: (defmacro shared-code (&body body) `(progn ,@body (setf *ps-forms* (append ',body *ps-forms*))))
20:53:04
buffergn0me
flip214: Then you can (ps* *ps-forms*) in whatever HTTP request handler you have
20:53:26
Inline
the documentation example call is like (%foreign-funcall "sqrtf" :float 16.0 :float)
20:55:37
buffergn0me
flip214: Or write them to a file. Or put them into an in-memory cache and serve them up under a unique URI with long-lived HTTP cache headers
20:57:12
pjb
(multiple-value-bind (q r) (truncate 10 3) (values q r)) == (let (q r) (setf (values q r) (truncate 10 3)) (values q r))
20:58:32
pjb
(defmacro multiple-value-bind ((&rest vars) expression &body body) `(let (,@vars) (setf (values ,vars) ,expression) ,@body))
21:01:31
flip214
buffergn0me: no, sorry. the basic logic is sound. I just hoped that parenscript already includes something like that shared-code macro.
21:04:12
Grue`
the whole point of multiple values is to avoid consing so multiple-value-list should be used only as last resort
21:04:18
flip214
buffergn0me: I guess I'll generate the string for JS by reading some source file during compile-time -- that way I can avoid the extra outer macro.
21:04:25
buffergn0me
flip214: I could not figure out a way to support all the possible use cases: multiple forms in multiple files of mixed, inlined, or separate code have to go to multiple arbitrary output places (dynamic handlers, cached static handlers, files, things that have nothing to do with a web server)
21:05:22
flip214
I would have hoped for a (parenscript:next-defuns-into *some-js-functions) (parenscript:defun ...)
21:11:37
PuercoPop
One thing about the streams API in CL I never quite understand is how I create a custom one. Say I'm trying to open a binary-stream that I can read from in FIFO order what I write into. Or even just write to an array. What I'm currently doing is writing and read from a file but that isn't quite what I want. Is writing my own graystream the way to go?
21:12:26
pjb
PuercoPop: you cannot within the ANSI CL standard (unless you re-implement this CL API in an extensible way, cf. com.informatimago.vfs).
21:12:48
pjb
PuercoPop: on the other hand, you can use the de-facto standard of Gray Streams, which is implemented by most implementations.
21:12:48
buffergn0me
flip214: I have not heard of COMPILER-LET before. CLtL2 already lists it as removed
21:12:50
buffergn0me
flip214: You can do something like that by modifying the value of *parenscript-stream* in an eval-when in PS code
21:14:43
no-defun-allowed
when Gray Streams are usable, they are much more likely to "just work" with other CL code
21:18:04
flip214
buffergn0me: I still need to provide my own LISP+JS-DEFUN macro -- but that's okay. I'll play around a bit.
21:18:45
_death
Gray streams are not the only way.. https://gist.github.com/death/5356be28dc3332caa189c91880fe12c6
21:21:57
pjb
_death: I'd agree. Just note that the gray stream itself could be defined more correctly.
21:22:29
pjb
PuercoPop: sure. But be careful, when using pipes, you need multiple-threads, because I/O are blocking.
21:23:55
_death
also, on sbcl they require this fix: https://github.com/death/sbcl/commit/399170635d5dad01b2866437fa35b14a7de01a1d
21:25:09
fiddlerwoaroof
_death: hmm, my inclination would be to have the decompressing stream always return octets and then wrap that with a flexi-stream
21:26:35
fiddlerwoaroof
And, when it is, you're probably going to want to avoid generic functions altogether.
21:27:55
_death
anyway, the issue is deeper than that use-case.. it should really be a lesson about design of protocols
21:28:12
PuercoPop
pjb: I'm not worried about writing portable code, the xcb library I'm wriiting is SBCL only
21:29:21
jmercouris
eg. (loop for item in items do (some-operation)), when some-operation returns a non-value
21:30:34
_death
so I feel that Gray streams is not part of CL is a good thing, and that also touches on arguments for further standardization...
21:31:00
pjb
Oops, yes, thereis works: (loop thereis (let ((x (random 10))) (if (evenp x) nil x))) #| --> 1 |#
21:31:09
specbot
Termination Test Clauses: http://www.lispworks.com/reference/HyperSpec/Body/06_ad.htm
21:31:25
pjb
I tried it on a boolean, so I thought it only returned nil or t, but it returns the value.
21:33:55
jmercouris
if there is no value, there is no value, I am no magician, I can't fix everything wrong with this database
21:34:45
flip214
jmercouris: why not (OR value (format nil "~36r" (RANDOM (expt 36 10))) to get around that?
21:37:15
jmercouris
and my goodness woocommerce, stores orders as, let me blow your mind, wordpress posts
21:37:34
jmercouris
how do you know the information about the order? obviously that would be in the wordpress post meta table
21:39:02
fiddlerwoaroof
well, the problem with a lot of these things is that the underlying platform isn't an ecommerce platform
21:39:29
fiddlerwoaroof
so the extensions just shoehorn their stuff into the existing data structures.
21:39:57
jmercouris
They have more than enough money to do a clean rewrite and migration for woocommerce..
21:40:50
fiddlerwoaroof
Woocommerce doesn't provide some sort of XML "export all information" functionality?