Arc Forumnew | comments | leaders | submitlogin
2 points by thaddeus 5064 days ago | link | parent

In addition to hasenj's suggestion of some:

  arc> (find 1 (list 1 2 3))
  1
The benefit of using 'find' is that it returns the value if found and nil otherwise. Depending upon how you're implementing your code you may discover 'find' works better. ie what if your going to pass the result into another function?

example:

   (tag-user (find user admins*))
might be better than:

   (if (some user admins*)
       (tag-user user))


2 points by rocketnia 5064 days ago | link

As long as we're going down this road...

  arc> (some 'c '(a b c d c b a))
  t
  arc> (find 'c '(a b c d c b a))
  c
  arc> (mem 'c '(a b c d c b a))
  (c d c b a)
  arc> (pos 'c '(a b c d c b a))
  2
  arc> (keep 'c '(a b c d c b a))  ; significantly less efficient
  (c c)
All of these ('some, 'find, 'mem, 'pos, and 'keep) use 'testify, so if the thing you're searching for is a function, it will actually use that function as a predicate instead of searching for the function value itself.

  arc> (pos no '(a b c nil e))
  3
  arc> (pos no (list idfn no 72))
  nil
  arc> (pos [is no _] (list idfn no 72))
  1
By the way there's a gotcha specifically with 'find, which makes it an odd one out: You can't find nil with it. The function will be called with nil (if it's a function), but a success will just result in an intermediate return value of nil (the found value), which is then considered to be a failure, and the loop keeps going.

  arc> (find [do (prn "checking " _) no._] '(1 2 nil 3))
  checking 1
  checking 2
  checking nil
  checking 3
  nil
Even if 'find could find nil, a successful value of nil wouldn't be very helpful. ^_^

-----

1 point by markkat 5063 days ago | link

Thanks, rocketnia. That really does clear some things up. Here, 'some works great for me, since I am passing the result to 'case with two instances.

I can't say I have got a feel for Arc yet, but I think I am starting to. The more I work with it, the more it seems to open up. Not so much that feeling with the HTML definitions, however. But I am not going down that road until I have a much better handle on the language.

BTW, are there any good editors other than vi and emacs? I used vi years ago for FORTRAN, didn't like it, and have never used emacs. Currently I am using Wordpad. :p

-----

1 point by evanrmurphy 5063 days ago | link

> BTW, are there any good editors other than vi and emacs? I used vi years ago for FORTRAN, didn't like it, and have never used emacs. Currently I am using Wordpad. :p

Not sure how anyone could would want something besides vi/vim or emacs, but I use emacs with vim key bindings so maybe I'm biased. ;)

vi and emacs are great editors, but each has a mammoth learning curve. I think this is why they often make bad first impressions. I'd be interested to know more about your experience with vi and what you disliked about it.

Other editors I see people using include Notepad++, Textmate, jEdit, nano, NetBeans and DrRacket (which you might like for Arc and Racket code). Unfortunately, I don't know much about these firsthand.

-----

2 points by markkat 5063 days ago | link

I guess I expected this answer. :) Although I hadn't heard of nano. I should probably bite the bullet and start to familiarize myself with emacs or vi since they are so universal. Probably emacs.

My experience with vi involved some physics modeling years ago in undergrad. I recall 'zz'? I never stop forgetting to toggle the input mode. I don't know why. Maybe I am a bit right-brained, but I have a sloppy way of working. Something about vi felt so 'tight', and I prefer a canvas feel. Not really the best mindset for programming, no doubt, but I have learned it's ok to be a bit sloppy and get things done rather than be very neat and unproductive.

Sorry, starting waxing philosophical there... thanks.

-----

1 point by rocketnia 5063 days ago | link

For what it's worth, you're not the only one. I haven't gotten the hang of anything but the Windows text box conventions. :)

Pretty much all I want is an editor that loads quickly, shows whitespace, highlights matching parens, and does regex search-and-replace and find-in-files. Usually my choice has been EditPlus, but Notepad++ is a great open-source alternative, and gedit's another good one (although I think I've had to use grep separately with gedit).

I turn to jEdit for editing Unicode documents, NetBeans for editing C/C++, and DrRacket for editing big Racket projects, but those are extremely rare situations for me. Most of the time I avoid all three of them because of how long they take to load; I can almost always get in and out faster with plain Notepad.

I haven't looked at TextMate or nano.

-----

1 point by evanrmurphy 5063 days ago | link

> Something about vi felt so 'tight', and I prefer a canvas feel. Not really the best mindset for programming, no doubt, but I have learned it's ok to be a bit sloppy and get things done rather than be very neat and unproductive.

Upvoted for waxing philosophical.

-----

1 point by thaddeus 5063 days ago | link

Textmate (http://macromates.com/) at least has syntax colouring using aran's bundle:

https://github.com/aran/arc.tmbundle

If you're on windows, there's a version of textmate called 'e:

http://www.e-texteditor.com/

It can use aran's syntax colouring bundle as well.

-----