Arc Forumnew | comments | leaders | submit | conanite's commentslogin
1 point by conanite 5597 days ago | link | parent | on: Atdefs - mutual atomicity

They're correct, but inefficient - it would be preferable to have a lock per queue.

-----

1 point by akkartik 5597 days ago | link

Fo' shizzle. The timing of this item is great, because I've been struggling with performance in my arc-based webapp. I have one thread bringing new items into the index, and it's constantly thrashing with UI threads causing unacceptable latencies.

-----

1 point by aw 5597 days ago | link

MzScheme only uses one CPU, so using atomic doesn't affect performance.

Unless you're wrapping an I/O operation in atomic -- don't do that :-)

-----

1 point by akkartik 5597 days ago | link

I don't use atomic myself. But I find that enabling the back-end thread slows down the UI threads. I've been struggling to create a simple program to illustrate this.

In fact, wrapping parts of my UI threads in atomic actually makes them more responsive[1]. I think it's because instead of getting 200 thread switches with their associated overheads, a single thread runs to 'completion'.

[1] You're right that throughput may go down, though I try to eliminate IO in atomic blocks. But latency is more of a concern to me than not wasting CPU. It's not the end of the world if new data takes a few seconds longer to make it to the index, but a few seconds in the front-end can make or break the user experience.

-----

1 point by aw 5596 days ago | link

Wow, that's interesting!

"vector-set-performance-stats!" in http://docs.plt-scheme.org/reference/runtime.html returns the number of thread context switches that have been performed, so you might try calling that at the beginning and at the end of an UI operation so you can see how many thread switches happened in between.

-----

1 point by akkartik 5595 days ago | link

Thanks for that tip! With its help I was able to figure out that my background thread was just doing a lot more work than I thought.

-----

4 points by conanite 5599 days ago | link | parent | on: Bug: on doesn't work for tables

"let ,gs ,s" frequently prevents double-evaluation of 's at run-time. It seems dumb at first when the expansion of 's is just another symbol or literal, but if 's is a more complex expression, better evaluate it just once.

-----

2 points by fallintothis 5599 days ago | link

For example, consider defining on without it.

  (mac wrong-on (var s . body)
    (if (is var 'index)
        (err "Can't use index as first arg to on.")
        `(forlen index ,s
           (let ,var (,s index)
             ,@body))))
Then

  arc> (wrong-on x (prn "abcd") (prs index x) (prn))
  abcd
  abcd
  0 a
  abcd
  1 b
  abcd
  2 c
  abcd
  3 d
  nil
because

  (macex1 '(wrong-on x (prn "abcd") (prs index x) (prn)))
is

  (forlen index (prn "abcd")
    (let x ((prn "abcd") index)
      (prs index x) (prn)))
Notice that (prn "abcd") is evaluated once at the start, then once on each iteration.

Versus the arc.arc on:

  arc> (on x (prn "abcd") (prs index x) (prn))
  abcd
  0 a
  1 b
  2 c
  3 d
  nil
because

  (macex1 '(on x (prn "abcd") (prs index x) (prn)))
is

  (let gs1763 (prn "abcd")
    (forlen index gs1763
      (let x (gs1763 index)
        (prs index x) (prn))))
Here, (prn "abcd") is evaluated only once. It's bound to the gensym gs1763, which won't clash with any variable names you already have (not strictly, cf. http://arclanguage.org/item?id=5104, but that's the idea).

You can automate this idiom with the once-only macro; see http://arclanguage.org/item?id=9918 or towards the end of http://gigamonkeys.com/book/macros-defining-your-own.html.

-----

1 point by akkartik 5599 days ago | link

Thanks for the pointer to once-only. Is this the version I should use? (I'm having trouble wrapping my head around the nested unquotes)

http://arclanguage.org/item?id=9939

My definition of on seems to eval the list only once anyway, but now I'm feeling paranoid about where else I've missed this and taken a performance hit.

-----

1 point by fallintothis 5599 days ago | link

Is this the version I should use?

You can if you want. It works.

  arc> (let a '(prn 5)
         (once-only (a)
           `(+ ,a 1)))
  (with (gs2595 (prn 5)) (+ gs2595 1))
Note that the parameter list doesn't work like w/uniq, where you can have a single argument with no parentheses. i.e.,

  arc> (let a '(prn 5)
         (once-only a
           `(+ ,a 1)))
  Error: "Can't take car of a"
This was fixed in the Anarki version (http://github.com/nex3/arc/blob/master/lib/util.arc#L374), but that version uses Anarki-specific utilities. The fix is still vanilla-Arc, if you want it:

  (mac once-only (names . body)
    (withs (names (check names alist (list names))
            gensyms (map1 [uniq] names))
      `(w/uniq ,gensyms
        `(with ,(list ,@(mappend list gensyms names))
          ,(with ,(mappend list names gensyms)
            ,@body)))))

  arc> (let a '(prn 5)
         (once-only a
           `(+ ,a 1)))
  (with (gs1724 (prn 5)) (+ gs1724 1))
My definition of on seems to eval the list only once anyway

Yeah, your definition's fine because each already handles the multiple-eval situation.

Side note:

  (zap [+ 1 _] index)
is equivalent to

  (zap + index 1)
which is equivalent to

  (++ index)
Just so you know.

-----

1 point by akkartik 5599 days ago | link

D'oh. You know, I actually tried (zap ++ index) first. Don't know what I was thinking.

Thanks for the (zap + index 1) trick.

-----

2 points by conanite 5611 days ago | link | parent | on: Arc wiki?

http://awwx.ws/ , of course :)

anarki is at http://github.com/nex3/arc and it's world-writable, lots of people share code there

-----

3 points by conanite 5611 days ago | link | parent | on: Arc wiki?

Anarki includes (included?) code for a wiki - see http://arclanguage.org/item?id=5053

I've never tried it so I can't comment

-----

2 points by rntz 5611 days ago | link

That's from back before the transition to arc3, so it'll now be on the arc2.master branch rather than anarki master. (Obviously, if anyone would care to translate it and push it, that would be great.)

-----

2 points by conanite 5612 days ago | link | parent | on: Function argument converter

I proposed this in http://arclanguage.org/item?id=10539 ... but your implementation is neater

-----

2 points by aw 5612 days ago | link

Zounds! Since I generally read every post in the forum, I can only assume that I read your post, forgot about it, and then when I needed to transform some arguments my subconscious presented the idea to me as its own invention :_)

Updated the docs :-)

-----


In addition to all these excellent suggestions, you might take a look at

  start-stop-daemon
which is generally useful on linux for starting background processes. You should be able to find some examples under /etc/init.d

-----

5 points by conanite 5633 days ago | link | parent | on: Ask ArcLang: What do you write Arc in?

With apologies to those who have heard this before ... "Welder" has improved quite a bit since I first mentioned it here - http://www.fnargs.com/2009/05/introducing-welder.html

As far as I know it's the only seriously arc-aware editor in the world - with full syntax highlighting, paren matching, jump-to-definition, delete-surrounding-form, surround-form, expand-macro among others. And it's largely written in arc, so you can use all your arc skillz to customise it.

The catch: it depends on rainbow - http://github.com/conanite/rainbow - and hence on java (the core editor UI is a standard java component) so your enjoyment will depend on having a jdk installed.

-----


very nice. any reason for (alref (req 'args) "code") instead of (arg req "code") ? (even if token count is a silly metric :))

One thing really confusing me: it looks like it writes the string value of the "code" parameter to the serial port, is that how it's supposed to work? (I notice it's the same in python)

-----

3 points by kens 5640 days ago | link

I didn't think of using arg; that's obviously better.

Yes, the code parameter is written to the serial port, where it is received by the Arduino microcontroller board. This board does the work of generating the IR signal corresponding to the code. The details are at http://arcfn.com/2009/11/controlling-your-stereo-over-web-wi...

-----

1 point by conanite 5645 days ago | link | parent | on: Is there any translation work I can do?

Waiters in Paris generally assume I'm an English-speaking tourist (a reasonable bet), and hand me the translated English menu. They mean well, but "Preserved Duck with Potatoes Fried in Duck Grease" doesn't sound anything like the delicious meal it usually is. I fear a translated programming language might have the same icky feel. And it would be a lot harder to share code if keywords were translated. But the tutorial ... yay.

-----

2 points by aw 5645 days ago | link

I'm sure that Arc will always be better in the original. But to deny someone the pleasure of programming in Arc merely because they don't speak English seems... cruel :-)

-----


This works for me, from a terminal, in my arc3.1 directory:

  $ mzscheme -if as.scm 
  Welcome to MzScheme v4.2.1 [3m], Copyright (c) 2004-2009 PLT Scheme Inc.
  Use (quit) to quit, (tl) to return here after an interrupt.
  arc>
What commandline are you using that's giving you the error?

-----

1 point by mk 5659 days ago | link

Sorry I should have been clearer. I can get to an arc repl just fine. Say I wanted to use arc programs from the shell:

$ cat somefile | somearcprogram

How would I get that working?

-----

2 points by palsecam 5658 days ago | link

Disclaimer: self-plug.

You may be interested by this thread: http://arclanguage.org/item?id=10344 - "Arc usable on Unix (include ability to run scripts!)"

-----

1 point by mk 5658 days ago | link

Cool. It looks like they pulled some of your patch into anarki, so maybe I should take a look at it.

-----

More