(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).
"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.
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.
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...
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).
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.
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 !
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.
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 ?"
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).