freenode/lisp - IRC Chatlog
Search
19:39:51
makomo
equwal: i also read all of my books in digital form most of the time, but this one i wanted to have irl :-)
19:40:12
equwal
I like to minimize parentheses even when it breaks convention. Anyone with slime can see the arglist in the minibuffer anyway, why not use it?
19:41:22
equwal
Personally I think COND is a bit of a mistake with the (cond (predicate result)) syntax. (cond predicate result) would have been better I think, for example.
19:42:29
pjb
(cond (condition1 expr11 expr12 … expr1n) (condition2 expr21 expr22 … expr2n) … (conditionp exprp1 exprp2 … exprpn)
19:43:00
pjb
also, there's no difference in memory and processing time between an a-list and a p-list.
19:43:18
elderK
equwal: I find electronic books to be a lot better than deadtree these days, mostly because of the ability to zoom :)
19:43:57
pjb
You can even define a macro (cond. test1 => a b c test2 => d e test3 => f g h else i j)
19:44:22
equwal
Well that is a place where I don't want a print copy. The locally stored hyperspec with slime is the best way to look at code docs I've ever used.
19:46:37
jackdaniel
I'm talking about his personal aesthetics, not yours, so you can't informely say nope (unless you are the same person)
19:47:17
pjb
or (if* condition then something else) if you prefer. or (if* condition else something) for unless
19:48:23
equwal
I think an example that supports my case is where you have a macro that calls another macro for every argument. Like if you have a unit test macro (deftest code result) you might have (deftests code1 result code2 result...) instead of (deftests (code1 result) (code2 result)).
19:52:19
NoNumber
Is PCL still a recommended text here in #lisp? Want to make sure I'm not wasting my time going through it.
19:52:30
pjb
and of course, with embedded ifs: (loop repeat 1 if (= a 1) then if (= b 1) do (something) else do (something-else) end else do (something-a/=1))
19:55:58
elderK
I spent a lot of time playing in Scheme. Lovely language. Great implementations with fantastic communities.
19:59:14
equwal
I don't know if I want that. I like scheme because it is a good simple, small language.
19:59:52
elderK
Silly subjective reasons, too. Like, I like define :) and the way predicates and things are denoted.
20:01:01
equwal
If you go back and look at the history you see that CL got stuck with bad design decisions in order to support old code. Great example is the separate namespaces.
20:01:47
elderK
How many times have you seen people contort the word "list" in an arglist just because they'd shadow the "list" function in Scheme code?
20:05:31
equwal
(defmacro y (lambda-list-args specific-args &rest code) `(labels ((f ,lambda-list-args . ,code)) (f ,@specific-args)))
20:19:00
aeth
CL has some concise/odd/unusual names accidentally because they're old and legacy names and CL is mostly compatible with those old versions. Some of these, like defun or mapcar or dolist seem fairly common. Others, like set or get or rplaca, are basically never used.
20:19:17
aeth
Both Arc and Clojure decided concise names were great and that everyone should save 3 keystrokes.
20:19:58
pjb
actually, you may be saving more keystrokes with the longer names, and emacs completion than with the short names, that are more ambiguous.
20:21:06
aeth
If you write "dofoo" instead of "do-foo" even though "dolist" exists, I don't like your code. Always hyphenate. And please don't abbreviate. Pretty much the only exceptions I can think of are (1) an accepted abbreviation like "id" that seems more right than the correct full form and (2) something like aref or + that's clearly designed to have potentially many on one line
20:22:40
aeth
Emacs will glaldy recognize do-foo as a new form of iteration and highlight it purple. It will *not* do so for dofoo. Are you going to make your users install a gigantic, messy .emacs file?
20:23:06
equwal
I think an immense line like (multiple-value-bind (the-first-thing the-second-thing) (long-names this-line-is-very-long)) is just hard to read. If you abbreviate you get a nice (mvbind (fn arg) (...))
20:23:07
aeth
There are edge cases where indentation simply won't work, but any random do-foo in particular should pretty much work for everyone, highlighting *and* indentation.
20:24:27
aeth
pjb: If Common Lisp were written from scratch using Common Lisp's newer naming standards and no backwards compatibility in names, it would be define-variable, not defvar. And it wouldn't matter because you shouldn't be using it often enough for it to matter, anyway.
20:24:48
aeth
Don't use old names as an example of what to do. That's how you get Clojure creating *new* ugly names in the 2000s
20:25:17
pjb
old names were short because 6 characters stood in a word (36-bit words, 6-bit per character).
20:25:53
aeth
Now, "defun" might be the one reasonable exception to "define-foo". Maybe "defmacro" and "defmethod" as well because they're the basic building blocks of your program. Honestly? define-class would make more sense. It's not like defclass is even built with conciseness in mind.
20:27:52
aeth
Although, really... I don't really have an issue with using define-function all over my code, though. I thought I might, but I don't. Turns out that when I'm adding functions, the extra second to type out 'define-function' doesn't really slow me down.
20:28:06
anamorphic
Hi, I'm a bit stumped with this expression from the defsetf docs at http://clhs.lisp.se/Body/m_defset.htm (defun xy (&key ((x x) 0) ((y y) 0)) (aref *xy* x y)) - I'm not sure what that keyword arg syntax does
20:32:00
anamorphic
Is there some reason in that example code for defsetf that they need to not export a keyword?
20:33:40
pjb
No. it's purely incidental. Perhaps they hadn't completed the specification of &key yet when the wrote the example.
20:34:10
pjb
Or perhaps the person who wrote the example was the promotor of being able to use normal symbols for &key arguments in addition to keywords.
20:37:11
makomo
elderK: regarding the named let, Let Over Lambda does exactly that :-) (implement it as a macro)
20:39:15
elderK
makomo: I imagine you could synthesize named-let with clever use of block or tagbody or something
20:41:39
equwal
Loop is pretty imperative. I like series but there are too many restrictions that make is difficult to know if something will work.
20:42:08
pjb
but you may want to transform the recursion into an interation to avoid using too much stack.
20:43:40
elderK
Well, I was thinking of something that... wouldn't use recursion unless it had to :)
20:44:40
equwal
Chapter 4 is great for getting into read macros. Doesn't require lots of experience.
20:48:24
equwal
Why not just read the first first six chapters? At your level you might not get much from the two non-free chapters anyway.
20:48:37
elderK
I might try writing once-only myself for fun - but I need to really understand /exactly/ what it's doing, first.
20:48:55
makomo
elderK: i would still try just reading it. LoL was the 2nd CL book i started reading
20:49:23
makomo
but as soon as i saw LoL, i had to read it. at that time i was very interested in macros and i wanted to see everything you could do with them
20:50:24
makomo
ONCE-ONLY is indeed a nice exercise, but yeah, you'll want to first start by defining the problem it's designed to solve
20:50:42
equwal
makomo: You'd like OnLisp. The whole book is about macros like LOL http://www.paulgraham.com/onlisp.html
20:52:45
makomo
elderK: to spice it up -- ONCE-ONLY is a macro that writes parts of other macros, i.e. it writes part of another macro's *expander* (the macro itself, the code which produces the expansion)
20:53:00
elderK
Create some gensyms, bind them to the result of evaluating whatever. Then rebind those names to the gensym'd ones. Have the rest of the expansion happen inside the form that creatse those bindings?
20:54:29
makomo
elderK: i guess that's correct, but it's a bit hard to describe in English without explicit reference to the various macroexpansion "levels"
20:55:05
makomo
so it might not be 100% correct, depending on the precise meaning you had in mind :-)
20:55:48
makomo
as ONCE-ONLY has to (1) be hygienic itself and (2) produce expanders which are hygienic
20:58:32
makomo
there are 2 things to learn, (1) the conceptual problem that ONCE-ONLY is designed to solve and (2) the backquote hackery that ONCE-ONLY relies on
20:59:54
makomo
LoL also implements ONCE-ONLY but in a much easier and neater, but sadly unportable way (nested backquotes are neat in their own way though :-))
21:03:42
equwal
I wonder how to understand triple or more backquotes. Like how can I understand what ``````(,@,,@,,,@thing) would do?
21:03:58
pjb
elderK: for example, let's write a macro that takes one argument x and builds a list where x is present twice: (list x x)
21:04:30
pjb
(defmacro double (x) `(list ,x ,x)) (double 42) #| --> (42 42) |# but (let ((x 41)) (double (incf x))) #| --> (42 43) |#
21:05:05
makomo
elderK: exactly as you said -- make sure that a macro argument is evaluated only once, but without doing it manually. usually you would (1) create a gensym, (2) bind the gensym within the expansion to the result of evaluating your ARG and (3) use the gensym instead of ARG everywhere within the expansion
21:05:19
pjb
So you must introduce a temp variable: (defmacro double (x) (let ((vx (gensym))) `(let ((,vx ,x)) (list ,vx ,vx)))) (let ((x 41)) (double (incf x))) #| --> (42 42) |#
21:05:44
makomo
elderK: ONCE-ONLY automates that, for an arbitrary number of symbols (known at compile-time)
21:05:48
pjb
once-only does this automatically, and use the same name for the temp variable, so you don't have to substitute it.
21:06:14
equwal
elderK: You don't have to announce every exit you make from an IRC. Most people come and go, and go long periods without answering.
21:06:35
pjb
Now, personnaly, I've never used once-only, On the rare enough occasions, I use gensym explicitely…
21:06:59
makomo
equwal: that's a good question. i have a writeup within my own notes somewhere which i've been meaning to publish if i ever get a blog or something
21:07:39
makomo
equwal: but the basic principle is the "ladder algorithm". the number of quotes indicates the number of times an expression will get evaluated (iteratively)
21:07:59
equwal
(defun interpol (obj lst) (shuffle lst (loop for #1=#.(gensym) in (cdr lst) collect obj)))
21:08:12
makomo
equwal: which of course assumes multiple (iterative) evaluations of the nested backquote form
21:08:13
elderK
makomo: I think you just touched on something I was meaning to ask: What's the deal with multiple levels of quoting and unquoting?
21:08:35
equwal
Basically I don't want to (length lst) when I could just throw things away with a readtime gensym.
21:08:46
makomo
` is a *reader macro* that reads in as some implementation-defined form that when evaluated produces a list according to a template
21:11:56
makomo
when using N nested backquotes it is expected that you will iteratively eval the form N times. to iteratively eval N times means to do (eval (eval ... (eval form)))
21:12:11
equwal
Read this paper and post-it note the clichés on your computer if you want: https://3e8.org/pub/scheme/doc/Quasiquotation%20in%20Lisp%20(Bawden).pdf fairly famous paper.
21:13:16
makomo
elderK: which means that the rightmost comma is the evaluation that'll be performed as part of evaluating the outermost backquote
21:14:00
makomo
so the ,',a idiom is basically "give me the result of evaluating A once, as part of the first evaluation"
21:14:45
makomo
err, "after 2 evaluations, give me the result of evaluating A as part of the first evaluation"
21:15:52
makomo
the quote in there makes the leftmost comma act as a no-op, which is the point of the idiom
21:17:10
elderK
makomo: Other than the linked PDF, are there any other sources of information on this particular topic that helped you understand multiple-level quotes and stuff?
21:18:31
makomo
elderK: only this really http://www.lispworks.com/documentation/HyperSpec/Body/02_df.htm
21:19:12
makomo
the books are only good for examples of backquote, not really for explaining how it *really* works
21:20:40
makomo
elderK: if you make it your goal to really understand backquote, i would suggest to study the formal rules in the CLHS
21:36:48
jmercouris
so, I'm working on S-XML-RPC with ambrevar on Gnu/Linux, here's what happens when he tries to receive a message in SBCL https://gist.github.com/jmercouris/756d0d10d4ca9aa0a1ebfe9261e9d1d2
21:42:56
jmercouris
if anyone does see something fascinating in the REPL output, please send me an email: john@atlas.engineer
22:56:21
didi
Hum, I think this is the first time I want to use a symbol that is locked to define a function (INTERSECTION).
0:12:42
equwal
They're important. Just make a package so you wont clobber cl-user and you're good to go.
0:14:43
didi
equwal: Ah, yes. I do it like that. I have some packages (and their systems). But I don't think I've played any advanced game yet.
0:20:54
equwal
If you are working from in a package you can make it external but not import it so you access it with package-name:intersection leaving the standard alone.
1:06:40
equwal
How can I change a regular character like #\f to a read macro without a dispatch character? This way I can call a read macro as if it were a function (fn...)?
1:09:56
no-defun-allowed
(defmacro brainfuck (code) `(lambda () (brainfuck-interpret ,(symbol-name code)))
1:10:21
equwal
I got it working like this: #defmacro/g! name (z) `(let ((,g!y ,z)) (list ,g!y ,g!y))
1:12:07
equwal
It does parentheses by just counting until there is an extra one on the right. I am trying to set it up such that it can be called with (defmacro/g!...) making #\d the macro-character. Unfortunately I can't do it without making it impossible to defun declare, etc.
1:13:09
Bike
putting a reader macro on d means when the reader sees a d, you take over parsing. you can't just do it halfway.
1:14:56
equwal
Well I could do that, but I was hoping to get it semantically the same as the book so I could send it to the production code repo.
1:15:45
Bike
there is no such thing as a fake function. i'm not sure where you got the idea that there was.
1:16:47
equwal
I could get it to work if, for example, I set the reader to activate a reader macro if it reads "DEFMACRO/G!"
1:18:03
Bike
as an example, if you had '(defmacro/g! ...), with your scheme funny things would happen.
1:23:19
no-defun-allowed
all i can suggest is to write a macro that takes the code as an argument, takes the SYMBOL-NAME of the symbol and uninterns it
1:40:58
no-defun-allowed
not a reader macro, just a normal macro which reads in your code as an an argument, eg (brainfuck [+.>])
1:43:11
equwal
I used the brainfuck because I though I was simplifying my question. I don't see why what I want to do should be impossible. I think I can do it if I save the original readtable and access it before reverting and the closing parenthesis.
1:44:56
no-defun-allowed
if you want to do a readtable thing, #f[code goes here] could work better for syntax i think
1:53:42
didi
I never used a read macro, but luv-slides has one that I might try some day: #L(if (oddp _) (* _ _) 0) -> (lambda (_) (if (oddp _) (* _ _) 0))
2:39:07
didi
Argh. Format's call function directive is not too hot; I've to use colons to call functions from packages, even if it's a symbol interned in the same package I'm in.
2:49:49
aeth
Any list/cons processing should directly or indirectly use destructuring-bind unless there's a built-in to handle it directly imo. Probably slows it down a bit but makes sure it is what you think it is.
2:51:09
aeth
(and if you actually don't care about the tail in a destructuring-bind it's not hard to do an ignored &rest rest)
2:52:59
aeth
In this particular case, most alternatives would probably work on NIL because (car nil) is NIL and (cdr nil) is NIL.
4:35:56
fiddlerwoaroof
elderK, equwal: LoL is a bit problematic because it doesn't restrict its macro definitions to things that are standards-compliant.
4:36:19
fiddlerwoaroof
So, in some cases, you might discover that implementations have implemented things in a way that breaks the examples.
4:37:21
fiddlerwoaroof
But, I learned the useful trick of expanding to a MACROLET in situations where one might otherwise try to write a codewalker from it.