Arc Forumnew | comments | leaders | submit | conanite's commentslogin
2 points by conanite 6042 days ago | link | parent | on: Anonymous macros

It would be interesting to see an example of how you would use this.

One difficulty is that the only macros used to expand a given expression are the macros that are already known at read-time for that expression. Are you thinking of a shortcut to macex, to expand expressions at runtime?

-----

2 points by shader 6042 days ago | link

> Are you thinking of a shortcut to macex, to expand expressions at runtime?

I guess so. I don't really know what I'm thinking, to be honest. I think that anon. macros would be useful in cases where you want a little bit of syntax modification, but not make a whole macro out of a function.

For instance, I have found it difficult to make a set of functions taking rest parms built on top of a base function that also takes rest parm. In order not to get the extra layer of cons around it, I end up having to make a macro for calling that base function, to splice the arguments into the list. Maybe I'm doing it wrong, and there's a better way, but it seems like it might be an application for a short anon. macro.

-----

3 points by cchooper 6040 days ago | link

Can't you just use apply?

-----

2 points by shader 6040 days ago | link

I think apply only works as long as there are no other arguments besides the rest arg. Otherwise you need to use macro with ,@. I think.

-----

2 points by absz 6040 days ago | link

That's not the case; apply doesn't care how many arguments the function takes. Take map (which takes a mandatory argument and a rest parameter) and map1 (which takes two mandatory arguments):

  arc> (help map)
  (from "arc.arc")
  [fn]  (map f . seqs)
   Applies the elements of the sequences to the given function.
      Returns a sequence containing the results of the function.
      See also [[each]] [[mapeach]] [[map1]] [[mappend]] [[andmap]]
      [[ormap]] [[reduce]] 
  arc> (map list '(1 2 3) '(4 5 6))
  ((1 4) (2 5) (3 6))
  arc> (apply map list '((1 2 3) (4 5 6)))
  ((1 4) (2 5) (3 6))
  arc> (apply map (list list '(1 2 3) '(4 5 6)))
  ((1 4) (2 5) (3 6))
  
  arc> (help map1)
  (from "arc.arc")
  [fn]  (map1 f xs)
   Return a sequence with function f applied to every element in sequence xs.
      See also [[map]] [[each]] [[mappend]] [[andmap]] [[ormap]] 
  arc> (map1 [* 2 _] '(1 2 3))
  (2 4 6)
  arc> (apply map1 (list [* 2 _] '(1 2 3)))
  (2 4 6)
As long as the last argument to apply is a list, you're golden.

-----

2 points by shader 6040 days ago | link

Interesting. I was wondering if that might be the case.

So I guess that we don't need an anon. macro for that ;)

I'm also wondering whether we would ever actually want an anonymous macro, since often they turn out to be so general purpose that you might want to make a utility out of it.

Does arc have symbol macros?

-----

4 points by absz 6040 days ago | link

I'm not really clear on what an anonymous macro would do. Transform code? If we're writing it in one place, we can just transform it right there. Can you give a usage example?

And no, Arc only has ordinary macros and ssyntax. Though actually---and this just occurred to me now---you can use ssyntax to create symbol macros. For instance, I have the following in a library file

  (= mac-seval $)
  
  (add-ssyntax-bottom
    @    (par apply R)
    $    (fn lists (apply map R lists))
    @    apply
    $    mac-seval)
The first two let me write (@func arg1 restargs) instead of (apply func arg1 restargs) and ($func xs) instead of (map xs). However, this $ makes the $ macro misbehave, and so I added ssyntax turning @ into apply and $ into the original $ macro. It turns out that this technique is fully generic, since ssyntax essentially does a find-and-replace on symbols:

  arc> (= defsym add-ssyntax-top)
  #3(tagged mac #<procedure>)
  arc> (defsym RANDOM (rand))
  t
  arc> RANDOM
  0.5548165450808223
  arc> RANDOM
  0.15745063842035198
  arc> (= things '(alpha beta gamma))
  (alpha beta gamma)
  arc> (defsym THING1 (car things))
  t
  arc> THING1
  alpha
  arc> (= THING1 'one)
  one
  arc> things
  (one beta gamma)
  arc> (defsym NOISY (do (prn 'HI) nil))
  t
  arc> NOISY
  HI
  nil
  arc> (car NOISY)
  HI
  nil

This is actually really nifty, even if it's an unintended side effect. On some level, though, I'm not fully convinced of the value of this---it seems a bit omnipresent. Then again, Common Lisp works fine with them, so perhaps they're fine for Arc too. Are there naming conventions for symbol macros in Common Lisp? I used capital letters above just because I wanted some distinguishing mark.

There are a couple of caveats: first, every time you run add-ssyntax-top, you'll add another entry to the ssyntax table instead of overwriting the old one, so redefinition will make ssyntax slower if it's done too much. Second, the five tokens R, r, L, l, and ... are all unavailable, even if quoted; they turn the given string into modifying ssyntax, not standalone ssyntax. Still, this is a new option I hadn't thought about yet.

-----

3 points by conanite 6060 days ago | link | parent | on: Curl in arc

there's stefano's http-get library in anarki, see http://arclanguage.org/item?id=8451

-----

1 point by shader 6060 days ago | link

Thanks.

Do we have any documentation for the various libs included in anarki? Or at least a list of what's available?

What use is a library if I can't find it, and can't use it once I do? ;)

-----

1 point by shader 6059 days ago | link

How would you add support for cookies to http-get?

-----

2 points by conanite 6061 days ago | link | parent | on: Arc presentation

Totally. "Embrace Change" was the mantra of the first book on XP. And to paraphrase "maximizing the amount of work not done" (thanks, CatDancer, for the link) we could say "maximizing the number of lines not written".

The usual techniques for enabling change involve exhaustive tests as well as not implementing stuff that might be unrequired. And DSLs. Hence Ruby gets a lot of attention because it's so easy to build a quick DSL in it. But as you've mentioned elsewhere, a layer of lisp macros in a program is effectively the DSL for that system.

Possibly the advantage of lisp in the context of DSLs is that the use of macros is thoroughly studied, and in a mature lisp the usual editing, debugging and optimization tools are available, whereas a home-made DSL might create as many problems as it solves ( ad-hoc, informally specified, bug-ridden, etc ).

-----

4 points by conanite 6064 days ago | link | parent | on: Arc presentation

True, [_] is one of those radical shortcuts that improves readability rather than obfuscates. Thank you.

As for up-arrow, I get "^[[A", so I haven't enjoyed the REPL as much as I ought to. I'm on a mac. Does anyone know a way to fix this?

-----

5 points by absz 6064 days ago | link

I'm on a Mac too; the trick is that you need mzscheme's readline library. In your ~/.arcshrc, put the line

  ($ (dynamic-require '(lib "rep.ss" "readline") (zero? 1)))
, and then you should have no problem.

(As a side note, you need to use (zero? 1) instead of #f because Arc turns #f into nil.)

-----

1 point by conanite 6064 days ago | link | parent | on: Arc presentation

This is interesting, I had been thinking only of how the core language might appeal to an agile mindset but it's true that the libraries have a lot to offer as well.

-----

2 points by conanite 6064 days ago | link | parent | on: Arc presentation

Thanks, this is an awesome presentation. I will definitely be stealing liberally from it if I do this.

(btw I uploaded back into google, I don't have ppt installed, it looks fine)

-----

2 points by conanite 6064 days ago | link | parent | on: Call graph for news.arc [pdf]

I second that.

If you're planning to add dynamic information and looking for ideas, encoding profiling data in the graph could be über cool.

Anarki has a basic profiler - see http://arclanguage.org/item?id=5318

-----

1 point by chris_l 6064 days ago | link

Thanks for the hint, I've now got a simple version where it takes the who-called-who from recording invocations. I'm currently working on sample call data, but profiling would also be interesting.

-----


  $ mzscheme -m -f as.scm
  arc> (nsv)
Now, theoretically, you're serving a news forum at http://localhost:8080

Hosting arc has been discussed several times, most recently at http://arclanguage.org/item?id=8830

-----

7 points by conanite 6072 days ago | link | parent | on: Happy birthday, Arc

It's a beautiful cake. But doesn't it have too many candles?

-----

5 points by conanite 6072 days ago | link | parent | on: Happy birthday, Arc

It's a year since the first public release of arc ... may the second year prove even more eventful than the first !

-----

More