Arc Forumnew | comments | leaders | submitlogin
Chalk one up for Arc
15 points by kennytilton 6012 days ago | 24 comments
The infection took: I am starting to pile up a nice little set of superabbreviating macros for my Common Lisp programming. :)


12 points by pg 6010 days ago | link

That happened to me early on, because earlier versions of Arc were written in CL. Within a month or so I found some CL operators intolerably verbose. And yet I'd been using CL for 15 years and had never had a problem with them. That was an interesting data point about how much one gets used to the language one uses. So much so that external constraints (e.g. counting tokens) are needed to force one to come up with ideas for improvements.

-----

3 points by kennytilton 6010 days ago | link

One funny thing is that I was not even used to one thing: a let just to bind one local at the head of a function really bugged me, so I would use &aux to avoid it.

But yeah, just a few weeks of arccing and I realized I was hitting myself in the head with a hammer and decided to stop, or rather, how much surprisingly nicer it was to just superabbreviate and de-parens the obvious.

Of course I try not to use LET (I think there is a tax on it) but I was doing a DSL which was always starting by picking a random entity that then got re=used a few times, so I was in Letville unless I wanted to go nuts and code-walk in my DSL.

-----

2 points by almkglor 6010 days ago | link

> a let just to bind one local at the head of a function really bugged me, so I would use &aux to avoid it.

> Of course I try not to use LET (I think there is a tax on it)

In Cadence Skill, the lisplike we use in the office, 'let does have a tax to it when using lexical bindings; environments were pretty hefty objects and using 'let in a loop would generate a lot of them as garbage (the language implementation doesn't even have tail call opts!). I ended up using @optional (approximately equal to &optional) for some variables in time-constrained code, which helped reduce environments.

-----

8 points by jmatt 6009 days ago | link

I agree whole heartedly with this. I have begun abbreviating too.

I think arc like macros should go in Anarki. What does everyone else think? I like seeing everything arc in one place - even if it is CL or Scheme macros.

That being said it sucks that the arc community uses Anarki while pg doesn't. Or at least he doesn't contribute regularly. I think there is plenty of room for a more cohesive community.

-----

5 points by almkglor 6009 days ago | link

> That being said it sucks that the arc community uses Anarki while pg doesn't. Or at least he doesn't contribute regularly. I think there is plenty of room for a more cohesive community.

Second that!

-----

5 points by stefano 6008 days ago | link

Cohesion is the real big problem of the Lisp community in general, and it should be addressed by Arc. In this respect I think that Anarki is what the official version of Arc should look like: one place were everyone can contribute.

-----

3 points by almkglor 6008 days ago | link

LOL. Let us therefore officially decree that Anarki is the official Arc. ^^

-----

3 points by stefano 6008 days ago | link

That's right! :)

-----

3 points by almkglor 6007 days ago | link

LOL. And therefore ArcN is the Decreed Unofficial Canonical Arc.

-----

5 points by pgwoden 6009 days ago | link

Would you care to share your macros?

I'm a noob with respect to both CL and Arc. For a long time I've wanted to familiarize myself with Lisp. My need for speed (driven by lots of number crunching) pushes me toward CL, but the fact that I'm only an occasional programmer makes CL's historical baggage painful (gotta remember that that the non-consing version of APPEND is not NAPPEND but NCONC, for example [and I don't want to touch of a flame war on this point, please {I've done so by accident in the past}: I can fully appreciate that if you program in CL every day, all of these little quirks cease to be difficulties and may even seem charming, just as do the inconsistencies of spelling in English]). I have high hopes for Arc, but I need more hand-holding (e.g., comprehensive texts) than it can provide right now, and I'm too squeamish to be programming at the frontier.

Macros making CL more Arc-like would be great.

-----

8 points by almkglor 6009 days ago | link

> gotta remember that that the non-consing version of APPEND is not NAPPEND but NCONC, for example

Ah, consistency: yet another thing lacking in Arc. Take 'afn and 'acons, for example. Or 'acons and 'number. Or 'number and 'string. Or 'string and 'sym...

-----

7 points by listic 6009 days ago | link

I hope this will get sorted out in the next 100 years.

-----

2 points by kennytilton 6008 days ago | link

(w (v (rv))

w is my let but I still want a pair of parens.

(rv) generates a random algebraic variable. I am writing an algebra tutorial in CL and this code is from my DSL for the bit where I randomly generate algebra problems. (rv 2) would return a list of two variables one would reasonably find in a typical text. ie, x and y or m and n, but not x and a.

      (dsb (a b c) (shuffle (cons 1
                      (random-primes 2 2 10)))
dsb is destructuring-bind. I did not use random-primes very oftwn so no abbrev. yet. :)

        (dsb (x y z) (rpu 3 (r+ 5))
(rp n form) expands into a loop expression that repeats that many times collecting the result of the form shown. rpu is the version that ensures no duplicates (u for unique). (r+ n) generates a random number from 1 to n inclusive.

          (m+- (m+- (ms* a (ms^ v x))
(m+- x y) generates either a mathematical expression tree my software will use for tutoring, randomly x+y or x-y

ms* generates a product as does m, but is smart about it and tosses a factor of 1. likewise ms^ returns a power but not if the exponent is 1, then just the variable. mss^ is supersmart and converts x^0 to 1.

                 (ms* b (ms^ (xqv v) y)))
xqv is short for mx-equiv, which copies a mathematical expression to get an equivalent expression. (mx-copy creates a Lisp copy that is "EQ" the original at the application's level of abstraction.

            (ms* c (ms^ (xqv v) z))))))
Hmmm. This is a problem in factoring out the gcf of three terms ax^i + bx^j +cx^k.

Note that the above is as much about DSLs as it is about abbreviation, and I think if I wanted to delay shipping even further <g> I would break down and do a full parser of something like "ax^i + bx^j +cx^k,(abc)=[1 5],....".

-----

2 points by vsingh 6011 days ago | link

Ha! That's fantastic. Nice to see you're still around here, too. I've been taking a break from Arc for a while (job search, recently completed). I'm still working on something related to our little LOOP tiff a while back. Just you wait, it's gonna be great! :)

-----

1 point by Johnny_65701 6009 days ago | link

Ha! I did the same thing! There are a bunch of funcs & macros in "On Lisp" that are helpful (like "abbrevs" to abbreviate unbearably long names, and "group" to help write macros to eliminate logically unnecessary parens). All said and done, the verbosity of CL is not that big a problem when you can fix it with 1/2 page of macros.

-----

2 points by Johnny_65701 6007 days ago | link

I also took it one step farther; hygenic macros. I wrote a macro called hyg that expands into a defmacro that uses let and gensym to avoid capture of all the symbols that are supposed to be hygienic. (Basically it automatically implements the solution in On Lisp for you). the syntax is

(hyg name (x) `(a b c) `(do-something-with ,x a b c)) where name is the name of the macro, x is the argument to the macro, a,b,c are the hygienic symbols, and the rest is the body of the macro. If anybody wants to play with it, I'll post it.

-----

1 point by stefano 6007 days ago | link

Could you push it on Anarki?

-----

2 points by Johnny_65701 6006 days ago | link

It's for Common Lisp, not Arc, but if you want to play with it, send me an e-mail: jjuniman at ll dot mit dot edu. I tried to post it but the formatting got all mangled up and it became unreadable. It's not a lot of code, only a dozen lines or so.

-----

2 points by absz 6006 days ago | link

To post code that looks like code, surround it by blank lines and indent each line with two spaces—that should allow the code to display in a sane manner.

  (When you do that,
   it comes out like this.)

-----

2 points by Johnny_65701 6006 days ago | link

I did that and the ends of the lines got all mutilated. Dunno why, I'm copying & pasting from emacs, I'm not doing anything exotic.

-----

2 points by absz 6006 days ago | link

Are you on Windows/editing files created there? If so, is it possible that Windows's "\r\n" line endings are being pasted in literally?

-----

3 points by Johnny_65701 6005 days ago | link

Nope, Linux. But let me try again, since I have a different macro now that's considerably simpler, so the loss of newlines isn't as bad.

The original one I wrote wasn't working quite right. Then I found something in On Lisp, a macro called with-gensyms that I renamed with-hygeine due to a symbol conflict with something in Clisp:

  (defmacro with-hygiene (syms &body body)
   `(let ,(mapcar #'(lambda (s)
                    `(,s (gensym)))
                syms)
    ,@body))
You're supposed to use it like this:

  (defmacro my-stupid-macro (x y z)
    (with-hygeine (a b c)
      `(do-something-with ,x ,y ,z ,a ,b ,c)))
This gets me most of the way there, but what I really want is this:

  (hyg my-stupid-macro (x y z) (a b c)
    `(do-something-with ,x ,y ,z ,a ,b ,c))
We can achieve that like this:

  (defmacro hyg (name args syms &body body)
    `(defmacro ,name ,args
       (with-hygiene ,syms ,@body)))
Now I can do this:

  (hyg swap (a b) (temp) 
    `(progn 
      (setf ,temp ,a) 
      (setf ,a ,b) 
      (setf ,b ,temp)))
Which expands to:

  (DEFMACRO SWAP (A B) 
    (WITH-HYGIENE (TEMP) 
     `(PROGN 
        (SETF ,TEMP ,A) 
        (SETF ,A ,B) 
        (SETF ,B ,TEMP))))
which expands to:

  (PROGN 
    (SETF #:G3089 A) 
     (SETF A B) 
     (SETF B #:G3089))
PS: I'm a Lisp noob, so apologies in advance if something about this is a little naive, or contains a major oversight.

-----

2 points by absz 6005 days ago | link

Are you sure that you're indenting the lines with two extra spaces each (even the first)? That might fix the formatting.

-----

2 points by Johnny_65701 6005 days ago | link

Ooops, you are correct, sir. I indented all the lines except the first. Indenting the first line fixed the formatting (I went back & edited it)

-----