Arc Forumnew | comments | leaders | submit | kostas's commentslogin
3 points by kostas 2262 days ago | link | parent | on: With and withs

Look at the definition of with and withs at https://github.com/arclanguage/anarki/blob/master/arc.arc

The macro definition of with creates a function with all the names as inputs and the body of the with as the body of the function. The newly created function is called with the definitions of each name, which are effectively in independent namespaces.

The withs definition, however; recursively calls itself so that each succeeding name sees the definitions of previous names.

I believe the difference is historically due to higher speed of with. In modern programming it probably makes sense to use withs everywhere and only change to with in places where optimization is necessary.

-----

4 points by akkartik 2262 days ago | link

I actually tend to the opposite: use with everywhere unless I need withs. The reason isn't performance. It tends to make code more elegant to not rely on the order in which things are defined. And when I'm reading code, with gives me the warm fuzzies that the code is going to be cleaner. When I see withs I slow down to look at the dependencies between the bindings.

-----

3 points by zck 2262 days ago | link

Similarly to this, when I'm writing Java, I use `final`^1 everywhere I can. It's nice to be able to know that anywhere later where the variable declared final is in scope, it will have the same value as at the point it's set. I don't need to look through any code to see if it's rebound; I know it hasn't been.

[1] "final" is kind of like "const", if I understand `const` right. `final int x = 3;` means that it is an error to later have the line of code `x = 4;`.

-----

3 points by prestonbriggs 2262 days ago | link

OK, I get it, thanks. In scheme, I would use letrec for this situation; my intuition for Arc isn't very well developed.

-----

2 points by kostas 5962 days ago | link | parent | on: Poor Man's Regular Expressions

I haven't played with Arc in while, but I have these two lines added to my ac.scm to add mzscheme's underlying regexp functionality to Arc:

  (xdef 'regexp pregexp)
  (xdef 'r-match (lambda (x y) (ar-nill (pregexp-match x y))))
Look up pregexp and pregexp-match in the mzscheme documentation for details on how they are called.

-----

2 points by kostas 6095 days ago | link | parent | on: Moved Anarki to GitHub

Sent.

-----

1 point by absz 6095 days ago | link

Thank you!

EDIT: Now I have 3 invites too. Yay exponential growth!

-----

1 point by kostas 6096 days ago | link | parent | on: Moved Anarki to GitHub

Me too please (sotsak.kostas@gmail.com)! Posting kind of late, so I hope someone notices.

-----

2 points by wfarr 6096 days ago | link

Done.

-----

1 point by kostas 6095 days ago | link

Got it. Thank you.

-----

1 point by kostas 6098 days ago | link | parent | on: posmatch broken?

  (pos #\a "bcd")

-----

1 point by kostas 6111 days ago | link | parent | on: Bug in codelines function in code.arc

Thanks. Learning to use git is next on the priority list.

-----

2 points by kostas 6114 days ago | link | parent | on: Arc2.tar

The install page http://arclanguage.org/install still refers to arc1.tar

-----

1 point by kostas 6116 days ago | link | parent | on: acond for Arc

Very nice. Thanks.

-----

1 point by kostas 6116 days ago | link | parent | on: acond for Arc

I was wondering why acond wasn't included in arc.arc. Now I see why. The Arc aif is definitely better. Thanks.

-----

7 points by kostas 6127 days ago | link | parent | on: New version

PG,

Grepping the source, the x.y and x!y syntax doesn't seem to be used.

Have you tried them out on the news.yc code? What's your initial feel in terms of code compression?

-----

6 points by pg 6127 days ago | link

I've been trying this syntax on example programs for several weeks. Maybe months, actually. It doesn't yield startling results in compression if you count x.y as 3 nodes, but it does make programs easier to read, particularly when you use it for structure access.

-----

9 points by curi 6127 days ago | link

why not change x!y to x.'y ? seems a bit easier to remember, saves ! for something else. dunno if there's a parsing problem with it.

-----

7 points by pg 6127 days ago | link

Hmm, never thought of that. I'll consider it.

-----

3 points by mattjones 6127 days ago | link

What if x.y!z expanded to ((x y) z)? Then if x were '(1 2 (3 4) 5), x.2!1 would give you 4. If (x 1 3) did work like cut, then you could do x.1.3!1!1, which would also give 4 in this case.

-----

More