freenode/#lisp - IRC Chatlog
Search
19:35:23
pfdietz_
Referencing your earlier comment: "One problem with storing "fat pointers" into strings is memory leaks: if you read a 1 MB string from a file and then save a "fat pointer" to just five characters of it, the rest of the 1 MB is basically a memory leak"
19:37:15
pfdietz_
The CL displacement mechanism for arrays is essentially an immutable offset into a subsection of another array. A sufficiently smart garbage collector could free up the parts of the target array that are no longer reachable.
20:48:49
pjb
But the point is that you map the keycodes to keysyms with xmodmap, and there's no windows keysym.
20:50:14
pjb
emacs uses C- M- and S- and combinations. So we're free to do whatever we want with choards including s- H- and A-.
20:50:58
didi
Idea: In REDUCE, if I say `:FROM-END t', then :START means end and :END means start. Why? Because then I can say `:FROM-END t :START 1' to avoid the last element and not have to say `:FROM-END t :END (1- (length seq))'.
20:51:38
pjb
didi: NOPE. (reduce (function list) "abcdefgh" :start 1 :end 3 :from-end t) #| --> (#\b #\c) |#
21:11:22
comborico1611
So if I run a compiled file in a REPL, it is pretty consistent with how the program would run outside of a REPL? -- specifically concerning the order of defining variables and functions.
21:12:28
comborico1611
The context I'm discussing is pretty expressed here: "REPLs tend to work a little differently, because they are usually used interactively, so don't take their warnings as good normal practice. I'm not familiar with your REPL, but most of them have a paste mode or a compile mode that will work more like a regular compile environment."
21:13:20
Grue`
if it's not a fresh REPL, the previously executed code might affect the newly loaded code
21:22:01
comborico1611
Anyone have recommendations for an article on the subject of order of definitions in Lisp?
21:23:37
comborico1611
In the sense how Lisp differs from most programming languages in that you can't call a function before you define it. (I think -- I'm pretty confused.)
21:24:36
fiddlerwoaroof
? the compiler will complain if a function hasn't been defined yet, but as long as you define the function before your code executes, it should work
21:25:02
fiddlerwoaroof
It gets complicated when you try to use a macro in the same file as its definition
21:25:22
fiddlerwoaroof
Because, the functions a macro calls have to be defined when the macro is expanded.
21:27:18
comborico1611
fiddlerwoaroof: Hmm. What about if defining a paramater which contains a structure defined lower in code?
21:27:34
Grue`
ok, this is dumb. If I use package.lisp to define all my packages, I can't use :import-from to import from a package defined in the same file, because the symbol doesn't exist in the target package because package.lisp is the first file to be loaded
21:30:36
fiddlerwoaroof
Grue`: is the symbol you're trying to import exported from the other package?
21:30:54
fiddlerwoaroof
If it is, it works, otherwise I think you have to refer to it at least once to intern it
21:32:18
fiddlerwoaroof
Well, it depends. I don't like :use, so I'll import-from if I want to avoid typing out the package name
21:35:20
pfdietz_
"Note that top level forms are processed in the order in which they textually appear in the file and that each top level form read by the compiler is processed before the next is read."
21:35:52
pfdietz_
So if you put a DEFPACKAGE form at the top level in a file, that package is available to the reader in reading subsequent forms.
21:36:58
pfdietz_
A somewhat common approach is to put a defpackage at the top of each file, unique for that file. Properly structured, these can be used to infer dependencies between files ("package inferred system").
21:49:40
fiddlerwoaroof
I like using packages to group things "logically" so I don't have to think about the file-structure as much
21:53:20
jasom
uiop:define-package also has some things that are useful for this style: https://github.com/fare/asdf/blob/master/uiop/package.lisp#L712-L733
21:56:47
pfdietz_
I am old school and put defpackages and defmacros off in their own files, to live with lisps that didn't implement things right. I think those have mostly been fixed or died off, though.
21:58:33
didi
pfdietz_: Macros and structs are challenging. Ideally they are defined first, but that means putting them away from where they logically belong, along with their auxiliary functions.
22:19:02
fiddlerwoaroof
I usually define a macro like DEFUN-CT that wraps DEFUN with an appropriate EVAL-WHEN
22:48:38
pfdietz_
The DEF- forms in CL should not need EVAL-WHENs, if the implementation is conforming.
22:50:34
gilberth
pfdietz_: Auxiliary functions to macros still need EVAL-WHEN as fiddlerwoaroof pointed out already.
23:21:01
jasom
:compile-toplevel generated the javascript and :load-toplevel would run postprocessing on the javascript
23:29:49
cl-arthur
I've recently read On Lisp and am looking to consolidate macro-learning by doing some semi-complex projects. Any suggestions? (My own first ideas of making an rdbms (*many* other unknowns, complexer) or a linear program solver (would need to learn linear algebra first, which is a future project) seem poorly suited to the macrology consolidation goal.)
23:52:24
pjb
cl-arthur: or you may help with #nEXT-Browser or with #mezzano https://github.com/froggey/Mezzano
0:03:47
fiddlerwoaroof
didi: EVAL-WHEN sounds a bit scary, but there's only really one form that you'll find yourself using in most circumstances: (EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)...)
0:04:59
cl-arthur
pjb: cheers, several interesting ideas there! Will comb through more carefully tomorrow :)
0:36:23
Josh_2
how can I go from a list like (list *header* *index-body*) to just *header* *index-body* so I can pass the arguments of an unknown length list to a function like append
0:39:07
Josh_2
(cl-who:conc who:*prologue* "<html>"(first (mapcar #'cl-who:conc list-of-html-vars))) "</html>"))
1:13:06
comborico1611
Does LOAD allow a form calling a function before that function is defined in a compiled file?
1:14:12
jasom
comborico1611: define "calling". You can define functions that call functions that have not been defined. Actually calling the function as a toplevel form is unlikely to do what you want.
1:15:30
comborico1611
jasom: (some-function 'whatever) [then on next line] (defun some-function ....)
1:16:14
jasom
comborico1611: yeah, that's not a good idea; I don't know off the top of my head if it's allowed (assuming some-function is already defined before you call LOAD)
1:17:41
Josh_2
jasom: https://plaster.tymoon.eu/view/1232#1232 so I have *index-body* and *navigation* both evaluate to strings but I want to stick the value of *navigation* into the macrobody and get it to evaluate Q_Q
1:19:53
Bike
some forms may be evaluated at compile time to support that, like macro definitions, but most things aren't run
1:20:19
Bike
i'm not sure what you really want here - not having to worry about order makes sense if it's not a sequential list of things to do, but if it's not a list of things to do putting a (some-function 'whatever) call at top level is nonsensical
1:22:16
comborico1611
This cart-before-the-horse ordering is mainly to aid in reading code by zooming out of details.
1:23:13
Bike
i mean, and i just want to reiterate this, (defun foo () (some-function 'foo)) (defun some-function ...) is fine
1:27:40
jasom
cl-who:str puts a string directly into the output without escaping. cl-who:esc does the same, but escaping things (so e.g. < becomes <
1:30:06
jasom
Note however, that I usually compose with functions, as that allows for more dynamicism; it's not needed for your example, but here is me doing it gratuitously: https://gist.github.com/jasom/4d6d8aa38204f3c80db974cb20140aec
1:32:11
Josh_2
I was just use defparams while I messed around and got a grip with cl-who but it appears to have been an hinderance
1:33:16
jasom
you can actually completely omit the optional outstream argument if you just want to always use *html-outstream* but I find it easier to pass a stream as a parameter than to bind a special when I'm doing quick checks of what functions will return at the repl.
1:34:58
jasom
e.g. you could call (navigation *standard-output*) at the repl to print the output of just navigation.
1:42:32
Josh_2
jasom: https://plaster.tymoon.eu/view/1233#1233 when I run (index-page) I only get <html></html>..
1:42:44
jasom
and for many (most?) real world examples I use &key rather than &optional because I have kwards
1:44:16
jasom
if you really want to build strings for each intermediate chunk you would want to do e.g. (str (header)) rather than just (header)
1:59:31
Josh_2
now I have to create a stream handling function for hunchentoot, so I can output that stream to my webpage
2:04:13
moldybits
is it possible to do something like this without defining a block first: (defun foo () (when bar (return)) ...)
2:09:27
Josh_2
jasom: I used (make-string-output-stream) and then (get-output-stream-string) and that worked
2:16:59
jasom
though IIRC that might be a binary stream, so you might have to make a bivalent stream on top of that
2:17:31
jasom
(send-headers) on hunchentoot returns a binary stream that you can write the response to