Arc Forumnew | comments | leaders | submit | CatDancer's commentslogin
6 points by CatDancer 6238 days ago | link | parent | on: Request for Bugs

atomic stops being atomic if an exception is thrown inside its body:

  (errsafe (atomic (/ 1 0)))

  (= x 0)

  (thread
    (atomic
     (= x 1)
     (sleep .5)
     (= x 2)))

  (atomic:repeat 5
    (prn x)
    (sleep .2))
  0
  1
  1
  2
  2
  nil
a patch is available at http://catdancer.github.com/atomic-fix.html

-----

1 point by pg 6224 days ago | link

Thanks, Rtm used your patch.

-----

5 points by CatDancer 6238 days ago | link | parent | on: Request for Bugs

This makes it hard to use lists as keys for tables:

    arc> (let x (table)
           (= (x '(a b)) t)
           (x (list 'a 'b)))
    nil
As list returns a Scheme list and the key is not ac-niltree'd before being passed to hash-table-get or hash-table-put!, the two lists are not Scheme hash table equal? and so represent different keys in the table.

-----

1 point by pg 6224 days ago | link

Ok, this is now fixed. The Arc def of list now makes an explicit copy. Rtm has ambitions of one day making rest args ac-niltreed copies in ac.scm, whereupon we can return to the nice simple def of list.

-----


If you have ten users currently logged in and you're at the repl, which user do you want to get?

-----

1 point by thaddeus 6239 days ago | link

The one signed in whom clicks submit at the repl... I'm thinking more like 2 admins at the repl.... this is a trick question right?

-----

2 points by CatDancer 6238 days ago | link

Not a trick question, I wasn't quite getting what you wanted to do.

Ok, so you could have the defop repl store the current user in a global variable which you could then access from the prompt. Which would work fine as long as you only had one person logging in as an admin at a time.

If you have more than one person logging in as an admin at a time and you want to know who you are from the prompt, it sounds like the challenge is to get the dynamic value of the user name into the scope of the eval'ed expression?

-----

2 points by thaddeus 6238 days ago | link

Yeah I tried going straight to your second idea (ouch!).

I really don't have 2 admins, but was trying to future proof it. I think I will just start with setting the global variable.

Thanks. T.

-----

2 points by CatDancer 6238 days ago | link

Right, well, notice that the repl-history*, that, and thatexpr are also global variables, and so future proofing it for multiple admins will take more work than just the eval issue.

(For getting values into the eval, one way to do it is with an MzScheme feature called parameters; I have a library to let you use those from Arc which I haven't quite finished yet).

-----

2 points by CatDancer 6241 days ago | link | parent | on: Confused by endmatch

You can see the expansion of endmatch for a particular pat argument using macex1, which shows you the expansion of a macro:

  arc> (ppr:macex1 '(endmatch "foo" s))
  (withs (gs1453 s gs1454 (len gs1453))
         (unless (> 3 (len gs1453))
           (and (is #\o (gs1453 (- gs1454 1 0)))
                (is #\o (gs1453 (- gs1454 1 1)))
                (is #\f (gs1453 (- gs1454 1 2))))))
so you can see why pat has to be a literal string with this implementation.

As to whether unrolling the match in this way will actually be more efficient... we'd need to run some timing tests to find out ^_^

By the way, it looks like your implementation of match-end doesn't work in arc2, I guess it doesn't have the negative index feature to cut from the end of a string.

-----

1 point by conanite 6240 days ago | link

timing tests ... ok, endmatch totally wins. Especially for a mismatch in which case endmatch returns early, but match-end shows no gain. These tests were run on anarki arc:

  average time im ms over 100000 runs of [_ ".jpg" "hello.jpg"]
  endmatch     0.029
  match-end    0.064

  average time im ms over 100000 runs of [_ ".jpg" "hello.png"]
  endmatch     0.016
  match-end    0.062
So it seems performance is a likely explanation for the way endmatch is implemented.

(interestingly, for comparison, on rainbow the time for endmatch is roughly similar (0.028,0.019) but for match-end is disastrous (0.11,0.11). I'll need to figure out why.)

You're right about my match-end not working on arc2 - I mostly use anarki as it has a bunch of convenient changes including negative offsets for cut.

-----

3 points by CatDancer 6239 days ago | link

match-end is disastrous

Though keep in mind that effort making a particular function run faster is only useful if a significant percentage of a program's execution time is spent in that function. For example, even if your match-end runs four times slower than endmatch in rainbow, if a program spends only 0.01% of its time matching the end of strings, then making match-end run faster won't help the program run any faster.

Certainly as an optimization arc2's implementation of endmatch would appear to be premature one, considering that endmatch isn't even used in the arc2 and HN source code, much less identified (as far as I know :) as a hot point slowing down the execution of someone's program. And while I do personally find it to be a fun piece of code (demonstrating how loop unrolling can be done using macros), your implementation is a clear winner in clarity and succinctness. :-)

-----


Is anyone using first-class continuations in Arc code that they've written?

-----

1 point by conanite 6250 days ago | link

I used ccc in an arc parser I wrote (it's at lib/parser.arc in anarki) ... I confess however that the choice of using ccc was driven more by the desire to experience this exotic construct than by the problem itself (as well as needing something to test rainbow's ccc with). The whole thing could be rewritten more simply.

-----

1 point by CatDancer 6250 days ago | link

That's a good example because in this case ccc in only used within the library. Thus an implementation option is to support ccc within a library while giving up something else while running inside the library (speed, or interoperability with Java classes, etc.) that makes to feasible or easy to support ccc inside the library. (After all worst case is that you write an Arc interpreter in which it is easy to support full ccc but it runs 20 times slower). Outside you don't support full continuations, but you have your regular Java Arc implementation (which runs really fast etc.)

-----

1 point by conanite 6242 days ago | link

ccc is also used by the 'point macro in arc.arc - but it's only used as an escape continuation, which is only jumping back up the stack, not copying it, so can be implemented very easily in java without introducing performance issues.

'point is also the only place I could find ccc used in the original arc distribution.

-----


  ProxyPass /folder/ !
  ProxyPass / http://localhost:8080/ retry=0
Apache will use the first matching ProxyPass, so the one for the folder needs to come first, since / will match any request. The ! tells Apache not to proxy that path. The retry=0 is a useful addition, if your Arc server is down it tells Apache not to wait to retry it; that way Apache will start proxying again immediately when your Arc server comes back up.

-----


I'm using git and github as an experiment, wondering what the best way to share Arc patches might be. For myself, so far using git has felt like driving a tractor trailer to get a sandwich at the corner grocery store... big, powerful, can move an awesome amount of stuff, but clumsy... necessary when you have tens of thousands of lines of code, but when your language is high enough level that you don't need that many lines of code, is git actually useful? I don't know yet. In any case, I'm happy to get patches in any form that is convenient for the sender, whether by email, pastebin, or by github's "pull request" mechanism.

-----


Very cool! I sent you an email, and also my email address is cat@catdancer.ws. I also added my email address to my profile here on arclanguage.org.

-----

3 points by CatDancer 6286 days ago | link | parent | on: Using SOAP in Arc ?

SOAP is a terribly bureaucratic protocol. The only time that you'd ever want to use SOAP is if you needed to use a web service and SOAP was the only protocol it supported.

What you want is Arc's read and write functions:

  arc> (tostring (write '(a b 4 5)))
  "(a b 4 5)"

  arc> (fromstring "(a b 4 5)" (read))
  (a b 4 5)

-----

1 point by thaddeus 6286 days ago | link

Thanks CatDancer.... The idea I am working is to see if I can publish a web-app from my server. And that other people can develop their own interface for it. That their interface can change data on my server using web protocols over http, so that anyone one can hook up their own interface to it and choose how much or little they need to manage.

So I believe I am saying I need to use a web service, and I am not sure what options I have for protocols.

The read and write is I can do, but how do I notify my web app that a message has been sent to it for processing ?

Thanks, T. T.

-----

3 points by CatDancer 6286 days ago | link

For a public API, JSON is a nice choice (http://json.org/), for which (ta da!) I just happen to have a reader/writer for: http://catdancer.github.com/json.html

For a nice example of a JSON web API, check out FriendFeed: http://code.google.com/p/friendfeed-api/wiki/ApiDocumentatio...

To handle an API message, you use a regular defop... what makes it a "web" API is that it uses the same HTTP protocol that a browser uses to fetch a web page or to post a form. In fact, you can often use a browser to try out a web API. For example, point your browser to http://friendfeed.com/api/feed/public, and you'll see a JSON message containing the most recent 30 public entries published to FriendFeed.

Here's an example of a very simple API written in Arc. For debugging, I have an op called "log" which will print a message in the window I'm running Arc in. So calling "http://myserver.com/log?message=hello" will print "hello" in my server window:

  (defop log req
    (eprn (arg req "message"))
    (pr "OK"))
My eprn function simply prints out to stderr, since anything printed to stdout is returned to the client.

  (def eprn args
    (w/stdout (stderr)
      (apply prn args)))
The (pr "OK") prints "OK" to stdout, which is returned to the client, so if you pointed your browser at http://myserver.com/log?message=hello you'd see "OK" displayed in your browser window.

To return JSON data like FriendFeed, you can either do it by hand:

  (defop inventory req
    (pr "{\"apples\":5,\"bananas\":18}"))
or use my JSON library:

  (defop inventory req
    (pr:tojson (obj apples 5 bananas 18)))
To have your client control your server, write a defop that takes actions depending on the arguments passed to it:

  (defop shutdown req
    (if (is (arg req "password") "xyzzy") (quit)))

-----

2 points by thaddeus 6285 days ago | link

is there a set of dependancies for json.arc ?

I run:

(pr:tojson (obj apples 5 bananas 18))

and I get:

Error: "reference to undefined identifier: __mz"

Thanks, T.

-----

2 points by thaddeus 6284 days ago | link

ugh!

Ok I found the mz patch you created, but it's a little confusing installing it.

I tried the "patch method" but obviously the command

    "patch <mz.patch"
will not work in the arc top level. i am assuming you're running mzscheme directly to run this command (which i have never done).

I tried downloading your version of arc, but it doesn't work with or sync with "anarki". I get errors.

I find the whole library part of anarki extremely confusing. As much as I am sure people are contributing valuable code, it's like it's a dumping ground with little documentation (some exceptions). People are throwing code in odd directories with odd names and no examples for usage.

wouldn't be nice to have an install like:

  /arc/required/*.arc

  /arc/recommended/patch/before/*.arc; for bug fix code that has to be loaded instead of the relative core arc or mzscheme code, as opposed to after.

  /arc/recommended/patch/after/*.arc; for bug fix code that can be loaded after core arc loads, but before libraries.

  /arc/recommended/libraries/*.arc; 

  /arc/optional/; no optional files or patch files for optional libraries to be in any 'recommended' directories.  

  /arc/optional/patch/*.arc

  /arc/optional/patch/before/*.arc

  /arc/optional/patch/after/*.arc

  /arc/optional/libraries/*.arc

oh and while i'm frustrated.... an ide with a picklist for the optionals that figures out for us what dependancies are in place and manage them.

ugh.....

:)

-----

1 point by thaddeus 6284 days ago | link

Ok,after reading many posts I found the right one; and can see people had already figured out a means to do this....

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

To date I have just been downloading the anarki directory, but tonight I'm going to try using the "git stable" method.

Question for you CatDancer, is your copy of Arc2 the equivalent of 'git stable' ?

I don't find I am using many of the optional features in anarki (so far I only use parsecomb and arcformat which are awesome) and if I do I was thinking I could drop them on top of your arc2 copy.

Thanks, T.

-----

1 point by CatDancer 6284 days ago | link

so far I only use parsecomb and ...

Were you able to get parsecomb to do anything? I was able to get it to make matches, but I couldn't figure out how to get it to tell me which match had been made. (For example, I could have it match a number or a string, but if it matched "123" I would get "123" returned to me but I couldn't figure out how to tell that it was a number that had been matched).

iirc, I ran parsecomb in pg's arc2 by removing the documentation strings from the beginning of the def's in the source.

-----

1 point by thaddeus 6284 days ago | link

Sorry. I meant 'parser'. I use it to feed code into arcformat. Let's me un-expand for presentation purposes.

T.

-----

1 point by CatDancer 6284 days ago | link

is your copy of Arc2 the equivalent of 'git stable'

My copy of Arc2 is pg's original arc2, which I got from http://arclanguage.org/install; I haven't looked at Anarki's stable branch.

-----

1 point by CatDancer 6284 days ago | link

thaddeus, I updated my documentation at http://catdancer.github.com/mz.html to give an explanation of the patch command and how to use it. Take a look and let me know if it's helpful. (Note github has come kind of caching bug with their pages so if you go back to the page your browser will display the old version of the page if it has a copy of it in its cache; you must click the refresh button or press F5 to see the new version).

I also crossed out the explanation of how to apply the patch using "git pull", since as you discovered "git pull" doesn't work if the two git repositories don't share a common ancestor. (I suspect there is a way to do this using git, but I'll have to go looking for it).

-----

1 point by thaddeus 6284 days ago | link

Looks good to me. Thank you for updating your doc.

:)

-----

1 point by CatDancer 6284 days ago | link

"patch" is actually a Unix command, it comes standard with Unix. So you'd type "patch <mz.patch" in your Unix shell, inside your arc directory.

If you're running Windows, if I remember correctly patch comes with cygwin... though I'm not sure.

If you look at mz.patch you can see that it is merely adding one line to ac.scm, so if all else fails, you can edit ac.scm and add the line yourself :-)

mz.patch is a patch against pg's original arc2... I have no idea if it will work with Anarki or not.

-----

1 point by thaddeus 6282 days ago | link

As a note for other n00bs who want to use the mz patch on anarki, it's probably best to just manually add the one line to the ac.scm file. Running the patch will fail with an error "patch already detected". I'm no unix expert but I looked at the anarki verion and there's already extra lines added where the patch expects to place it's code line(And the "add anyway" unix prompt failed for me).

At any rate I'm now playing with your json library CatDancer. Thanks for the help along the way. T.

-----

1 point by CatDancer 6282 days ago | link

I have no idea why I used ((mz integer?) v) instead of (isa v 'int) in json.arc, it sounds like it would have saved you some trouble if you hadn't needed to install the mz patch first.

-----

1 point by thaddeus 6284 days ago | link

Thank you. I will give this another go.

-----

1 point by thaddeus 6286 days ago | link

Ok, that looks like the kind of example I was looking for. Thanks!

-----

5 points by CatDancer 6313 days ago | link | parent | on: Merge let and with into one?

Arc allows you to use pattern matching with let and function definitions (and very convenient it is too!):

  (let (a b) '(1 2)
    (prn a)
    (prn b))
  1
  2

-----

2 points by CatDancer 6310 days ago | link

Oops, I think I misspoke when I described this Arc feature as "pattern matching"; iirc what "pattern matching" means is something that lets you compare a value against a list of patterns and select the first that matched. (Perhaps including setting pattern variables to the corresponding parts of the value, which would be like what this Arc feature does).

Hmm, "auto-destructuring" or even "destructuring" as what to call it, even if is standard usage, is quite the mouthful though...

-----

More