freenode/#lisp - IRC Chatlog
Search
21:48:59
John[Lisbeth]
If I am forming an entire list that needs to be reversed is it more efficient to form it then reverse it or is it more efficient to forming it by appending the value to the end of the list each time?
21:58:50
pjb
John[Lisbeth]: on some old architectures, it was more efficient to push and nreverse it.
21:59:53
pjb
John[Lisbeth]: but nowadays, I would say that if your list is bigger than your cache (depending on the level? VM, L1, L2?), it will be faster to build it in order, but if the list is smaller, then it will be faster to nreverse.
22:13:47
sebboh
rumbler31 was right: (uiop:copy-file "/media/sf_projects/diagrams/work-todo.png" (format nil "/media/sf_projects/diagrams/work-todo/~A.png" (get-unix-time)))
22:14:28
sebboh
internally I guess it uses a syscall and is probably an order of magnitude faster than my previous method, calling /bin/cp
22:19:17
jasom
didi: because nth only operates on lists, and traditionally going past the end of a list returns nil
22:29:39
minion
phoe, memo from pjb: in CLUS, it would be nice if the parts that are identical to CLHS were distinguishable from the part that you re-phrased.
22:30:23
phoe
pillton: and AFAIK taking a 10th element of a 4-element array is an error, therefore undefined.
22:39:47
_death
the clhs gives hint as to why nth works that way, with its equivalence to (car (nthcdr ...))
22:40:01
pillton
phoe: Which falls back to 'Except as explicitly specified otherwise, the consequences are undefined if these type restrictions are violated.' in clhs 1.4.4.3.
22:43:59
pjb
however, both are accessors, and (let ((l (list 1 2))) (setf (nth 42 l) 0) l) #| ERROR: 42 is too large an index for SETF of NTH. |#
22:46:00
_death
(setf (car nil) 42) is also an error.. it's just the implementors doing you a favour with a nicer reason
22:50:51
_death
(actually, there's no need for it to be a place, since (car ...) designates a place.. yet another indicator that I need to go to sleep ;)
22:57:06
azzamsa
found good random pic Lisp https://i.warosu.org/data/g/img/0435/14/1407753601833.jpg
23:10:46
sebboh
Is there some reason (let ((multi-return (fun-that-does-multi-return))) (log:debug (nth-value 1 multi-return))) doesn't seem to be storing the multiple return items into multi-return and then letting me access them at my leisure?
23:11:26
sebboh
I'm willing to accept "you don't know how to use let" as the root cause, but I-- ok.
23:15:39
didi
If you are designing a queue data type, popping from an empty list: 1. errors 2. returns nil 3. returns (values nil nil), like `gethash'?
23:17:19
aeth
There are two common ways to do a queue, one uses lists and the other uses vectors. You don't need to use lists.
23:17:31
rme
In (prefix) dylan, you could say (bind ((foo bar baz) (values 1 2 3))) ...). I've seen at least a couple of attempts at fancy alternative binding macros that try to unify let/m-v-b/etc.
23:18:28
didi
aeth: Thanks, but the implementation is not an issue right now, but how the function should behave when receiving an empty queue.
23:19:28
aeth
didi: If you want to make it parallel stacks (which are built-in), they just return NIL when empty, e.g. (let ((foo (list 1))) (pop foo) (pop foo))
23:21:22
didi
I am abstracting the underlying implementation, so I feel I can choose another way. I am not sure which one tho.
23:22:09
aeth
The other stack in CL errors with "There is nothing left to pop": (let ((foo (make-array 3 :adjustable t :fill-pointer 3 :initial-contents '(0 1 2)))) (vector-pop foo) (vector-pop foo) (vector-pop foo) (vector-pop foo))
23:39:36
sebboh
pjb, I see. I am not aware of a situtation where I'd rather use multi-vals than a list. Probably a common use case is so that the extra values are there if you need them, but you want access to the first value by default. Seems like a job for a quick (car ...) or (first ...) to me, but obviously there's some reason.
23:41:27
pjb
sebboh: building lists is slow (you have to store them in memory). multiple values stay in the registers.
23:44:23
aeth
sebboh: Ime, multiple values are a good way to represent a small number of things, better than even arrays, let alone lists.
23:49:26
aeth
I would hesitate returning more than 4 values, though. I'm sure at some point, implementations become inefficient, but I'm not sure where the modern limit is.
2:24:32
defaultxr
is it possible to change a readtable only while a specific function or macro is being read? i have a function like (defun foo (&rest bar) ...) and i would like to be able to split the 'bar' parameter up by newlines, without affecting how newlines behave for other functions.
2:25:21
defaultxr
additionally i don't want to have to change the readtable manually before and after each invocation of 'foo'
2:28:25
defaultxr
yeah, i'd like to be able to differentiate whitespace from newlines, so i know where the newlines are in the arguments, rather than them just being treated as normal whitespace
2:29:12
defaultxr
so if it's called like (foo 5\n4\n3 2 1) i would be able to split it up to get something like '((5) (4) (3 2 1))
2:30:20
Bike
yeah, that's not possible. it would be difficult even allowing for changing the reader between calls.
2:30:53
Bike
the reader reads whole forms, so if you have (+ (foo 5 4 3 2 1) 7) that whole expression is read at once. and for the inner call, the whole (foo ...) list is read before it could possibly be acknowledged that the car is FOO.
2:32:09
defaultxr
that's unfortunate. so it also wouldn't be possible to selectively replace \n with another symbol if the current form's car is FOO?
2:32:41
Bike
when the reader sees a ( it basically just recursively calls itself a couple times until it hits a ), and puts the results in a list.
2:32:52
pillton
What are you trying to do? Why are you interested in differentiating whitespace from new lines? Are you writing a document?
2:33:48
Bike
personally i'd find it extremely confusing if calls to this one function parsed completely differently
2:34:59
defaultxr
pillton: i'm writing a library for music composition/performance and i feel that it would be faster and more expressive to be able to split musical phrases by newlines rather than explicitly with another symbol between each one.
2:35:34
Bike
if you're making your own score format you might just want to not use the lisp reader for it
2:36:35
loke`
I mean, if it's not actually Lisp code, you can create a parser for that specific format and add it to the readtable: #M[some music format]
2:37:03
pillton
defaultxr: What about (defconstant \\ '\\) and (my-composition c c g g \\ a a g \\ f f e e \\ d d c)?
2:37:17
equwal
You need a reader macro if you want to do it though. I have used them before here: https://github.com/equwal/LispBrain
2:38:24
defaultxr
loke`: basically each line would be the arguments for another function, and i would apply them to that function
2:40:35
equwal
No problem. You can see it at the bottom of code/interpreter.lisp. There is also documentation online.
2:41:12
equwal
That macro makes it possible to run things like #fxyz where rxyz is some brainfuck code.
2:41:28
loke`
defaultxr: How about createing a dispatching macro character (let's call it #M, called like so: #M[ ... ]), and inside that block, #\Newline is redefined to return a symbol. Then something like #M[a b\nd] would be read as (a b SPECIAL d)
2:47:52
equwal
Exactly what I was getting at like #'different-newlines which can be called to create the behaviour you need, and have #'default-newlines set it back (for example)
2:49:08
defaultxr
but then wouldn't those functions have to be called manually? like in an eval-when?
2:49:43
pillton
defaultxr: If you are reading symbols inside the #M reader macro you'll probably need the function read-preserving-whitespace.
2:58:18
pillton
defaultxr: Once you get the reader macro working and you like it, I also suggest that you use the named readtables system to simplify read table management.
7:49:26
holycow2
new version of txr is released: https://www.reddit.com/r/lisp/comments/6bc1mt/txr_175_released_ffi/
9:28:15
easye
Younder: Like LOOP, FORMAT is arguably not very Lisp-y, but is so useful that most people "put up with it".
9:31:28
Younder
I would argue that the ability to create sub languages in Lisp is one of it's strengths. But whatever. It was always a compiler prototyping tool.