Arc Forumnew | comments | leaders | submit | mec's commentslogin
1 point by mec 6327 days ago | link | parent | on: Confusing Macro Error

Thanks! That fix also allowed me to get (_ . __) to work for [] as well which was giving the same error. Now, time to play around with multivar anonymous functions.\

Edit: Well never mind then, that change doesn't work in brackets.scm either so back to just playing with the macro.

-----

2 points by mec 6328 days ago | link | parent | on: Possible bug in using + for lists

I believe that '() is nil and works correctly in your example, but I'm not entirely sure what the difference is between the two.

-----

3 points by mec 6330 days ago | link | parent | on: Multi-var function literal shorthand

What about having [...] expand to (fn (_ . __) ...) so that it would still keep its simplicity and be identical when only passing one argument, but when adding multiple arguments you can access them through __.

-----

2 points by mec 6334 days ago | link | parent | on: New version

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 6334 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 6334 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 6334 days ago | link

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

  > (cut "abcde" 1)
  "bcde"

-----

3 points by tokipin 6334 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 6334 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 6334 days ago | link

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

-----

1 point by mec 6335 days ago | link | parent | on: Stupid noob question

Side question here, is there a keybinding anywhere in DrScheme to close all open parentheses? It's driving me crazy trying to find it.

-----

1 point by danielprager 6334 days ago | link

Dunno, but the '[' and ']' keys in DrScheme are clever enough to give you '(' and ')' when you need them (and '[' and ']' at other times).

Since discovering this I just keep tapping ']' until the highlighting tells me I'm done.

-----

2 points by mec 6335 days ago | link | parent | on: Stupid noob question

Thanks for asking the newb question, I've been trying to figure it out too and just gave up and been using (fst . rest).

-----

2 points by mec 6338 days ago | link | parent | on: Multi-var function literal shorthand

After thinking about it for a while this seems like the best approach. I really liked the suggestion to use '*' for the list but '__' seems the most natural after that.

-----

1 point by mec 6339 days ago | link | parent | on: Poll: What would you change in Arc?

I love python's 2 window environment but the functionality I'd like even more (and please point me to it if it already exists) would be the ability to dump the current REPL log to a file so that I could tinker completely in the REPL without constantly having to copy/paste to/from another file.

-----


Why not return the reverse when going backwards within bounds?

    >>> s="aoeui"
    >>> s[3:1]
    "eoa"
    >>> s[4:-3]
    "ue"
    >>> s[9:-20]
    ''
    >>> s[0:-0]
    'a'
    >>> s[12:42]
    ''

-----

2 points by sjs 6346 days ago | link

That is too magic for my taste. [0:-0] returning the first char is madness. That should be '' no matter what, as 0 == -0 on modern cpus (thankfully).

-----