Arc Forumnew | comments | leaders | submitlogin
5 points by akkartik 5137 days ago | link | parent

This thread's making me uncomfortably aware of how many tricks I - and we as a community - have forgotten about. The HN-style forum interface isn't ideal. Perhaps we need a repository of tips like http://vim.wikia.com/wiki/Vim_Tips_Wiki

I remember seeing tricks for cons counting, profiling (http://arclanguage.org/item?id=11556, another story about forgetting the existence of a key tool), tracing, visualizing macroexpansion.. the list goes on. Lots of stuff in the arc2 branches never made it to arc3. I'm certain there's gems there.

-

I posted a few at http://arclanguage.org/item?id=11111

REPL tricks at http://arclanguage.org/item?id=11103

Then there's defgeneric/defmethod. I'm still proud of the writeup on how I rediscovered defgeneric for myself: http://arclanguage.org/item?id=11779

And serialize/unserialize/persisted: http://arclanguage.org/item?id=11865

I like these one-liners:

  (= be is)
  (= neither nor)
  (= redef =)
Here's a counter-intuitive one:

  (= const =)
I'm using 'const' as just documentation - it's up to the programmer to not change the variable.

I don't want to use init (http://arclanguage.org/item?id=11103) because I do want the value to be updated when I reload the file. init is for global state in data structures which shouldn't be reset when I reload the file, and const is for global parameters that influence the behavior of my app. Those I often do want to update on reload.

-

Another recent macro encapsulates a common pattern for initialization code:

  (mac firsttime(place . body)
    `(unless ,place
       ,@body
       (set ,place)))
-

A workhorse of readwarp: pick a random feed from a set and check if it satisfies certain properties (e.g. has an unread item, is recent, is well-cleaned, etc., etc.)

  (mac findg(generator test)
    (w/uniq (ans count)
      `(ret ,ans ,generator
         (let ,count 0
           (until (or (,test ,ans) (> (++ ,count) 10))
              (= ,ans ,generator))
           (unless (,test ,ans)
             (= ,ans nil))))))
The generator expression often uses randpos:

  (def randpos(l)
    (when l
      (l (rand:len l))))
As I've said before, suggestions for better names are especially welcome.


2 points by fallintothis 5137 days ago | link

And then, exploding forth with a dramatic surplus of conceit and utter lack of humility, came ... ME!

cons counting

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

tracing

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

visualizing macroexpansion

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

the list goes on

http://arclanguage.org/submitted?id=fallintothis

(Okay, that last one was excessive, but I thought it was funny. I'm just glad anyone likes things I write. :P)

P.S.: Gah! I hadn't realized rand-elt would break on empty sequences before. Good catch. Should probably use (unless (empty ...) ...), in case you want a random string character.

-----

2 points by shader 5133 days ago | link

Yeah, I've noticed that a lot of arc ideas have been posted as code in comments, instead of linked to on a source control site. This makes it so that the code is more likely to get lost, and harder to use in the first place.

To be honest, this is what I think people should be using the 'lib section of Anarki for; posting code that they think is useful. That way it's available for anyone that wants it. If you post code on the forum, post it somewhere else so that people can find it again.

Maybe people don't like using Anarki for that purpose, either because they're worried about dirtying the codebase, or because they just don't like using git. In that case, maybe we should make a server for arc hacks? Like an HN style arc-app that allows submission of code and comments, but with a search engine and an API for pulling code remotely. Thoughts? Maybe this should me moved to another thread.

-----

1 point by evanrmurphy 5133 days ago | link

> maybe we should make a server for arc hacks? Like an HN style arc-app that allows submission of code and comments, but with a search engine and an API for pulling code remotely. Thoughts? Maybe this should me moved to another thread.

Maybe aw's idea for a new code site could fill this role. Have you seen that recent thread? -> http://arclanguage.org/item?id=12920

-----

1 point by shader 5133 days ago | link

Possibly. At the time I wrote that I hadn't seen that yet, though I had seen previous ideas about an example system, etc.

Certainly, the ideas are related. I suppose any discussion should be on the other thread ;)

-----

1 point by garply 5137 days ago | link

I've got an identical "rand-pos" in my code. Any opinions on which is more correct? I never know when to hyphenate.

-----

1 point by akkartik 5137 days ago | link

I think that's up to our discretion. I don't have a hyphen because it seems like a frequent token in readwarp.

-----