freenode/lisp - IRC Chatlog
Search
6:42:40
beach
So, anyway, I don't think there is anything that can be done about the people who claim that Lisp is hard to read.
6:43:47
pranavats
I have heard more convincing claims about comprehension being affected by the syntax, after one has gotten familar with the syntax. Though that is about APL, and tendency of APL programmers to rely on recognizable idioms, instead of just creating new layers of abstraction.
6:44:06
plisp
more relevant to the topic: the couple programmers I talked to were fairly quick to accept indentation-based reading. Almost as quickly as they brought up parentheses
6:48:09
pranavats
I mean comprehension of programs, not the language. Following from that, embedded DSLs can make the job of reading a program a bit of a task; needing to jump from one layer of abstraction to the other frequently, depending on the way the program is written, of course.
6:49:54
ludston
Personally, I think that the worst thing we lisp programmers do is teaching car and cdr before make-array
6:52:04
ludston
The power of lisp over other languages, in my opinion, is that you can manipulate cons cells to generate code dynamically
6:53:23
ludston
And singly linked lists are a terrible data structure for beginner programmers, because writing algorithms to manipulate singly-linked lists can be very fiddly
6:56:06
ludston
Because of this, I think it is better to gain fluency using lisp data-structures like array, and hashtable, because, if you want to write fast lisp code, you will be using these data-structures most of the time
6:56:55
python476
I always feel that perf is better added onto a good overall design and problem space mapping
6:57:12
ludston
And then, mastering list manipulation later, for the sake of writing macro's, is a good approach
6:58:22
ludston
I think that teaching '(), car and cdr first encourages programmers to first try and model their problems in the singly-linked list space, but singly-linked lists are very often a poor abstraction for many algorithms
7:00:21
ludston
pranavats: For example, try writing the quick-sort algorithm using singly-linked lists
7:03:21
python476
but it's very important to make new devs see how the language can impact your coding
7:06:51
ludston
pranavats: If somone was looking over your shoulder, like, "No don't do it like that, just use make-array" you'd have had a much better time, see?
7:09:11
ludston
My experience with common lisp, was that I learned it in my first year of university, because someone else said it was cool. The first book I picked up was Land of Lisp, which taught me a pile of bad habits that I had to unlearn, and then it was not until after I'd done some datastructures and algorithms courses and coming back to lisp was like, "Wow this language is so much better than C#"
7:10:50
beach
You choose the first element as a pivot. Then partition the rest of the list according to that pivot. Recursively sort the partitions. Append the results. Done.
7:15:25
beach
python476: I wasn't arguing about the value of using a list. I was reacting to ludston thinking it was hard to implement.
7:17:07
ludston
beach: Unfortunately, choosing the left-most cell as the partition gets the worst possible performance on an already sorted list
7:17:08
python476
yeah I'm from a recent times where immutable ds / lists influenced me more than CL ways
7:20:16
ludston
beach: The reason I don't agree with you is that I'm looking at a stackoverflow question about this, and none of the answers do it in place https://stackoverflow.com/questions/19082032/quicksort-in-lisp
7:21:05
ludston
beach: It is, in the very least, less trivial to implement quicksort over a list vs over an array
7:21:46
beach
ludston: I strongly disagree. For an array, it gets tricky to avoid an infinite recursion.
7:22:23
ludston
Which is irrelevant to the power of lisp, which supports arrays just as easily as lists, but relevant to which to teach first
7:22:31
beach
You have to be very careful with excluding the pivot and putting it back in the right place.
7:23:40
pranavats
Btw, I didn't use any imperative code when I tried implementing quick sort in Lisp.
7:29:57
ludston
pranavats: You also cannot write a functional algorithm that doesn't have O(n) allocation, by definition, given that you aren't allowed to modify the source list
7:46:05
pyc
Ah! I see one does not add a newline and the other one does while printing the string but they both seem to return the same string.
7:48:58
ludston
pyc: Easy to test the difference with (let ((s (make-new-output-stream))) (write-string "blah" s) (get-output-stream-string s))
11:44:12
pyc
Is there any best practice guidelines for write-line vs. format? Is format to be avoided when write-line would suffice?
11:45:37
pyc
I see all tutorials and PCL book use format even while printing simple strings. Makes me wonder why write-line is ignored. For simple strings, the code looks neater with write-line.
11:46:43
phoe
for me it's (format t "...~%") or (format t "~A~%" variable-string); possibly superfluous, but I never really felt the need to use write-line
11:47:30
pyc
phoe: thanks. that is what I wanted to know. for single characters, I guess you use write-char (still not write-line), am I right?
12:01:57
pyc
Xach: thanks! Incidentally, I was looking for write-line on the web and I came across your code. I agree I like (write-line line) to be cleaner than (format t "~A~%" line).
13:50:56
ralt
_death: are you still maintaining dbus? I've been playing with it again this week, and the main issue I have with it is the error reporting. For example, an invalid list of parameters returns an EOF error
13:53:35
ralt
Because the introspection is runtime but the classes and their slots are defined at compile time :/
15:28:19
_death
ralt: sure, I can review and accept patches.. not using it nowadays so there are no changes coming from me
15:38:43
_death
ralt: I guess one way to make a lispy interface would be to write something that generates stub code from an interface and dump it to a file.. then your code could depend on that stub (harnessing asdf) and the names it exports
17:49:54
rlp10
How do you append a subdirectory to the end of a pathname? I'm finding the number of different libraries a bit confusing, since what I want to do is pretty common I guess.
17:52:10
rlp10
phoe: Thank you, that's really helpful. I guess it's the other way round from what I was expecting, but that makes no odds. I don't know why I was struggling to find it so much. Anyway, I appreciate your quick response - thanks.
17:53:42
aeth
phoe: shouldn't it be uiop:merge-pathnames* to fix portability issues between implementations?
17:55:19
rlp10
aeth: So is that what I should be using? Quite a bit of my scripting deals with folders, files, their contents etc.
17:57:25
aeth
rlp10: uiop/filesystem and uiop/pathname and uiop/configuration (and maybe a few other parts of uiop) may be able to help with some of your problems, but I'm not very familiar with the nuances because I rarely work with complicated file-based operations. Iirc, ASDF mostly uses UIOP for this.
17:58:03
aeth
rlp10: e.g. (uiop:xdg-config-home) should get you the correct parent directory of where you should put your configurations.
17:58:30
aeth
Well, on Linux (XDG) and on Windows (whatever Windows uses). It treats macOS like a Unix, rather than using macOS's custom conventions, so it might not be fully idiomatic there depending on what you're doing.
17:58:42
rlp10
OK, I have to confess that I'm new, so I don't fully understand what uiop and asdf are. I'd probably better start by reading their websites.
18:00:37
aeth
rlp10: Packages in CL are namespaces for symbols. Quicklisp is the "package" manager, but since the name "package" was taken, it's really the "system" manager. Systems are ASDF systems, and they basically are the standard library format in CL. ASDF fills a similar role to e.g. make. ASDF uses UIOP as its utility library, which means UIOP can be useful if you're dealing with files.
18:02:45
aeth
UIOP or CL-FAD should give you what you need, but since most people already have UIOP installed (because it's used by ASDF), the latter is probably more popular.
18:04:18
aeth
UIOP does a *ton* of extra stuff, but it's mostly used for its file/path/etc. functionality.
18:13:32
aeth
It's usually polite to stay within subdirectories of uiop:xdg-config-home or uiop:xdg-cache-home or uiop:xdg-data-home if reading/writing. If only reading, then asdf:system-source-directory will get you the directory of a system (i.e. library). I guess you start from cl:user-homedir-pathname if you want to read/write e.g. ~/Documents
18:37:42
aeth
ralt: yes, and then you can write something like this: (apply #'path-from-dir (funcall lookup-function) (append (if org-name (list org-name)) (list app-name)))
18:38:57
aeth
ralt: that should get you "professional" looking usage of ~/.local/share/ (or whatever the #'xdg-data-home happens to be configured as) where it's ~/.local/share/your-organization/your-app/ or ~/.local/share/your-app/
18:42:15
aeth
(In that case, #'path-from-dir is in turn just a trivial wrapper over uiop:merge-pathnames*)