Arc Forumnew | comments | leaders | submit | akkartik's commentslogin
1 point by akkartik 4791 days ago | link | parent | on: How do you http redirect in Arc?

I wasn't aware of aformh before, but yes it's not supposed to redirect. But arformh is.

-----

1 point by akkartik 4791 days ago | link | parent | on: How do you http redirect in Arc?

[ ... ] expands to (fn(_) (...))

So [ "foo" ] expands to (fn(_) ("foo")), which fails because you're trying to call a string like a function.

Just use (fn() "foo").

-----

1 point by lark 4790 days ago | link

It might be better if [ "foo" ] expanded to:

  (fn(_) (do "foo"))
rather than

  (fn(_) ("foo"))

EDIT: On second thought, I doubt that's what [ "foo" ] expands to:

[ ... ] expands to (fn(_) (...))

Because you can already write aform submission code that looks like:

  (defop said req
    (aform [ (pr "You entered " (arg _ "foo"))]
      (input "foo") 
     (submit)))
If that's what [ ... ] expands to, aform wouldn't even work so far because it would be trying to call:

  (fn (_) ((pr "You entered.")))
That would be a function call to a function call: (( on the call to pr.

-----

1 point by akkartik 4790 days ago | link

I just ran the following at the repl:

  arc> ([(prn "You entered " _)] 34)
  You entered 34
  Error: "...urces/arc/ac.scm:974:33: arity mismatch;\n the expected number of arguments does not match the given number\n  expected: 1\n  given: 0"
Do you see something different? I think your defop expression is also incorrect. It just happens to have the right side-effect before it runs into the error. You probably have errors at the server -- that aren't visible on the browser.

Edit: I kept having this feeling I'd already pointed this out to you -- and I just found it :) http://arclanguage.org/item?id=16356

-----

1 point by lark 4790 days ago | link

I see the following:

  arc> ([(prn "You entered " _)] 34)
  You entered 34
  Error: "car: expects argument of type <pair>; given ()"
That's good investigation. Note the work described in this thread uses Arc 3.1, not Anarki.

Btw do you mean there's something wrong with defop, or that the example I wrote is incorrect? I had gotten that example from: http://arcfn.com/doc/srv.html

-----

3 points by rocketnia 4790 days ago | link

The examples at arcfn say [do (prn ...) ...] and [w/link (pr ...) ...]. At some point you changed one of these to [ (prn ...)] for your example.

-----

1 point by lark 4789 days ago | link

Thanks. I understand one should write:

  [do (prn "...")]
I support one shouldn't. The do should be implicit.

-----

2 points by Pauan 4789 days ago | link

The reason it does that is so that things like [+ _ 1] work. Under your suggestion, you would have to write [(+ _ 1)] which looks ugly.

Rather than using [(prn ...)] you can just use [prn ...]

---

Incidentally, using Arc/Nu, it's easy to make the square brackets behave the way you want them to:

  (mac square-brackets args
    `(fn (_) (do ,@args)))
I believe Anarki has something similar as well.

-----


http://www.arclanguage.org/item?id=17479

Also check out http://arclanguage.org/item?id=4708 for making changes to a running server.

-----


Weird. Can you try running the main branch of anarki with just:

  $ racket -f as.scm
? We're trying to move away from legacy mzscheme. Let us know if the error persists.

In general, the instructions we've been steering newcomers toward are at https://sites.google.com/site/arclanguagewiki/getting-starte..., which we try to keep up-to-date. If that helps in this case.

(Once you resolve this issue I'd also recommend switching to the Nu branch described in the above link. It's a much more clean and modern implementation.)

-----

2 points by Pauan 4792 days ago | link

When akkartik said "the Nu branch", he meant this:

https://github.com/Pauan/ar

I too recommend using it rather than vanilla Arc. It has many bug fixes and new features, yet is still backwards compatible.

-----

1 point by geoengineering 4792 days ago | link

will do

-----

2 points by geoengineering 4792 days ago | link

racket -f as.scm works! moving forward ...

-----

3 points by akkartik 4793 days ago | link | parent | on: Google Analytics inside news?

Look for votejs* in news.arc, how it's defined and where it's used. You can insert arbitrary javascript by similar means, including the analytics code.

Does that make sense?

-----

3 points by thaddeus 4793 days ago | link

Note though, while votejs* may be appropriately placed in the page header section, my understanding is that you want your google analytics script tags to occur after your body section (or at the end of your body section) such that the page display doesn't have to needlessly wait.

-----

1 point by marcvs 4788 days ago | link

hey, it works! thank you.

-----

2 points by akkartik 4797 days ago | link | parent | on: How do you http redirect in Arc?

See defopr: https://github.com/nex3/arc/blob/2762cc15fe/lib/srv.arc#L203

You could also define the op for the first url to render a meta refresh tag: https://en.wikipedia.org/wiki/Meta_refresh#Examples

-----

1 point by lark 4796 days ago | link

Thanks, I'll try it.

How would you redirect when executing a closure created with w/link?

-----

2 points by akkartik 4796 days ago | link

There's actually something called w/rlink :)

You might find http://arcfn.com/doc/srv.html useful.

-----

3 points by lark 4794 days ago | link

w/rlink was what I was looking for. Thank you!

-----


"I wonder how the pursuit of this feature could impact the design of a language's macro system."

Whoa, how do you mean?

One idea I've been thinking about a lot is to attach metadata to code. We can do a lot to code (pretty-print, optimize, ...) besides just eval it, and metadata might help with those without affecting eval.

My favorite use for this idea is to give functions levels:

  def (foo x y) :(level 3)
    34
(This is the 'other idea' for colons I referred to at http://www.arclanguage.org/item?id=17358, but I suck at surprises ^_^)

This can be used in a variety of ways by different tools. You could flag as errors any calls from a lower to a higher level, so that level 3 functions could only call functions in levels 1-3. You could tell tracers to trace everything until level x, not below. You could tell debuggers to automatically step past calls below level x and step _into_ calls above that level. In gdb I often accidentally hit 'next' when I meant 'step', and now I have to restart and laboriously try again from scratch.

You could syntax-highlight calls within a level to be more salient to calls to lower levels. We've all seen open source projects with this structure.

  void main() {into 
    ...  // lots of option parsing crap
    if (doSomething()) { // the actual app code
       ... // more crap
    }
    ... // more crap
    return -1;
  }
Here wouldn't it be cool to be able to highlight the doSomething() compared to all the other calls?

In general, syntax highlighting sucks[1] because we simply highlight the things it's easiest to infer. Metadata might help reduce the inference burden and open up new uses for color.

[1] http://arclanguage.org/item?id=16488

-----

3 points by rocketnia 4797 days ago | link

"Whoa, how do you mean?"

If we syntax-highlight (withs ...) this way, since it expands into several (fn ...) forms it'll give a different color to each of its variables. But that's assuming we're able to perform some amount of macroexpansion frequently enough to be useful as the programmer edits, and it also assumes we can relate the original syntax to the transformed version returned by the macro.

It would be interesting to see a macro system tailor-made for purposes like these. Some hygienic macro systems might already apply, but I wonder what the options are here. I think Reactive Demand Programming would be an effective ingredient for this kind of incremental program visualization, but that's not a complete plan on its own.

-----

2 points by Pauan 4796 days ago | link

Fun fact: if you used boxes, it would be really easy to associate the "withs" form with its expanded form, since the boxes would be the same.

The Nulan IDE already incrementally macroexpands as you're typing, and syntax-highlights boxes different colors depending on their scope. So this would be fairly trivial to add in.

-----


Thanks a lot!

-----


Yeah that seems plausible. I guess I don't understand what you're asking.

Perhaps it'll help to tell us more about what you're building and what you're trying to do and why.

-----

1 point by akkartik 4812 days ago | link | parent | on: Generalizing iflet

After playing with it some more, I'm finding that this actually works better in arc than in wart. In wart perhaps I should require parenthesizing it differently:

  (iflet x ((...) :satisfies f)
             'branch1)
Otherwise it interacts poorly with paren-insertion. Things like this with multiple branches:

  iflet x 2+3 :satisfies even?
            x+1
          3+4 :satisfies even?
            x+2
=> (iflet x 2+3 :satisfies even? x+1 (3+4 :satisfies even?) x+2)

Need wrapping in parens lest the inner test get wrapped in parens:

  (iflet x 2+3 :satisfies even?
             x+1
           3+4 :satisfies even?
             x+2)
Hmm, unhappy with my choices here.

-----

More