Search
Monday, 7th of June 2021, 21:32:45 UTC
3:05:45
beach
Good morning everyone!
5:03:54
rbtEngrDude
** NICK rbtGotKicked
7:23:40
Colleen
Clhs: section 5.2 http://www.lispworks.com/documentation/HyperSpec/Body/05_b.htm
7:51:57
hirez
so I wrote an implementation of graham's scan in CL and it actually works :D
7:51:58
hirez
https://hastebin.com/igapemasop.swift
7:52:21
hirez
its so elegant looking in cl, lol. If anyone has any feedback on how I can make this more...canonical lisp I'd appreciate it
7:53:56
beach
(setf i (+ i 1)) is better expressed as (incf i)
7:54:16
beach
There is no need for a newline after LET* when the body lines are not long.
7:54:28
hirez
old habits from less refined languages die very hard
7:54:59
beach
Similarly, no need for a newline after a PROGN.
7:55:43
hirez
I see yeah, paredit cleans up nicely when I remove it.
7:55:45
beach
Instead of using PUSH and REVERSE, you can use COLLECT in LOOP.
7:56:16
moon-child
hirez: I think it would be cleaner to avoid the pushes in the body, as in (let* ... (stack (list (pop sorted) min))
7:56:46
hirez
Could I? I basically have to hold an element in `sorted` based on the `left` function. I will read up on collect.
7:57:10
hirez
Im not sure how I could avoid the push because the algorithm is dependent on a stack. I'd be interested in hearing how to avoid it.
7:57:10
beach
hirez: You would need an IF clause in the LOOP.
7:57:42
hirez
I see, I'll crack open the hyperspec again.
7:58:04
hirez
ooh I see what you mean moon-child
7:58:11
hirez
yes indeed I can remove those
7:59:42
moon-child
(that's a matter of personal style, though; others would consider it more consistent to view the algorithm as a sequence of pushes onto an empty list)
8:08:35
dsk
hirez: It's best not to try to destructively modify a literal object. That has undefined consequences.
8:09:49
dsk
You can cons up a fresh empty list with (list) instead of using '().
8:10:11
beach
dsk: That's not correct.
8:10:14
moon-child
(list) doesn't cons anything, it returns NIL
8:10:35
beach
dsk: '() is just the empty list, and nothing is destructively modified.
8:10:40
moon-child
'() is a perfectly fine, well-understood, and self-documenting way of producing an empty list
8:10:57
beach
dsk: Even using PUSH after initializing to something like '(a b c) is fine.
8:11:00
phoe
you can't really mutate '() in Common Lisp
8:11:03
beach
PUSH does not modify the object.
8:11:29
phoe
the only thing I can imagine is modifying the SYMBOL-NAME of NIL, but that has nothing to do with lists
8:13:11
dsk
I apologize, not sure where I got that idea.
8:19:22
dsk
It seems obvious that (push thing stack) is equivalent (setf stack (cons thing stack)) so that wouldn't be an issue. But is (setf (car '(foo)) 'bar) okay?
8:19:49
phoe
'(foo) is a literal list and therefore mutating it is UB
8:19:59
phoe
and mutating its CAR counts as mutating it
8:20:26
dsk
Ah, okay, good. Not *completely* losing it.
8:28:11
phoe
it's just that '(), treated as a list, has no components to mutate
8:28:17
phoe
so it can't be mutated
8:31:16
dsk
Right. Somehow my brain went on the fritz and told me that NIL is actually a cons, the CAR and CDR of which are both NIL.
8:31:55
dsk
But I understand that while the CAR and CDR of NIL are both NIL, it is not a cons, though it is a list, and there's only one of it.
8:32:09
phoe
CAR and CDR of NIL are special cases
8:32:24
phoe
NIL isn't a cons, correct
8:32:31
moon-child
imagine if you could (setf (car nil) ...)
8:33:16
dsk
I feel like that may have been possible in some historical Lisp.
8:43:53
Duuqnd
moon-child: https://www.reddit.com/r/LispMemes/comments/g645oy
9:32:44
Duuqnd
If I wanted to have a reader macro that works in one file or one package (whichever is easier) how would I go about doing that?
Tuesday, 8th of June 2021, 9:32:45 UTC