Search
Monday, 7th of June 2021, 20:19:30 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?
Tuesday, 8th of June 2021, 8:19:30 UTC