libera/#commonlisp - IRC Chatlog
Search
22:35:42
aeth
Common Lisp macros are surprisingly easy if you use separate functions (the catch: the functions have to be in a separate file from the DEFMACRO or they need to be inside of an EVAL-WHEN). Remembering when to gensym can be a bit tricky, too, but you avoid issues like not unquoting with , at the right time (nobody knows how to write ` in `) if you use a lot of functions, or at least a giant LET/FLET
22:37:44
_death
to avoid eval-when you can have the functions and defmacro in a single file, but users of the macro in another
22:38:24
aeth
_death: that works until you have a second macro that expands into the macro you just wrote
22:39:29
aeth
there's one thing that's not obvious at all with fancy macros, though: if you need to produce two forms instead of one (macroexpand-1 on DEFUN in some implementations to see this), you need PROGN
22:40:45
aeth
But I don't think there's any book substitute to just writing macros because it's just a bunch of edge cases you get from experience.
22:42:49
lisp123
its just a bit of experience and your mind starting to memorrie the combos of `,, `, etc
22:45:20
lisp123
splittist, be careful - most companies are very against sharing company materials with private e-mails or accounts
22:45:40
lisp123
its just not worth the hassle (and if they are not paying you, why work extra for the company?)
23:10:22
lisp123
phoe, indeed. I think the trick is to teach what is macro (syntax generating function), how macroexpansion etc works - its always on my list to write such a tutorial but never mustered enough energy to do so
23:14:09
phoe
it has been a three-step process for me - imagine the form before expansion, imagine the form after expansion, write a pure/idempotent function that will translate from the former to the latter
23:14:53
aeth
phoe: the problem comes from when it's too big to cleanly fit inside of just one function... which is why sometimes people nest `s and create a mess
23:15:54
phoe
and then, a macro is just a pure* function; if you need to split it up then factor it like you would any pure function
23:16:04
aeth
although I guess putting bindings probably results in nesting ` if not cleanly organized, since you'd do e.g. `(let ,(mapcar ...
23:18:01
phoe
with https://github.com/phoe/portable-condition-system/blob/master/src/restarts.lisp being probably the heaviest example
1:35:04
lisp123
What are the downsides of representing a buffer as an Array of strings, one for each line?
1:43:28
kakuhen
depends on what you're doing i guess... the buffers I often deal with would make that representation a very inconvenient one...
1:59:26
kakuhen
i usually deal with things like audio samples... which make that representation a bit inconvenient
2:00:14
mfiano
Arrays of arrays (array of strings) cannot be made very efficient either, being an array of pointers.
2:03:59
lisp123
the context of why I'm going down this route (after doing some analysis), is that an array of 'lines' lends itself to subclassing lines to various media formats - plain text, rich text, pictures, videos, etc
2:28:15
mfiano
I seem to recall there was a way to tell CL to invoke the debugger on printer releated errors, instead of silence and seeing <<error printing object>> (on SBCL) in the printed repr. Is that something on the CL side or SBCL side? (it's been way too long for me to remember this stuff). cc: yitzi I think it was who wrote a portable printer implementation.
2:36:14
Fare
mfiano: in those cases, I had handlers or ignore-errors and validity checks in my own print-object methods
9:27:51
pve
Good morning! Continuing the theme of file-local things, I wanted to see if symbols can be made file-local. Here's an example of what I got:
9:32:09
pve
But the hyperspec page for the reader algorithm says that "The reader macro function must not have any side effects other than on the input stream...", and I'm not entirely sure how to interpret that.
9:43:26
pve
beach: the reader collects the file-local symbols into a table as it goes through the file, and replaces the occurrences with uninterned symbols.
9:44:48
beach
Yes, I also think it is a side effect. How does that work if the symbol ends with the special character?
9:52:42
pve
beach: when it encounters "%FOO" for the first time it adds an "%FOO" -> #:FOO entry to a hash table, on subsequent occurrences it uses that same uninterned symbol
9:53:37
beach
I was asking specifically for the case when the special character is at the end of the name. And I am asking how you program the reader to do that.
9:54:22
Nilby
pve: The standard reader macros have side effects, so the hyperspec is being a little hypocritical. It's probably good to make sure reader macros don't have _unintended_ side effects, but I think every CL allows it.
9:54:59
pve
beach: oh, I use (alexandria:ends-with "%" (symbol-name sym)), if that's what you mean..
9:57:42
pve
beach: oh ok, with-symbol-expansion sets up the readtable that "intercepts" the standard reader for all "standard" characters
9:58:36
beach
Too bad you are not using Eclector. It would be much simpler, and you would not need to violate the restrictions of the standard.
10:00:05
beach
But I guess you want this thing to work with the default reader of the Common Lisp implementation.
10:00:51
beach
Then let me change to "Too bad all major Common Lisp implementations are using a reader other than Eclector".
10:05:31
pve
beach: If I were to use eclector, I think I would still need to intercept the standard reader for all characters to redirect to eclector at the beginning of the file. Unless some asdf voodoo can be done to change how a file is loaded (I think I would rather load with CL:LOAD).
10:08:53
beach
Yes, I don't think you can change what reader CL:LOAD uses. But that would be handy if it were possible.