Arc Forumnew | comments | leaders | submit | gaah's commentslogin
1 point by gaah 5897 days ago | link | parent | on: How to implement a no-side-effects macro?

I don't have access to the Arc source for various reasons at the moment (maybe in 30 minutes), but assuming an appropriate definition of deepcopy:

  (mac w/nondestructive (names . body)
    (if (acons names)
        (cons `(fn ,names ,@body)
              (map [list 'deepcopy _] names))
        `(let ,names (deepcopy ,names) ,@body)))
There's probably a better way to write that, but that's what I have now.

-----

2 points by gaah 5898 days ago | link | parent | on: Question about "subclassing" lists

Just saying, I've looked at Factor (http://www.factorcode.org/) and I like what little I've seen of its OO mechanism. For example, when you call add (which adds the top element of the stack to the end of a sequence underneath), it ends up calling whatever add method the sequence defines.

In Arc, this would translate into the ability to define your own sequence type, and you could have your own definitions for operations like cut within the type definition.

-----

1 point by gaah 5901 days ago | link | parent | on: Newbie questions about list operations

Have you never seen a good implementation of singly-linked lists? Because accessing the last element is a relatively common operation, a decent implementation will keep a pointer to the last element. Because it's singly-linked, the last element is the only one that pointer is any good for, so (lst -2) is still O(n), but (lst -1) becomes O(1).

The weird thing is, I actually found this good idea in an APCS review book.

-----

3 points by gaah 5901 days ago | link | parent | on: How to implement a no-side-effects macro?

I think you want this:

  arc> (= a 3)
  3
  arc> (= b 5)
  5
  arc> (let a (+ a 4)
         (+ a b))
  12
  arc> (with (a 2 b (+ b 2))
         (+ a b))
  9
  arc> (with (a 6 b 2)
         (prn a) (prn b)
         (= b a) (= a 'foo)
         (prn a) b)
  6
  2
  'foo
  6
  arc> a
  3
  arc> b
  5
The title of your post is misleading. I think when people saw "How to implement a no-side-effects macro" they read that as "How to implement macros with no side effects" rather than "macro that hides side effects from the surrounding scope".

You asked a simple question about lexical scoping. You got complex and confusing answers about macro hygiene. It is not that Arc has no easy answer to your lexical-scoping question, it is just that your simple question looks like a much harder one about macro hygiene.

-----

1 point by lacker 5901 days ago | link

Sorry I was unclear - I was indeed actually trying to ask a hard question.

I don't know a priori what variables this code will try to access. I could possibly figure that out with a macro, but some of the details are still unclear to me. I also don't want side effects if annotate, def, mac, or anything like that was run from the no-side-effect'd code.

At any rate, I think just wrapping in a let is insufficient, even if you do know all the variable names. E.g. you can break out of the sandbox with scdr:

> (= a '(1 2))

(1 2)

> (let a a (scdr a '(3)))

(3)

> a

(1 3)

-----

2 points by gaah 5901 days ago | link | parent | on: Password trouble

Sorry, yes. My regular account name is Jesin, but the best proof I can offer is that while I don't have the password the account will remain inactive (unless of course someone else manages to get the password). I use that name for almost all of my online accounts, but I don't happen to have an account at Hacker News yet.

As I said, I think I put my email address on my profile for that account, so if I could access a verification-email-based password recovery system I'd be fine, but for some reason you need to be logged in to do that.

-----

1 point by gaah 5901 days ago | link | parent | on: Arc has no return statement?

The major difference between return statements in other languages and ccc is that you can use any continuation that you can access, which means you can conditionally return to two different places in the code. As an example, here's a loop that supports "break" and "continue" (and can even break with a return value):

  (mac my-loop body
    `(ccc (fn (break)
        (while t (ccc (fn (continue) ,@body))))))
Also, I need help. I can't use my regular account because I have forgotten my password and the only password recovery thing is only accessible when you are already logged in. I am pretty sure I put my email address on my regular account, so I don't see why I can't recover it. Please post any suggestions at http://www.arclanguage.org/item?id=4449

-----

1 point by Jesin 5894 days ago | link

Please note that I have my account back. I don't really know how, though. Follow the link for more info.

-----