Arc Forumnew | comments | leaders | submit | sacado's commentslogin
2 points by sacado 6480 days ago | link | parent | on: Arc has no return statement?

I gave a solution at http://arclanguage.org/item?id=4430 . It invloves only ccc (Arc's version of call-with-current-continuation) :

  (def a (return)
    (each i xs
      (if ( ... )
        (return i)))
    nil)

  arc> (ccc a)
  1
This is a very low-level solution, if you want to put your hand into axioms. almkglor's solutions, based on point & breakable macros (from Anarki) are much cleaner, even if they just expand in the above code (or something very close).

-----

3 points by lojic 6480 days ago | link

Just to clarify, point is in Arc and doesn't require Anarki.

-----

4 points by sacado 6481 days ago | link | parent | on: asds

Obviously we can't vote done submissions, only comments. It's a shame.

-----

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

"I think we do not have a Lisp plug-in for browsers"

Well, we have JavaScript, and it is not really safer by design than Lisp (they are quite close, too). But JavaScript has a security manager, quite restrictive sometimes. And look at rebol : that's also a close relative to Lisp and it's got a cool security manager.

Well, they mainly prevent you from reading/writing the host filesystem or from connecting to undesired remote servers.

Lacker, this might not be as "secure" as Java's model, and not exactly what you were asking as it does not prevent you from overwriting another's code, but it is obviously enough to run untrusted code on one's machine. And to implement it, you only need to overwrite the dedicated axioms in ac.scm.

-----

1 point by kennytilton 6481 days ago | link

"Well, we have JavaScript,"

Then there was that other ILC where the speaker argued we Lispers should rejoice because Javascript was a Lisp and was in all the browsers. Make sure there are no children in the room and I'll tell you what happened next.

-----

1 point by sacado 6481 days ago | link

Compared to Java (i.e., seen from far away), it is. Well, of course, code isn't also data in JavaScript :)

-----

1 point by kennytilton 6480 days ago | link

Many agree. Here is a blog entry on the ILC guy I mentioned:

  http://bc.tech.coop/blog/030920.html
Looks I'll be tearing into ActionScript shortly, I'll let you know. :)

-----

2 points by sacado 6481 days ago | link | parent | on: Arc challenge: 8 Queens Problem

  (def valid (stack)
    (with (q2 (- len.stack 1)
           result t)
      (each q1 (range 0 (- len.stack 2))
        (= result (and result
                       (isnt stack.q1 stack.q2)
                       (isnt (abs:- q1 q2) (abs:- stack.q1 stack.q2))))))

  (def queens (stack n)
    (if (is n 8)
      (prn stack)
      (each rank (range 1 8)
        (push rank stack)
        (if (valid stack)
          (queens stack (+ n 1)))
        (pop stack))))

  (queens '() 0)
It's a naïve implementation of what you wrote in Ruby. It should work, however I didn't try it. It is not really optimal, as there is no return in my code. Anyway, it's quick and dirty...

-----

2 points by almkglor 6481 days ago | link

If you're on arc-wiki, you can use the breakable: modifier to create a breakable with/let:

  (def valid (stack)
    (breakable:let q2 (- len.stack 1)
      (each q1 (range 0 (- len.stack 2))
        (if (or (is stack.q1 stack.q2) (is (abs:- q1 q2) (abs:- stack.q1 stack.q2)))
          (break nil)))
      (break t)))
edit: BTW, your 'valid function didn't actually return the result ^^

-----

1 point by sacado 6481 days ago | link

oh, right, each returns nil...

Thks for the "breakable" info

-----

2 points by lojic 6481 days ago | link

Is there a way to return in Arc?

-----

2 points by sacado 6481 days ago | link

Sure, ccc is here for that. Let's say we want the equivalent of this Python code :

  def a:
    for i in (1, 2, 3):
      if i < 2:
        return i

    return None
It can be written this way in Arc :

  (def a (return)
    (each i '(1 2 3)
      (if (< i 2)
        (return i)))
    nil)

  arc> (ccc a)
  1
To those who don't know ccc : in this code, return is not a defined macro or function, it is the current continuation, waiting for a value. We could have called it another way, k for example.

Once you "throw" it a value (i in this case), it's happy and goes on to the next calculation. (ccc a) thus tells to perform a and, once the return parameter is called, exit a and go back to the REPL (with the specified value).

-----

2 points by lojic 6481 days ago | link

Thanks for the quick reply. That seems like an awkward way to accomplish a simple thing - Python & Ruby win on this IMO.

I submitted a new article ( http://arclanguage.com/item?id=4431 ) on the topic. It might be good to re-post your comment there and have followups on that thread.

-----

2 points by almkglor 6481 days ago | link

better is point:

  (def a ()
    (point return
      (each i '(1 2 3)
        (if (< i 2)
          (return i)))
      nil)))
That said, the breakable: macro simply compiles down to (point break ...)

-----


Oh, yes. That one drove me crazy a few times.

-----


As a matter of fact, I'd love Arc to not be only web-oriented. Anyway, what will the web be like in a hundred years ?

-----


I didn't vote up for Arc, but I actually used it at work most of the time for the last month. For what I'm working on, I am free to use whatever I want and Arc really rocks !

And I use it as a hobby, too...

-----


I use them to build trees, two-sided lists, when I need to encapsulate a value (e.g. to dinsinguish between nil-the-boolean and nil-the-empty-list). For all those things, opaque lists or hashes could be used, too.

But the main use of dotted lists is for recursively-built and recursively-explored lists :

  (def foo (a b)
    (if a 
      (cons (car b) (foo (cdr b))
      nil)
and relatives appear in so much of my code... I don't think I would like to see dotted pairs go away. And if you don't like them, you can always use (list ...), (l 0), (l 1), (last l), rev, ... and not care about actual implementation.

-----

3 points by nzc 6482 days ago | link

I know, I know, I just asked this question b/c I saw someone else's post about dotted pair containing lists (old timers would say "s-expressions") not working properly in some cases in arc, and I having noodled around implementing lisp in ruby recently, and having stubbed my toe on implementing cons after having chosen arrays as the underlying implementation of lists, I thought I'd throw this out there and see what people had to say.

-----


Ah, I remember that too. Those innocent days where most of the problems were like "should I use 'print' or 'input' there ? What's the difference between them ?"

-----

3 points by sacado 6483 days ago | link | parent | on: How do I Run a Program?

It does work, but don't do that :) At least if you're generating, for example, very big lists : everything evaluated in your program will be displayed. If your code contains something like (= foo (range 1 1000000)), you'll somewhat regret it...

But, in many cases, that will work just fine, despite the noise generated by the repl. You can also do mzscheme -m -f as.scm < myprogram.arc >/dev/null to turn the whole output off (in case you don't need it at all).

-----

2 points by absz 6483 days ago | link

Or wrap your whole program in a (do ... t) block, which is what I do. No change in semantics, and everything works fine.

-----

More