Arc Forumnew | comments | leaders | submit | nex3's commentslogin
5 points by nex3 6648 days ago | link | parent | on: New version

"End of string" is specified by not passing a fourth parameter:

  > (cut "abcde" 1)
  "bcde"
See http://arclanguage.org/item?id=2267.

-----

1 point by nex3 6648 days ago | link | parent | on: Cut and Index - Arc and Ruby Side By Side

It seems a little weird that the second parameter switches meaning from "end" to "length" if the first parameter is negative, but I suppose it's more useful than the alternative...

-----

3 points by mdemare 6648 days ago | link

No, it's another function. cutl instead of cut.

-----

1 point by nex3 6648 days ago | link

Gotta stop trying to read code at four in the morning...

-----


But what if he wants to conserve the lone ? as well?

-----

1 point by shiro 6648 days ago | link

Well we can only speculate. He said he wants to reserve '?' for ssyntax, and I pointed out '?' in ssyntax and lone '?' can coexist. If he also reserve lone '?', that's his decision.

-----

3 points by nex3 6648 days ago | link | parent | on: Cut and Index - Arc and Ruby Side By Side

Your "items from position 1 to the end minus the last 2 items" can actually be achieved in a nicer manner in Arc:

  (cut s 1 -2)
(Note that that's using the Anarki negative-end semantics, which PG has said are better; in arc1.tar, that would be (cut s 1 -3). See http://arclanguage.org/item?id=2225)

-----

1 point by mdemare 6648 days ago | link

Good point, I've changed it, but am still using arc1 as reference.

-----

2 points by nex3 6648 days ago | link | parent | on: New version

Agreed. On a related note, I also wish the first parameter could be negative as well.

-----

4 points by nex3 6648 days ago | link | parent | on: New version

Given this, I've changed it to 0-based reverse indexing in the Anarki.

-----

1 point by nex3 6648 days ago | link | parent | on: Ruby-like in place list expansion

Perhaps... one in forty-two?

-----

2 points by nex3 6648 days ago | link | parent | on: Ask PG: Intrasymbol Syntax

I think PG has said before that he'd like to allow prefix, infix, and postfix operators to be programmable by the user. So I'd guess that, yes, there are such plans.

-----

2 points by nex3 6648 days ago | link | parent | on: New version

Agreed. Ruby does it the other way ("abcde"[1..-1] is "bcd"), but that's only because there's no other way to specify "until the end." But that's the default in Arc; the following are equivalent right now:

  (cut "abcde" 1 -1)
  (cut "abcde" 1)

-----

3 points by lsb 6648 days ago | link

Nope, Ruby has -1 at the end:

    $ irb
    >> "abcde"[1..-1]
    => "bcde"
    >>

-----

4 points by nex3 6648 days ago | link

Oh, right. That's what I meant.

So, to clarify: I think arc should not do it Ruby-style, but rather have

  arc> (cut "abcde" 1 -1)
  "bcd"

-----

2 points by mec 6648 days ago | link

How would you then decide 0 0?

  arc> (cut "abcde" 0 0)
  "a"
  arc> (cut "abcde" 0 0)
  "abcde"
-1 should deffinitly refer to the last elemental or I don't see a way to get it.

-----

3 points by nex3 6648 days ago | link

(cut s 0 0) should return the empty string, just like (cut s 1 1) and (cut s 42 42). Which it does in either implementation.

-----

2 points by vincenz 6648 days ago | link

Then you would need -0 to get the full string. You're not making sense.

How do you propose to get "bcde" from "abcde"?

Either you need -0, or your final 0 is ambiguous.

-----

3 points by nex3 6648 days ago | link

No you don't - the full string is the default.

  > (cut "abcde" 1)
  "bcde"

-----

3 points by tokipin 6648 days ago | link

i was thinking that too, but how would you do it dynamically (eg with variables) ?

  (cut "abcde" begin end)
what would i need to put in end to get the full string? nil?

-----

3 points by sjs 6648 days ago | link

Both nil and (len str) work. I see both sides of the argument as counting from -1 eliminates the 0 corner case.

I like indices that are intuitive with literal numbers. Counting from 0 at one end and from 1 at the other is jarring. When -1 points to the end of string rather than before the last char (cut str 0 (- (len str))) returns the first char instead of the empty string.

With -1 -> before last char:

  (def chop ((o str "abcdef"))
    (pr "Chop how many chars off the end of \"" str "\"? ")
    (= n (coerce (cut (readline) 1) 'int)) ; bug in readline prepends #\newline
    (prn "Chopped: \"" (if (is n 0) str (cut str 0 (- n))) "\"")) ; handle corner case
With -1 -> end of string:

  (def chop ((o str "abcdef"))
    (pr "Chop how many chars off the end of \"" str "\"? ")
    (= n (coerce (cut (readline) 1) 'int)) ; bug in readline prepends #\newline
    (prn "Chopped: \"" (cut str 0 (- -1 n)) "\"")) ; no corner case, but there's this -1 there
I probably made a stronger argument for -1 pointing to the end of string as it leads to shorter code.

-----

2 points by nex3 6648 days ago | link

If you absolutely need to do that, you can just use (len str).

-----

3 points by akkartik 6648 days ago | link

Yup. Which is how python does it.

-----

2 points by jules 6648 days ago | link

    $ irb
    >> "abcde"[1...-1]
    => "bcd"

-----

8 points by nex3 6649 days ago | link | parent | on: New version

I've added this as branch "official" of the arc wiki. I've also tried to merge it into the master branch. I resolved everything I knew how, but there might be some regressions and references to renamed/no-longer-existent functions hanging around.

-----

6 points by ryantmulligan 6648 days ago | link

it would be nice if we made specs to test the language, a la Rubinius, while the language is still small. Then, we could say with greater confidence of the merge.

-----

More