freenode/#lisp - IRC Chatlog
Search
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.
10:42:28
dim
am I understanding correctly that those `out' implementations are compatible with that of the format-stinks paper?
10:44:15
_death
mcdermott wrote the format-stinks paper, and recommends it there, so I'm guessing it's compatible.. mine is inspired by his, so maybe
10:46:56
_death
for mcdermott's see src/ytools in https://sourceforge.net/p/clocc/hg/ci/default/tree/
10:58:15
splittist
format strings can be commented. That no-one does it is either a bad habit, or a sign that they're not really mysterious write-only incantations after all.
11:08:30
dim
far too easy to make mistakes, some forms are impossible to remember (0-pad a number to n digits on the left?)
11:12:10
_death
dim: I too dislike use of regular expressions.. I agree with Naggum's point of view, that it may be useful as a user-visible feature, but not really for use in programs
11:15:07
axion
pjb: Thank you for replying to peter's sbcl-help message. We have been trying to debug this for a long time, and your answer makes perfect sense, however, the solution is not going to be ideal for us, as it introduces complexity at the macro call site for the user. This macro is actually used by another macro that handles working with several vectors at once, and worse, for several 4x4 matrices.
11:16:32
_death
dim: with out you could also define your own user-op so it's (out (:u hex32 42)) or something
11:27:54
pjb
axion: well, while you have still 3 slots, your macro is ok. But once you have more, you won't have x y z parameters, but &rest values, and you will write: (map-into pv #'identity values).
11:27:59
axion
pjb: peter failed to show why these macros truly exist. In most cases, the user is supplying 3 15-length arrays
11:30:18
pjb
Now, you may want to use a compiler that unroll the loops, or use your own looping macro to unroll them.
11:30:58
axion
To be honest, we are only interested in sbcl performance, however we definitely want conformity/portability
11:32:23
axion
We went through great lengths to type-annotate and inline suitable functions, and wrote macros such as this to make writing and visualizing everything simple.
11:32:24
pjb
Unless you or the compiler can use vectorial instructions. IIRC sbcl can do some, but I don't know on what conditions. You can always implement the needed VOP.
11:33:06
pjb
So you'd write a loop using your own looping macro, but instead it would use vectorial instructions to implement the body.
11:33:43
pjb
(of course, you'd have a conforming implementation of the macro for other implementations or processors).
11:35:00
axion
pjb: Yes VOPs were something we discussed, and the sb-cga system does this already should we need it. This may be used on other implementations though, so portability is a concern.
11:37:31
Younder
Reader macros are by their nature not isolated. In particular packages can't restrict them
11:37:48
axion
pjb: I can give you an example of how this macro is used in the wild, and why it is nice
11:40:02
axion
pjb: https://github.com/mfiano/gamebox-math/blob/master/src/matrix-ops.lisp#L234 pretty much this whole file is it's main use in the form of WITH-MATRIX and WITH-MATRICES, and the macro definitions are in the matrix-base.lisp file.