logs archiveIRC Archive / Freenode / #emacs / 2010 / May / 30 / 1
indio
,threading
fsbot
try: CustomizeThreading multithreading NoThreading slrnthreading
ggole
It's been discussed on emacs-devel.
laynor
even though, with dynamic scoping, it seems difficult to use in practice.
quotemstr
laynor: Not really.
laynor: Why would dynamic scoping matter? Bindings are thread-local, right?
laynor
quotemstr: if you implement it that way, yes. But I don't want to think about the impact on existing software
quotemstr
Why?
fsbot
Why not?
quotemstr
What impact?
Right now, Emacs is single-threaded.
All that software will continue to work fine.
         

ggole
laynor: they were discussing "green" threads, not preemptive threads
laynor
ggole: ah ok :) I have no experience nor knowledge about "green" threads
ggole
So old code that didn't call threading primitives would operate exactly as it used to
quotemstr
(Action) prefers adopting the Microsoft term "fiber" for the kind of concurrency we're talking about.
And that's not just because I work for them now. :-P
ggole
laynor: essentially, control is yielded only explicitly, which means that programmers can arrange for changes of state to be expected.
laynor
quotemstr: lucky you :-)
qDot_
coroutine. :D
leo2007
technomancy: hello
quotemstr
No, coroutines are something different.
You can build coroutines on top of fibers, or vice versa to some extent, but the terms don't mean the same thing.
qDot_
Ah, ok.
ggole
laynor: the difference is that if you have a function that mutates some state, you don't have to lock in order to prevent the state from changing under you. All you need to do is not yield.
quotemstr
ggole: You still need locks sometimes though.
ggole
Which is, uh, pretty simple.
quotemstr
ggole: Mainly, when you do want to protect a resource across a yield.
ggole
Yeah, but it only applies to code that uses yield.
So all the old code should still be ok.
quotemstr
ggole: Also, you have to make _sure_ yielding doesn't take place. In some implementations, you yield implicitly when performing IO, for example.
ggole
Yeah, I don't think emacs could get away with that.
quotemstr
(The alternative would be for IO to block everything by default, and to provide separate yield-blocking IO functions.)
ggole: So what do you do with, say, process-send-region?
laynor
happy to know there's some innovation in the emacs pot. What other goodies are they planning for the next generation emacs?
ggole
quotemstr: leave it as it is, unless I'm missing something
         

quotemstr
ggole: Okay, then you need some kind of process-send-region-and-block, yes?
ggole
Yeah
quotemstr
err, -and-yield
Actually, a better approach would be a global special variable *block-yield*
When nil, the default, the entire emacs process blocks when a function would block.
When t, the calling thread yields instead, and resumes when the blocking call returns.
(It's equivalent to an implicit big global lock thing in the nil case.)
ggole
Wouldn't that allow somebody to break existing code by binding the variable?
Assuming it's special and not lexical
quotemstr
ggole: special variables are thread-local (or should be), so only code that explicitly wants that behavior would get it.
ggole
quotemstr: I'm thinking of existing code that is called from within new code
Although maybe new code would just have to be written so that it works
quotemstr
ggole: I don't think that will be a big problem. Blocking calls *generally* aren't buried under many layers.
magcius
Is there a good emacs text mode that automatically format lines to 80 characters?
quotemstr
ggole: And of course, any new code binding this variable would need to make sure code it called was thread-safe.
underdev
hi! i have just discovered M-x term. How can i switch the buffer in a window running term? The term captures all the keystrokes, including C-x b.
quotemstr
magcius: auto-fill-mode
ggole: That said, I think all this is just paranoia. Python, for example, has the equivalent of cooperative threads that yield on block, and it works fine.
magcius
quotemstr: it doesn't quite work when I delete stuff from a line
mrak
reformat the paragraph with Esc-q ?
quotemstr
magcius: Press M-q when yo're done.
ggole
quotemstr: just because you are paranoid doesn't mean they aren't out to get you.
quotemstr
Let's encode Emacs in H.264.
woodworks
ohboy lets start =another= conspiracy theory!
quotemstr
ggole: I also use yield-on-block for Haystack and that approach works fine there, too.
ggole: In fact, I don't even have a block-everything primitive. :)
damd
is it best to use `push' on each element in a list to build a list and then nreverse it or should i use `append' or similar?
quotemstr
damd: LOOP.
(loop for x in foo collect (bar 52))
internally, that keeps both head and tail pointers.
damd
`loop' is not okay in emacs packages, is it?
woodworks
(Action) observes quotemstr, ggole, and damd have their big head hats on
quotemstr
Total time is O(N).
ggole
elisp's loop, sadly, doesn't do the setcdr/tail thing
quotemstr
damd: (require-when-compile 'cl) is okay, and that's all LOOP needs.
ggole
At least not last I checked
quotemstr
ggole: It doesn't?
(Action) checks.
damd
quotemstr: pretty cumbersome to test it then, isn't it?
ggole
(cl-block-wrapper (catch '--cl-block-nil-- (let* ((i 1) (--cl-var-- nil)) (while (<= i 10) (push i --cl-var--) (setq i (+ i 1))) (nreverse --cl-var--))))
:(
quotemstr
ggole: :(
ggole
(Action) wonders how hard that would be to fix
quotemstr
You should still use LOOP just in case that crap is fixed one day.
ggole: I've never looked at the internals of LOOP.
fledermaus
alternatively, never use a monstrosity like LOOP, ever
ggole
I actually saw a nice clean version somewhere, a while ago
It was pretty huge, but nicely factored
fledermaus
lies.
quotemstr
ggole: And the author would probably never sign it over.
ggole
Yeah, good point
quotemstr
ggole: Line 985 in cl-macs.el
Granted, I don't want to touch that code without looking at it in more detail, but it seems like we keep track of the forms in a bunch of sections.
The header (?), the body (loop-body), and the tail (something with cl-loop-handle-accum)
ggole
Ooh, that's a big chunk of function
Oh, just a case. Not so bad.
quotemstr
Oh, great.
All this depends on dynamic binding.
cl-loop-handle-accum just reaches up the stack and twiddles variables bound by loop guts.
ggole
Blargh.
fledermaus
lasciate ogne speranza, voi ch'LOOP
quotemstr
The less wicked way to do that is to make these helpers macros that just refer to free variables. :-)
laynor
fledermaus: s/ogne/ogni :)
quotemstr
Or if we had lexical closures, to use those.
ggole
http://homepage1.nifty.com/bmonkey/lisp/sacla/html/lisp/loop.lisp.html
That's the one I remember
Now for an implementation of CL's format in elisp...
fledermaus
laynor: your renaissance italian is better than mine
quotemstr
Hrm, that's the first time I've seen CDAR used in anger.
laynor
fledermaus: I'm italian, so I studied that stuff in high school :-) And also, "ogni" is a normally used word in modern italian.
damd
if some customizable variable gets added to emacs now, what :version value will it have?
GNU Emacs 24.0.50.1 (i686-pc-linux-gnu, GTK+ Version 2.20.1) of 2010-05-24 on stalin
so does that mean 24.1?
laynor
fledermaus: "ch'intrate" is not used anymore though. It would be "che entrate" or "ch'entrate" now.
quotemstr
It'd be nice if the loop-body data structure were, you know, documented.
sepult
omg, les chretins!
fledermaus
(Action) peers at sepult
sepult
err
quotemstr
Hrm, that's a problem.
"It is valid for several accumulation clauses of the same type to accumulate into the same place"
What the heck is the purpose of the (eq var loop-accum-var) clause?
Shouldn't the true branch of that always work?
damd
quotemstr: it's always good to be sure
quotemstr
Look at the macro-expansion of (loop for x in '(1 2 3) collect x into foo)
What the heck is going on with that nconc?
(setq foo (nconc foo (list x))) ?!
Isn't that O(N^2)?
damd
they should `push' and then `nreverse'
ggole
quotemstr: yeah, that is odd
quotemstr
damd: They do, without the 'into' part.
offby1
ah, the notorious "loop" macro
a mini-language in itself, so I hear
quotemstr
offby1: The cl.el implementation is somewhat worse than I imagined.
damd
loop is like awk - few understand it, even fewer master it!
offby1
awk is pretty easy
damd
shush, you
offby1
just read the Awk book, and Robert is your parent's sibling.
(Action) glances around nervously, to see if isomer is listening
quotemstr
(Action) posts to emacs-devel
offby1
y Roberto es el hermano de su padre
it's the tequila that's making me talk in Spanish.
quotemstr
Actually, can someone verify that loop is still broken in that respect in Emacs HEAD?
I'm using Emacs 22.
ggole
quotemstr: still broken that way in GNU Emacs 23.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.12.11) of 2009-07-30
offby1
quotemstr: can you give me a one-line test case?
that doesn't require either intelligence or sobriety?
ggole
That is, (loop for i from 1 to 10 collect 1 into i) results in nconc silliness. That's what you mean, right?
quotemstr
offby1: Macroexpand
(loop for x in '(1 2 3)
collect x into foo) and see whether nconc appears.
ggole: Yeah
ggole
Er, that should probably be x and not i
offby1
=> (cl-block-wrapper (catch (quote --cl-block-nil--) (let* ((--cl-var-- (quote (1 2 3))) (x nil) (foo nil)) (while (consp --cl-var--) (setq x (car --cl-var--)) (setq foo (nconc foo (list x))) (setq --cl-var-- (cdr --cl-var--))) nil)))
so, I guess it's still broken
GNU Emacs 23.2.50.3 (i686-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-05-22 on erich-laptop
fyi
ggole
quotemstr: as far as I can tell, to fix that we stick a --tail-- var into loop-bindings and then fix up collect/collecting to use that
quotemstr
ggole: That
s
ggole: That's my plan, but first I want to see whether there's a good reason for this craziness.
offby1: Thanks
ggole
quotemstr: how? There's no documentation at all. :/
quotemstr
ggole: By asking whoever wrote it?
ggole
Oh, right. Might take a while, but good idea.
quotemstr
Bombs away.
Eraldo
How can I insert a remember template at point?
quotemstr
"remember template"?
ggole: Actually, I know the reason.
ggole: 'into' means that the variable is externally visible, right?
ggole: It can be modified by arbitrary code. If loop just kept a tail pointer around, other code that loop knows nothing about could invalidate that tail pointer.
ggole
Hmm
SBCL doesn't emit any nconc
And I trust it's loop implementation a lot more than cl-macs.els
quotemstr
ggole: SBCL probably has a code-walker.
bpalmer
quotemstr: it's not clear to me you see why it does that; the variable is visible during the loop.
quotemstr
What about something like (loop for x in '(1 2 3) collect x into foo do (setq foo (append foo (list (1+ x))0 ) ?
offby1
SBCL probably has a couple of developers who actually, y'know, work on it
bpalmer
quotemstr: thus, the value of it "as it should be" must be available during the loop's body.
quotemstr
bpalmer: That's the conclusion I arrived at as well.
ggole
(let ((x ())) (loop for i from 1 to 10 collect 1 into x) x) -> NIL
bpalmer
ok. sorry, this tail-var bit was making my brains hurt.
ggole
Doesn't look like loop considers outside variables
quotemstr
ggole: 'into' variables are bound inside the loop.
ggole
So what's a collection variable "as it should be"? According to how you'd push/nreverse it?
offby1
quotemstr: just saw your message on the mailing list. It's so bizarre to see that you have an ordinary meatspace name
I can't bring myself to mention it!
bpalmer
ggole: yeah. If you collect 1 2 and will later push 3, during the "will later" phase, the variable needs to contain '(1 2) in that order.
let's fight against he who must not be named.
JordiGH
I think I found a bug in Doxygen
quotemstr
(Action) sends another message to the mailing list explaining the noise.
JordiGH
No idea how/if to report it.
quotemstr
Now it'll be archived forever for posterity.
offby1
I think I found a worm in my tequila bottle.
bpalmer
s/he/him/
(Action) is torn grammar-wise.
and my gramaryes may also be torn.
damd
(Action) smirks att quotemstr's devel post
offby1
damd: he has a real name! isn't that weird?!
damd
offby1: i was shocked when i first found out too
offby1
I bet he's got a job, and a place to live, and houseplants, and ...
JordiGH
offby1: It's in his /whois...
damd
actually i have a real name as well
offby1
JordiGH: shush, you
damd
though i rarely post anything of value
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 next »