Arc Forumnew | comments | leaders | submit | zhtw's commentslogin
2 points by zhtw 6393 days ago | link | parent | on: Don't understand how macros work

No. You didn't understand. I meant exactly what I wrote. I want to assign a value to variable which name is stored in the variable "name".

-----

1 point by zhtw 6438 days ago | link | parent | on: Asynchronus I/O in arc

Actually I can live without asynchronous I/O (smth like posix aio_* functions). Just nonblocking read and select/poll would be enough. I have some experience with threads and believe that they just are not worth the throuble in most cases. I find the twisted python's approach (with reactor and deferreds) much more elegant. So I wanted to implement smth similar in arc but it seems I can't at least in the obvious way.

-----

2 points by almkglor 6438 days ago | link

Well, threads are really pretty easy in Arc.

For example I think this ought to work:

  (def nonblocking-read (port)
    (with (done nil
           rcvd nil
           rv (table))
      (thread (= rcvd (read port))
              (= done t))
      (= rv!isdone (fn () done))
      (= rv!received (fn () rcvd))))

  (= foo (nonblocking-read port))
  (while (~foo!isdone)
    (do-what-you-will))
  (now-process (foo!received))
Not sure though; it really depends on how well mzscheme handles blocking I/O.

-----

1 point by zhtw 6437 days ago | link

Yes, thanks, it must work. But it means that you need to have exactly N suspended threads when you're waiting for data from N sockets. Thread pool helps a lot but in worst case you will still need exactly N threads.

-----

2 points by almkglor 6437 days ago | link

Thread management is done automatically for you by the underlying mzscheme. A bit more of research seems to suggest that mzscheme can actually handle blocking I/O even if it uses green threads, and it can also have OS threads if compiled with support for it.

From what little I could grok from http://download.plt-scheme.org/doc/insidemz/insidemz-Z-H-8.h... it seems that there's not much overhead per thread anyway.

What are your concerns?

-----

3 points by soegaard 6437 days ago | link

MzScheme does not use OS threads. A long time ago it did, but it is pretty hard to make it work on Windows, OS X and Linux at the same time. Also context switching becomes cheaper without OS threads.

If you have found anything on OS threads in "Inside MzScheme" it must be in the section on how to embed MzScheme into a C program (with its own thread).

-----

1 point by zhtw 6437 days ago | link

Oh, is that rather usual that scheme implementation uses green threads? If so, maybe I really shouldn't worry about it. I was concerned only because I thought it was expensive to have one system thread per connection.

Thanks for the link.

-----

1 point by soegaard 6437 days ago | link

Most Scheme implementations doesn't use OS threads due to the cost of context switches. It is standard practice to use one thread for each connection.

See for example this very well written introduction to Systems Programming with PLT Scheme:

http://pre.plt-scheme.org/docs/html/more/index.html

-----

1 point by almkglor 6437 days ago | link

Maybe, I'm not sure. I couldn't grok the doc much. AFAIK mzscheme uses green threads only if it isn't compiled with "better" thread support.

As for cost per thread - no, I don't worry about it, it seems that mzscheme threads are reasonably light.

-----

2 points by zhtw 6459 days ago | link | parent | on: Hash element as lvalue

Thanks for the tip. That way my first post, I didn't know how would it look.

Anyway looks like defset is exactly what I need. Thanks a lot!

-----

2 points by absz 6459 days ago | link

It occurs to me that there's another problem with this code: your use of t as a variable name. This is outright forbidden globally:

  arc> (= t (table))
  Error: "Can't rebind t"
. Though it does work locally, it is nevertheless inadvisable: t is the global "true" value (equivalent to 't). It's probably better to use tb as the name for your table.

Glad to be of assistance.

-----

2 points by sacado 6459 days ago | link

And don't ever use tab, particularily for a table : it is a macro's name so it will get you in trouble.

-----

1 point by absz 6459 days ago | link

Or we could fix that part of the language ;)

Seriously, that's one of my biggest standing irritations. If I have some time, I might look at fixing that in the Anarki, actually.

-----

2 points by zhtw 6458 days ago | link

I also had a problem with tab and also think that it should be fixed.

Btw what do I need to load to get the base language without any web stuff. Are there an official "base" part? As.scm loads all the libraries for me. Do I need to load arc.arc only to get the base language.

-----

1 point by absz 6458 days ago | link

Yes, that would be the way to do it, but I don't know a simple way to load only arc.arc.

-----