Arc Forumnew | comments | leaders | submit | sjs's commentslogin
2 points by sjs 6560 days ago | link | parent | on: Alphabetical List of Arc Functions

Very nice. Here's a list of just lib functions for those interested:

http://samhuri.net/arc-lib-fns.txt

-----

1 point by sjs 6561 days ago | link | parent | on: Ask Arc: What's the Arc symbol going to be?

Something clever involving parens and arches.

-----

1 point by sjs 6561 days ago | link | parent | on: Suggestion: partial application by default

I think this would be great, but it'll take some work. For example right now Arc compiles s-exps to mzscheme, so it would need to change mzscheme's semantics (not sure if this is even practical or possible). Arc most likely needs to stand on its own a little more before this will be feasible.

-----

1 point by sjs 6561 days ago | link | parent | on: Suggestion: partial application by default

Did you mean to write (def accgen (n) (par + n))?

-----

3 points by Zak 6561 days ago | link

I did not: an accumulator increments. See http://paulgraham.com/accgen.html

-----

2 points by sjs 6561 days ago | link | parent | on: Optional Parenthesis

I'm almost certain that Eli meant to write:

    def f (x y)
      let z (* x y)
        * (- z x) (- z y)

-----

1 point by EliAndrewC 6561 days ago | link

Exactly so, thank you. I've since Googled to find how to do code formatting, so I shouldn't have this problem in the future. Thanks for posting the correct code.

-----


"aoeui"[3:1] ??? "aoeui"[12:42] ?? "aoeui"[0:0]

With or without negative indices one can do pointless things with slicing/subseq. Returning an empty string/list is the only sane thing to do in those cases.

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

-----

1 point by mec 6561 days ago | link

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 6561 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).

-----

1 point by sjs 6562 days ago | link | parent | on: Arc, a Comedy of Errors: Part I

What's wrong with that?

    arc> (is () '())
    t
    arc> (cons 1 ())
    (1)
    arc> (cons 1 '())
    (1)

-----

2 points by sjs 6562 days ago | link | parent | on: Regular expressions

There are some funcs that may tide you over in the meantime, or at least give you a starting point to write replacements for regexes you need.

* whitec (test for a whitespace char)

* nonwhite (inverse of above)

* alphadig (test for alphanumeric chars)

* punc (true for any of [.,;:!?])

With the functions all and some, and a little subseq-fu you should be able to do what you want.

edit: Also look around the forum here for a patch to subseq to support negative indices for slicing off the end.

-----

3 points by sjs 6562 days ago | link | parent | on: Show us your Arc code

Standard stuff...

    (= sum [apply + _])
    (= prod [apply * _])
I went to create a range function, but it was already there. It's like python's range:

    arc> (range 37 42)
    (37 38 39 40 41 42)
There's also intersperse, familiar to Haskell coders, but only works on conses.

    arc> (intersperse 0 '(42 21 7 1))
    (42 0 21 0 7 0 1)
There is much more in arc.arc.

-----

3 points by fallintothis 6562 days ago | link

range is useful, though I kept making the goof-up of trying to pass only one arg as in Python. So, I went ahead and changed it:

  (let orig range
    (def range (x (o y))
      (if y
          (orig x y)
          (orig 0 x)))) ;could be (orig 0 (- x 1)) to be even more Python-like
Come to think of it, you could instead do something like this to be the most like Python (whether or not that's a good thing):

  (def range (start (o end) (o step 1))
    (let test (if (positive step) >= <=)
      (when (no end)
        (= end start 
           start 0))
      (if (test start end)
          nil
          (cons start (range (+ start step) end step)))))

  arc> (range 10)
  (0 1 2 3 4 5 6 7 8 9)
  arc> (range 10 1)
  nil
  arc> (range 1 10)
  (1 2 3 4 5 6 7 8 9)
  arc> (range 1 10 2)
  (1 3 5 7 9)
  arc> (range 1 10 -2)
  nil
  arc> (range 10 1 -2)
  (10 8 6 4 2)
  arc> (range 10 1 -1)
  (10 9 8 7 6 5 4 3 2)
This same idea of having the "step" parameter maps nicely into subseq syntax in Python, as I noted in this thread: http://www.arclanguage.org/item?id=479

-----

1 point by icemaze 6561 days ago | link

Everybody seems to be in love with the step parameter. Would it be such an improvement over (for instance):

  (reverse (range 10)), or
  (map [* 2 _] (range 5)) ?
Do python guys use it that often?

-----

1 point by Xichekolas 6561 days ago | link

Yeah I'd much rather compose functions than have extra parameters to remember... but I'm not a Python guy either.

-----

1 point by apgwoz 6561 days ago | link

It's pretty inefficient to use reverse, if instead you can add an extra parameter, though I guess it's often negligible.

-----

3 points by sjs 6562 days ago | link | parent | on: Show us your Arc code

I'm still digging through the source, haven't done any coding yet. But...

There is a function called 'isnt' I did not see mentioned in the tutorial.

  arc> (isnt 1 2)
  t
Also an 'empty' function that's true for nil, empty lists and strings.

There's subseq, which is sort of like nthcdr but works on lists and strings (any sequence), and takes the seq before the n.

  arc> (subseq "uh, hello world" 4)
  "hello world"
  arc> (subseq (coerce "uh, hello world" 'cons) 4 9)
  (#\h #\e #\l #\l #\o)
'last' gets you the last value in a cons.

  arc> (last '(fee fie foe fum))
  fum
'adjoin' inserts a value into a set, unless already present.

  arc> (adjoin '(1 2) '((5 3) (1 2) (7 4)))
  '((5 3) (1 2) (7 4))
  arc> (adjoin 1 '(2 3 4))
  (1 2 3 4)
'consif' conses a value if it's not nil.

  arc> (consif 'sugar '(coffee cream))
  (sugar coffee cream)
  arc> (consif nil '(coffee milk))
  (coffee milk)
The complement of 'when', pg snuck 'unless' into the arc.arc excerpt at the end.

Make sure you read *.arc after the tutorial to really get a feel for the language.

-----