Arc Forumnew | comments | leaders | submitlogin
Bug in cut
3 points by lark 3594 days ago | 11 comments
There's a bug in the cut function in arc.arc. end (64) should be higher than start (128) but if it's not cut breaks.

  (cut "test" 128 64)
  Error: "make-string: contract violation\n  expected: exact-nonnegative-integer?\n  given: -64"
The strange thing is I got this bug trying to visit a url served by Arc.

Is this a known issue in Anarki?

For whatever it's worth this bug is fixed if you force start to be equal to end when start is higher than end:

  ;; fix bug in cut
  (def cut (seq start (o end))
    (let end (if (no end)   (len seq)
                 (< end 0)  (+ (len seq) end) 
                          end)
      (if (> start end)  ;; the bug fix
	  (= end start))
      (if (isa seq 'string)
          (let s2 (newstring (- end start))
            (for i 0 (- end start 1)
              (= (s2 i) (seq (+ start i))))
            s2)
          (firstn (- end start) (nthcdr start seq)))))


3 points by rocketnia 3594 days ago | link

When you got the error in the Arc server, what was cut's caller? Maybe it's buggy in its own right, and fixing it might make this change irrelevant.

I've seen cut-like behavior that uses out-of-order endpoints to reverse the list. Groovy does this for instance:

  >>> ​[ 1, 3, 5, 7, 9 ][ 3..1 ]​
  [7, 5, 3]
(http://groovyconsole.appspot.com/)

If we want this kind of behavior for Arc's 'cut (and I'm not saying we do), then your change is inconsistent with it.

-----

3 points by lark 3594 days ago | link

I'm unable to reproduce it now. I disabled the bug fix, and I believe I am now running the same code as I did when the bug occurred, but I no longer get this exception when I visit that url (it's an ordinary GET request without parameters). The state of the app has also changed and I wonder if this state change has something to do with it.

What's certain is that it's a call that passes 3 arguments to cut. I had logged the exact call to cut to be:

  (cut "U2FsdGVkX19jl4f9tgc8cwsQso1Q1HMYtqzp4HAQO+3fL9LTcN5X7UEZTaz7V+F2" 128 64)
It might be one of:

  app.arc:markdown
  app.arc:unmarkdown
It can't be arc.arc:split because either the first parameter is a hardcoded 0 or the call takes only 2 parameters.

It can't be arc.arc:ellipsize because the call uses a hardcoded 0.

It can't be app.arc:shash because the second parameter there is a hardcoded 0.

It can't be app.arc:urldecode because the 2nd and 3rd parameters there should differ by 2 and they instead differed by -192 (did I get this right?)

It can't be strings.arc:lines because calling (lines "U2FsdGVkX19jl4f9tgc8cwsQso1Q1HMYtqzp4HAQO+3fL9LTcN5X7UEZTaz7V+F2") doesn't cause this error.

It probably isn't strings.arc:trim because calling (trim "U2FsdGVkX19jl4f9tgc8cwsQso1Q1HMYtqzp4HAQO+3fL9LTcN5X7UEZTaz7V+F") doesn't trigger it either.

It can't be app.arc:paras because I'm not using paras anywhere.

It can't be strings.arc:slices because I'm not using slices anywhere.

It can't be html.arc:hex>color because the values there are hardcoded.

It can't be html.arc:shortlink because it uses only 2 parameters.

-----

2 points by akkartik 3589 days ago | link

Yeah, none of those call sites seem responsible, as far as I can see. The calls in markdown and unmarkdown only trigger if the string starts with certain chars, which it doesn't. Remind me, are you using anarki?

-----

2 points by lark 3585 days ago | link

I'm using Arc 3.1.

I should have investigated this bug further when it happened.

-----

2 points by akkartik 3583 days ago | link

Ah, you're using arc 3.1 without the mutable-pair bugfix: http://arclanguage.org/item?id=18070. Anything can happen after a race condition. Hold on, let me patch that bug to the stable branch so you can pick it up.

Edit 1 hour later: Done, https://github.com/arclanguage/anarki/commit/b683a84a68. lark, can you start using this stable branch? Should be a lot less disruptive than migrating to anarki, and will also help us better help you.

-----

2 points by lark 3582 days ago | link

Thank you for tracking down and pointing out the mutable pairs issue.

I wish there was a version of Arc that made it clear what was changed in it, and made it easy to not apply some changes. A version that consisted only of:

- the original, untouched, Arc 3.1 -- however broken it might be.

- a single Arc file called fixes.arc that contains all fixes needed as redefinitions (say, the bugfix for cut). This is different than modifying the originals; you always know what was modified.

- a collection of .patch files, to patch what can't be provided in fixes.arc (like ac.scm)

- a script called arc.sh that (a) deletes all patched files, (b) creates new copies of the original files (untouched), (c) patches them, (d) starts Arc.

About the github commit link, I don't understand what's going on with it:

- I don't know what kind of branch this is -- is this Arc 3.1 or Anarki? I want to keep using Arc 3.1.

- If it's Arc 3.1 why is it named Anarki?

- Is there a way to get a diff? If not, how do I extract this branch and then get a diff (do I need a different link, and if so which one?) Is there a way to not use git?

(Couldn't this be easier? Why is there so much work involved? I think I want a new way to organize programs.)

-----

3 points by akkartik 3581 days ago | link

You know, you don't have to switch to the entire 'stable' branch. Just apply the patch linked to in my last comment. It doesn't rely on anything outside arc3.1.

Anarki has multiple branches: http://i.imgur.com/WefAVGX.png. Notice the branches 'official' and 'stable'. 'Official' is just the various releases of arc, and 'stable' is releases + small bugfixes. To see what's changed in 'stable' since arc3.1, look at the list of commits: https://github.com/arclanguage/anarki/commits/stable. There's only 15 commits or so on that page after the arc3.1 release, and you can click on them to see what was changed. Scanning the list, really there's no other important bugfixes.

I keep a directory called arc3.1 by doing:

  $ git clone http://github.com/arclanguage/anarki arc3.1
  $ cd arc3.1
  $ git branch -a  # list all branches
  $ git checkout stable
I can then see the same list of commits by typing 'git log'. Or generate diffs by typing:

  $ git diff remotes/origin/official
This is enough information for you to create and manage a repo just how you described. I have a slightly different itch, so I have a different approach: http://github.com/akkartik/arc. Back before me, a user called aw created a new approach as well: http://awwx.ws/hackinator, which I doubt is actively maintained. You should create one too and show us. If it's substantially better we'll switch to it. Over time.

I'm sure everything could be much better. (I'm trying to create a new way to organize programs, after all: http://akkartik.name/about.) But no matter how you organize programs, people would still need to know about some baseline tools, like diff and patch and scripts in your description above. For anarki you need to learn some git at the moment.

-----

2 points by rocketnia 3581 days ago | link

If you're going to resort to patches to manage code as text, that's what source control systems like Git are good for. They also manage the emergent complexities with this approach:

- They help highlight one version of the code as the canonical one that most people are expected to be using. That way development effort isn't wasted on out-of-date code combinations that nobody cares about.

- They provide ways to merge textual changes, revert them, and otherwise apply them out of order.

What you have in mind might be a coherent alternative to the existing version control systems, so I'm not just saying to give up. :)

---

"Is there a way to get a diff?"

Git makes it easy to create diffs (using the "git diff" command with various arguments), and GitHub makes it particularly easy to view certain kinds diffs on the Web. In GitHub, if you're on the stable branch and you click the "commits" button you get to this page:

https://github.com/arclanguage/anarki/commits/stable

Clicking each commit message will take you to a page that shows the diff for that commit. For instance, here's the mutable pair bug fix:

https://github.com/arclanguage/anarki/commit/b683a84a6831fd4...

Don't bother trying to copy and paste a diff from GitHub though. I think you'd have better luck at a command line, even if it means learning several commands. (I'm not sure I know all the right commands myself though. >.> )

---

"If it's Arc 3.1 why is it named Anarki?"

There are a lot of ways to answer that question. If someone wants to make a contribution to Arc so that every other Arc user can benefit, that's what Anarki is for. However, not everyone uses Anarki, so the fantasy is that it's Arc, but the reality is that it's a specific project that we refer to by a specific name.

I'm not actually sure why that branch of Anarki exists, but it looks like it was created to support plain Arc 3.1 coding without all the extensions people made to the master branch. Its differences mostly have to do with adding text editor extensions and shell commands to support Arc 3.1 programs.

-----

1 point by akkartik 3581 days ago | link

"Don't bother trying to copy and paste a diff from GitHub though. I think you'd have better luck at a command line, even if it means learning several commands. (I'm not sure I know all the right commands myself though. >.> )"

True. I coulda sworn github had a raw view. Was that just for snapshots?

-----

2 points by rocketnia 3581 days ago | link

They have a raw view for files, but I haven't seen one for diffs.

-----

2 points by akkartik 3581 days ago | link

Yeah. BTW, the command for viewing a commit is 'git show'. In this case:

  $ git show b683a84a68

-----