Arc Forumnew | comments | leaders | submit | zck's commentslogin

Skimming through the comments, I haven't fallen in love with the thread-first operator, but I'm unfamiliar with it. Perhaps I'd become more used to it in time.

I would sometimes do this:

  (def recstring (test s (o start 0))
       (let helper (afn (i)
                        (and (< i (len s))
                             (or (test i)
                                 (self (+ i 1)))))
            (helper start)))

-----

2 points by zck 4433 days ago | link | parent | on: Code golf with many Arc solutions

Main page here: http://golf.shinh.org/

There are some good solutions: http://golf.shinh.org/p.rb?character+subsets#Arc

and some ones that, I would argue, don't actually fulfill the point of the problem: http://golf.shinh.org/p.rb?irc#Arc

-----

2 points by zck 4435 days ago | link | parent | on: Improved plural, pluralize

A lookup table would be interesting. I considered that, but wavered -- would it be filled at write-time, or by some sort of memoization? Keep in mind that if it's memoized, you have to worry about when you tell the function what the plural should be, or you could get inconsistent data.

Is there a use case where you're not aware of the exception when calling the function?

-----

2 points by thaddeus 4435 days ago | link

I had imagined that the table would just be defined in advance from a src file. That would be consistent with other comparable features arc offers. And the memoization would just be a code efficiency thing.

If we don't care about being consistent, it certainly would be cool to have the table load from a data file, and then to have the first run of an override write to file when it's not present. Memoization to, again, cover code efficiency.

As for use cases I only had a few plural overrides I needed to deal with and I too just hard coded them. At the time I did so I remember thinking I should put it in a table, but never got around to it. Then I saw your post and I thought of it again!

Note that I don't really use arc these days, but I have ported most arc functions over to clojure and I'm always looking to improve my library. In my clojure world I would just store them in datomic as facts. I think I might run along and do this now that I've spent some time thinking about it ... ;)

-----

2 points by akkartik 4435 days ago | link

"Is there a use case where you're not aware of the exception when calling the function?"

Any situation where the string being pluralized is not a literal. This is I suppose why rails pluralization doesn't work like this.

-----

2 points by zck 4435 days ago | link

Oh. Duh.

-----

1 point by zck 4442 days ago | link | parent | on: Using Arc with jQuery?

You'd have to write a compiler from Arc to Javascript. As far as I know, there isn't one.

Alternately, it might be easier to write a compiler from Arc to ClojureScript, and then use the existing ClojureScript compiler.

-----

2 points by zck 4449 days ago | link | parent | on: When I type 'mzscheme -m -f as.scm'

If you're using Arc 3.1 with a recent version of Racket (I can verify it works with Racket 5.3.1, but it should work with anything newer than that also), you just call it via `racket -f as.scm`. Arc 3.1 can be found here: http://ycombinator.com/arc/arc3.1.tar . Check out the unofficial Arc wiki for more information: https://sites.google.com/site/arclanguagewiki/

-----

1 point by akkartik 4449 days ago | link

Yeah, I think the '-m' flag was deleted sometime after v372.

-----

3 points by rocketnia 4448 days ago | link

Here's a comment I made in an earlier thread (http://www.arclanguage.org/item?id=14747):

The -m option means to call the "main" function now. Just leave it out. It used to mean "--mute-banner", which suppressed the "Welcome to MzScheme" line.

-----

3 points by zck 4463 days ago | link | parent | on: Discussion about macros in Arc

Yeesh, I can feel my mind expanding. It's fighting it, but it's going.

Thanks again for the tutoring. I can't help but think this would be an order of magnitude easier in person, but c'est la vie.

-----

3 points by fallintothis 4462 days ago | link

Sure thing! I was a teacher in a previous life, so I enjoy helping people learn...to say nothing of whether I'm any good at it. :)

-----

2 points by zck 4465 days ago | link | parent | on: Re-announcing my unit test library for arc

Thanks for the feedback, both here and on the bug in the bitbucket tracker.

I'm not sure of my feelings on changing all the asserts to be just one. On one hand, it is simpler to have just the one command. On the other, it seems like a much more complicated interface, as you would never guess how to use it from, for example, the method signature. assert-t, assert-same et. al. seem like a lower conceptual load.

It reminds me of the arguments over CL's loop macro -- who knows all of it? I can never remember how to do much of what I want. Of course, this is much simpler than loop. Maybe I'll implement it and see how it feels.

-----

2 points by zck 4466 days ago | link | parent | on: Re-announcing my unit test library for arc

I've mentioned my unit test library before (http://arclanguage.org/item?id=17922), but now I think it's pretty much ready for prime time. It reports results nicely (if verbosely), and you can run decent subsets of your tests. It even has a README!

One thing that fell out of this is that there's no built-in way that I know of to check hashes for equality in Arc. Even `iso` doesn't do it (https://bitbucket.org/zck/unit-test.arc/issue/18/make-assert...). So I wrote a way (https://bitbucket.org/zck/unit-test.arc/commits/a007eb6491c3...).

The only big thing that I really want to do for usability right now is to not have a ton of lines of "test X passed!" (https://bitbucket.org/zck/unit-test.arc/issue/20/optionally-...).

I'd love to hear feedback, whether on this forum or by submitting a bug (https://bitbucket.org/zck/unit-test.arc/issues/new). This is a weird thing, but as I'm doing this project for Lisp In Summer Projects (http://lispinsummerprojects.org/), I'm supposed to do pretty much all the work myself. I'd love to take patches after the contest closes.

-----

2 points by zck 4466 days ago | link

Also notable about Lisp In Summer Projects is that 2% of the first 250 entries are in Arc: http://lispinsummerprojects.org/Stats

-----

1 point by akkartik 4466 days ago | link

Wow. Is there a way to see the other 4 projects?

-----

1 point by zck 4465 days ago | link

Well, one other one is brianru's oauth library (http://arclanguage.org/item?id=17925), but I don't think it's publicly released yet. Not to be too stalkeresque, but it's not on his Github (https://github.com/brianru?tab=repositories).

Lisp In Summer Projects hasn't made a list available that I know of. Certainly they will announce the winners; I don't know if they'll announce all the projects. Hopefully.

-----

4 points by zck 4475 days ago | link | parent | on: Quasiquoting and understanding macroexpansion

Ah, fantastic! Thanks for the hint.

For some reason, I had in my head that, inside quasiquote in a macro, you need to unquote every variable you want to evaluate before returning the code to be executed. Note that all my examples have ,sym1 and ,sym2 (except fancy-combine4, but that's deliberately executing the code before the returned generated code).

I guess the moral of the story here is that ,(...) evaluates the entire sexp, and puts the value there. I'll have to do more reading about macros.

-----

4 points by fallintothis 4475 days ago | link

I guess the moral of the story here is that ,(...) evaluates the entire sexp, and puts the value there.

Yup! If your quasiquoted expression only contains unquotes, the expansion is simple. Basically,

  `(sexp1 sexp2 ... ,sexpn ...)
will expand into

  (list 'sexp1 'sexp2 ... sexpn ...)
This also applies recursively, so that

  `(sexp1 (subexpr1 ,subexpr2))
expands into

  (list 'sexp1 (list 'subexpr1 subexpr2))
With unquote-splicing, you can think of quasiquote expanding into cons, so

  `(sexp1 sexp2 ,@sexp3)
will expand into

  (cons (list 'sexp1 'sexp2) sexp3)
If you're interested, I encourage you to look over my implementation of quasiquote in Arc. It's actually pretty simple (175 lines with comments), and might help clarify how quasiquotation works.

I'll have to do more reading about macros.

I think you seem to have the mental model for macros down. And I've always said that macros aren't that magical, because they fall out as a natural consequence of the language. Hell, here's a simple Arc "interpreter" that shows how macros are handled differently from functions:

  (def interpret (expr)
    (if (acons expr)
        (let op (interpret (car expr))
          (if (isa op 'mac) (interpret (apply (rep op) (cdr expr)))
              (isa op 'fn)  (apply op (map interpret (cdr expr)))
                            (eval expr))) ; punt on special forms (fn, if, etc.)
        (maybe-lookup-name expr)))

  (def maybe-lookup-name (expr)
    (if (and (isa expr 'sym) (bound expr))
        (eval expr)
        expr))
Here, interpret is really just another name for eval. Macros are simply functions whose inputs are unevaluated code. They construct some other bit of unevaluated code, and that result gets evaluated.

Quasiquote is then just a nice way to construct lists, whether it's unevaluated code for a macro to return or whatever. Its syntax takes some getting used to, but it comes with practice. Happy hacking!

-----

2 points by zck 4489 days ago | link | parent | on: Help debug some finite state machine code?

Good luck. I could use one -- I've wanted to use it with Twitter for a while. I started writing one myself, then realized I needed a unit test framework, so I've been working on that. Oh, the perils of a language lacking libraries.

Would you like some help? As long as it's free software, I'd love to assist.

-----

2 points by akkartik 4488 days ago | link

But anarki has a unit test framework already: https://github.com/arclanguage/anarki/blob/7415f52cdc/lib/ar.... It also has some intermittent unit tests, e.g. https://github.com/arclanguage/anarki/blob/7415f52cdc/arc.ar...

Did you mean in some other language? It's easy to build a test harness, it's usually the first thing I do with a new language, and invariably just a few lines of code.

Here's my test harness in C++, for example: https://github.com/akkartik/wart/blob/cc70d66ee6/literate/00.... Even in C++ it's just 50 lines or so. Dynamic languages are often even shorter.

(It's not a normal C++ project. I use readable diff directives inside :(..) to add the test harness to the skeleton program at https://github.com/akkartik/wart/blob/cc70d66ee6/literate/00.... But now that this is done, any function I write with 'test_' is automatically run in test mode. Look at the makefile to see how I do that with minimal code.)

Anyways, tell me what language and I'm sure we can get you quickly past this hurdle.

-----

3 points by zck 4487 days ago | link

Honestly, there are some fiddly bits about the unit test framework I don't like, but mainly I wanted to write one.

I actually applied with it for Lisp In Summer Projects (http://lispinsummerprojects.org/), which is why I haven't announced it -- you're supposed to do the work yourself, without help. And people here like to help out and post code. :-p

Luckily, at this point it's got the main features I want, so I can actually use it.

-----

3 points by brianru 4487 days ago | link

Sweet. I had been wanting to play around with the unit test code too -- i'm excited to see what you've put together.

The oauth utility is also for the LISP contest -- we'll see how far I get over the next few weeks.

Either way I'm planning on uploading a few bits and pieces to Anarki or my own repos over the next couple of weeks. (spent some time on anarki's web.arc, the state machine stuff, oauth, some lazy evaluation stuff, etc...)

Once it's all up I'd love some help!

-----

4 points by zck 4487 days ago | link

Well, if it might be useful, let's do it. https://bitbucket.org/zck/unit-test.arc

Please let me know what you think -- email in profile, comment here, open bitbucket tickets, find me on the street^1, etc.

[1] Actually, after writing this, I read your profile, and found you're in Hacker School. I'm in nyc too -- we should meet up sometime. Shoot me an email.

-----

1 point by akkartik 4487 days ago | link

That makes sense :) I'd love to hear more about what's fiddly about the existing version (I have different versions at http://github.com/akkartik/arc, etc.) and why you need the features (suites, nested suites, failure messages, anything else?)

-----

4 points by zck 4487 days ago | link

I'm going to have to go to bed soon, as I need to wake up in eight hours and twenty minutes, and I've promised myself I'm going to try to sleep enough, for once.

So I'll just explain what, in my mind, is the biggest difference -- how I want to use it. To run the anarki test-iso test, you execute the entire `(test-iso ..)` sexp. If you want to run a bunch of tests, you have to execute all the sexps.

That's kind of a hassle. Especially if you find a bug, have a bunch of tests that fail, then change a small thing in the function, and want to re-run all the tests.

In my unit-test.arc, all you have to do is call `(run-suites suite-name)`, and it'll run as many tests as you've got in `suite-name`. You don't have to copy a bunch of sexps into the repl or reload the file (and what if you want to run a subset of a file? You can't). Also -- and this is one of the features I'm currently working on (https://bitbucket.org/zck/unit-test.arc/issue/21/after-runni...), what if you run one hundred tests at once? Do you really want to parse -- with your eyes, like a bloody scribe -- every single line of output to find the seven tests that broke? And when you then make a fix, you're not going to want to parse them again, so you'll only run the seven that failed before. So if you broke something else, you won't find that out.

So, what falls out of my desire to run a set of tests easily and repeatably, and have summarized output? Some sort of grouping, with a single point of entry to run the tests -- that is to say, test suites.

Please correct me if I've missed any feature of Anarki's test framework. I did read its code and try it, but I didn't look into other files for supporting functionality.

-----

2 points by akkartik 4486 days ago | link

Thanks! You're absolutely right, I've had every single one of these problems, I just never focused on them. But I'd often comment out a bunch of tests in the middle of debugging just one.

(brianru also reminded me that arc has a whole new recent unit-test framework with suites: https://github.com/brianru/anarki/commit/b62a38ebcd via https://github.com/arclanguage/anarki/pull/15)

-----

More