Arc Forumnew | comments | leaders | submit | thaddeus's commentslogin
6 points by thaddeus 5085 days ago | link | parent | on: Project to learn Arc

1&2.There are a few options:

There's an old anarki library you can use to download a webpage. The library can be seen here: http://github.com/nex3/arc/tree/arc2.master/lib/http-get/. However - I once used that library for my personal market scanner (downloads data for tens of thousands of stocks) and found it to be fragile. My suggestion is to use the 'system' command (http://files.arcfn.com/doc/os.html) in order to call 'curl' or 'wget'. See http://curl.haxx.se/ or http://www.gnu.org/software/wget/. These utilities auto-download the webpage for you.

3. You will then need to 'readfile', see http://files.arcfn.com/doc/io.html

4. You'll need to edit the data, then re-serve the page, in which case you use 'defop' (http://files.arcfn.com/doc/srv.html) or you can write the file out to your static directory.

[edit] #4: If you choose to use the static directory you may need to ensure arc is set up to serve out certain types of files (i.e. .js, etc). See http://arclanguage.org/item?id=10620. Anarki has already taken care of this, but arc proper has not.

-----

1 point by parenthesis 5082 days ago | link

>> My suggestion is to use the 'system' command …

One just needs to be careful to avoid command injection vulnerabilities.

-----

1 point by akkartik 5082 days ago | link

Eek, meant to upvote.

-----

1 point by akkartik 5082 days ago | link

Can you elaborate on how http-get is fragile?

-----

1 point by thaddeus 5082 days ago | link

My memory is a little foggy, but I remember a system fork error.

Hmmm... I also found the old related post and there was also another error: "PLT Scheme virtual machine has run out of memory; aborting Aborted"

http://arclanguage.org/item?id=11899

I know the nginx comments add a little confusion to the post (as I wasn't sure at the time what was going on), but I don't think Apache vs. nginx was the problem.

In retrospect it may not be the library, it might have been scheme, but none the less when I switched to wget, the problem went away.

-----


Through-out this whole thread I've wanted to kick in and say: "boy I wish Arc was built on top the jvm, similar to Clojure's implementation", but then I also realize one might as well just switch to Clojure if that's what one wants.

Would have been be nice though. Smart move by Rich.

-----

1 point by aw 5130 days ago | link

Why do you wish Arc was built on top of the JVM?

-----

1 point by thaddeus 5130 days ago | link

The way clojure implemented it allows for seamless integration between libraries. With clojure I can load and easily make use of any java code out there. I can use cron job libraries, database libraries etc. etc. And I really don't require much java knowledge, just a basic API used to call the library/jar file. This gets people on-board, hence larger community, building all kinds of kewl apps/libraries... More solutions, more knowledge base... Just more options.

With arc, the language syntax and base libraries are awesome, but you scratch your head more often, wondering" well how the hell am I supposed to do that. " And these problems/features are not small roadblocks... For example, if I need to use Arc connecting to oracle? - good luck, it's not going to happen.

If arc were built atop the jvm, the way clojure is... These problems all go away.

-----

1 point by thaddeus 5129 days ago | link

@aw/

Thanks for the offer. I think real database connections to arc could only improve the adoption + user happiness levels, but I will suggest connecting to oracle was just an example for the point I was trying to make.

What I am suggesting is not new or even surprising. Arc has no depth for libraries. Rich solved this problem right from the get-go by having tight integration with java. Arc would have had similar success had it done the same thing - too bad really. And dropping into Scheme just doesn't cut it.

I'm suggesting users of arc will google things like 'arc oracle', or even 'scheme oracle' which returns jack. With Arc you get Nada for google answers + you get unanswered posts such as these.

http://arclanguage.org/item?id=10839

However google 'clojure oracle':

http://en.wikibooks.org/wiki/Clojure_Programming/Examples/JD....

step-by-step recipes to connect to a myriad of databases. This was made possible through Clojures tight integration with java. Clojure can import java libraries with 1 simple import statement.

Let's not forget that Clojure is a newer language than Arc - correct?

Now, I'm just looking at the title of the thread "Effort to make it easy to use in production?", and thinking - yeah, I can understand, that's why I moved over to Clojure and its too bad Arc didn't do this.

Sure I'm no expert in the programming language industry, but if I were to come up with a new spiffy language I'd rather do what Rich did. Arc could have been built atop the jvm - correct? It was just easier not to, considering arc was not about being practical, it was about attaining some elusive mystical idealized syntax that will be practical in, possibly, a hundred years from now.

Sorry if this sounds like a rant, but it just seems like the original poster wasn't getting much love, and I can appreciate what and why he/she was asking.

-----

2 points by aw 5129 days ago | link

When I started work on my Arc runtime project, the first thing I looked at was what I thought would be the best platform to write the runtime on top of. Racket seemed to be moving away from Arc in some ways, so I didn't start with the assumption that Racket was going to be the right choice. I looked at a number of options, and concluded that as far as I could tell that Racket still had the best mix of features.

The JVM naturally has the advantage that it's easy to call Java libraries, but it has the disadvantage that it has no built-in support for tail call optimization or continuations. Since it's not particularly difficult to make use of libraries running in a different process, it would be easy enough for me to use Java libraries from an Arc implemented in Racket if I wanted to, and so I had no compelling reason to write ar on top of the JVM.

There is a long history of languages written for people who want to use the JVM but who also want to be able to use a less terrible language than Java: Jython, Groovy, Clojure, etc. Since Clojure is a particularly nice language, it didn't surprise me that it rapidly gained popularity among people who want to use the JVM.

For any particular project that I may be working on, there are a mix of features that I need for that project. If I were working on a project that primarily needed to call Java libraries and I didn't need the features unique to Arc, I would most likely use Clojure myself (or Rainbow or Jarc, if it turned out that one of those were suitable to my project). If I were working on a project where the features of Arc were important and I also needed to call some Java libraries, I'd likely write it in Arc calling out to Java libraries.

Since this is a forum for Arc, I answer questions primarily from the perspective of Arc. Since typically a hundred people will browse a forum for each person posting, I primarily answer questions for the majority reading. For example, if someone makes a statement that is wrong, I will say that they are wrong, so that someone else reading the forum isn't left with incorrect facts.

When someone complains about Arc, I tend to suspect that either there's something they want, or else they just feel like complaining. People wanting things is useful. If someone actually wants X and says so, and we come up with a solution for them, then we also help the hundred other people who want that thing as well. Other the other hand, and I'm not saying that anyone has actually done this, but if someone were to sit at a computer and type in a complaint that other people haven't done the work to make Arc a popular language faster than some other language has become popular, that doesn't strike me as being particularly useful.

I'm not against complaining. Complaining is often a useful first step towards finding a solution. However, while I'm not trying to pass judgement, I am trying to discern whether someone is complaining because they just want to complain or because they want a solution.

Again, when I answer a question, I answer a question primarily for people in general reading the forum; and from the perspective of people wanting to use Arc. Thus if Clojure is a better solution for you for most of the projects that you work on, that's fine, I agree you should use Clojure. However when I read "for example, if I need to use Arc connecting to oracle? - good luck, it's not going to happen" my immediate concern is that someone else is going to read that and might be left with the impression that it's prohibitory difficult to connect to oracle from Arc... which, while it's certainly harder to connect to oracle from Arc than it is from Clojure, isn't all that difficult.

-----

2 points by thaddeus 5129 days ago | link

Being difficult or easy is a relative thing. The hours of investment by grade-a developers contributing to making these production grade feature-x's in other languages leads me to feel pretty comfortable suggest that having them, or a dozen other similar feature-x's would not be all that easy.

Sure, if you have spent hundreds of hours doing low level hacking between racket<->arc you can suggest these things are not all that hard, but the reality is that many of these feature-x's are just not going to happen.

Chances are that mainstream features are not a priority for the members here... And that's my message to the OP: go use Clojure or something having the features you want. I say this from 2 years of following arc, the arc forum and its members. There are probably a dozen submissions/comments about db connects and FFI, yet to this day nothing works.

The people on this forum, who know me, know I like the arc language, often promote it and that I'm not here to tear it apart, but I'm going to be real about it and make sure the op gets the right message (from my perspective).

-----

1 point by thaddeus 5129 days ago | link

@aw/

> "If you like the Arc, then instead of complaining that other people aren't figuring out what you'd want to use for you, why not take the time to help and describe what you would need in a db connection library and FFI?"

I'm thinking if you re-read the thread starting from my first comment (http://arclanguage.org/item?id=14539), you'll hopefully come to understand that I haven't been complaining, but rather I have been defending/substantiating my suggestions and thoughts.

As for why I don't take time to describe some spec, well because I'm not asking for anything and I've chosen to spend the bulk of my time learning Clojure and building applications. I guess you could say I take my own advice.

> "If you want some love on the forum, there's an easy way to get that:make a useful contribution."

It's pretty obvious, based upon your replies, that you don't see my posts as valuable contributions, but maybe you'll come to understand these posts are intended to help the OP rationalize his topic, not to gain some form popularity/acceptance with or by you.

-----

1 point by aw 5129 days ago | link

oh, I don't mean to be impugning your intentions, and I apologize if I did so.

-----

1 point by aw 5129 days ago | link

If you like the Arc, then instead of complaining that other people aren't figuring out what you'd want to use for you, why not take the time to help and describe what you would need in a db connection library and FFI?

Or, you could add a page to the wiki describing the ways that Clojure is better than Arc.

If you want some love on the forum, there's an easy way to get that: make a useful contribution.

-----

1 point by aw 5129 days ago | link

Would you like to be able to use Arc to connect to oracle?

-----

1 point by rocketnia 5130 days ago | link

What about Rainbow and Jarc?

-----

1 point by thaddeus 5130 days ago | link

I have to go back and check them out... See how they load other jar files or if they do, but good idea - thnx

-----

1 point by rocketnia 5129 days ago | link

If the JARs are in the classpath, the classes are just as accessible as any standard platform class like java.util.Map. I give a demonstration here, where I explain the custom interface I built so I could sometimes use the same code on both platforms: http://rocketnia.wordpress.com/2010/06/01/lathes-arc-to-impl...

Since then, Jarc's actually added Rainbow compatibility functions, so you might be able to get away with writing code just for Rainbow without leaving Jarc too far behind. Rainbow's faster, but Jarc has a more straightforward implementation.

I recommend having one of the JARs be a language with eval, like Groovy, JRuby, or Clojure. Jarc and Rainbow convert certain values to/from Arc in ways that are nice most of the time but sometimes lose precision, like the distinction between Boolean.FALSE and null.

-----

2 points by thaddeus 5141 days ago | link | parent | on: Why arc?

> why starting to work on a new species instead of trying to evolve an existing one.

Because working with arc is more enjoyable than working with scheme.

;=

I think you're assuming that people here only use Arc. I for example spend 99% of my programming time in Clojure. And still, in many respects, arc is better than other languages. For example, I think arc is perfect (syntax wise) for being an embeddable language. An end user of my app can easily become familiar with Arc, which is not the case for scheme or clojure. It's certainly both easier and more enjoyable to use than scheme is.

There's also a time/money/productivity argument to be made as well. I will not elaborate, suffice to say Arc wins this one hands down.

Also, I'll add on what I know a few others think -> The Arc code is small in size, easy to learn making it more easily hackable hence a better choice for experimenting.

-----

1 point by Pauan 5141 days ago | link

"Also, I'll add on what I know a few others think -> The Arc code is small in size, easy to learn making it more easily hackable hence a better choice for experimenting."

Short version:

This. Very this. I think Arc's smallness is a Good Thing.

---

Long version (do I have too much spare time on my hands...?):

The funny thing is, when I first started programming in Arc, I had almost no Lisp experience, and almost no functional programming experience either. Sure, I knew lambdas and closures (due to my JavaScript experience), but I didn't write my JavaScript in a very functional style. I kinda sorta understood the concept behind recursion, but when I tried to read a program written in recursive style, I didn't understand it and my brain hurt.

Yet, I was able to start writing programs in Arc... and anytime I had a question like, "I wonder how that function works", I could just look in arc.arc and see for myself. Despite all the limitations described above, I didn't have a very hard time learning Arc. After a short while (maybe 2 days or so), I had even started to get into the "rhythm" of Arc, reading and understanding code by it's context, rather than having to parse each individual node. I even forced myself to learn to read recursion a bit better.

I thought this was astonishing. Being able to pick up and quickly learn and use a language and paradigm that I had almost no experience with, just by reading the language itself. It was like how a baby learns to speak a language, except I'm not a baby, so I don't have that magical ability anymore. I didn't have that experience with Python. I could pick up and use Python because it was similar to JavaScript (both tend to emphasize imperative/procedural style), but I'm still constantly looking up how to do things in the Python documentation...

And then there's Racket. Racket has a large amount of documentation, and they even have a search engine to trawl through it and find what you want. Yet I still have a hard time figuring out what a function does, even though they give me what parameters the function expects, what value the function returns, a brief description of what the function does, and sometimes even examples!

I find Arc easier to learn and use, despite (or perhaps because of?) it's philosophy that "code is the spec". In a sense, I think being smaller is better for exploratory programming. Having a nice, robust, stable language with tons of well-written big libraries is great for writing robust programs. But I think a lot of that just gets in the way when you want to fool around and experiment.

In that situation, I think you're better off axiomitizing things as much as possible. Lisp does that by (over?)emphasizing lists, and then having a bunch of functions that operate on lists. You can then go in later and change the datatype to a hash table or whatever, once the program is in a more complete state.

It's easier to add things, than it is to take things away. Lua wins not because it can do everything, but because it's small, and smallness is good in embedded languages. I think Arc wins for a similar reason: it's small. I think it'd be a lot harder to evolve that kind of smallness in an existing language, compared to starting with a clean slate.

Oh yeah, maybe it would help if you thought of Arc as being more of a thin skin on top of an existing language (like Scheme). This is actually true in pgArc, Anarki, and ar, because they let you access the underlying Racket functions. So you get the niceness of Arc by default, but you can tap into Racket's libraries when you need to.

I also plan to eventually do the same thing with Arubic... allowing Arc programs to import and use Python libraries. And if I recall correctly, jarc and rainbow also let you call into Java's libraries. And then wart, which I assume lets you call CL functions.

I actually think that's a pretty neat idea: having a nice small core that's easy to learn and use, but still give an "escape hook" to get access to the underlying implementation, when needed.

-----

2 points by thaddeus 5143 days ago | link | parent | on: Why arc?

Not sure there's a definitive answer, but I believe pg saw an ideal evolutionary path for Lisp that was not being followed. I believe the plan, with arc, was to correct the foundation such that this hopeful evolutionary path could happen.

This is just what I get from reading a bunch of his post, code comments and articles. It's probably a good idea to read pg's articles from years ago during the initial design phase to get an understanding of what choices were made and why.

for example:

http://paulgraham.com/ilc03.html

The reason I got interested in arc was not all that interesting.It was simply much easier to learn than scheme was.

-----

2 points by rocketnia 5143 days ago | link

"an ideal evolutionary path for Lisp that was not being followed"

"much easier to learn"

These are my reasons in a nutshell.

I've always liked the philosophy of programming in whatever language was most suitable to the task, and everywhere I looked indicated that lisps emphasized that philosophy. It made sense, since s-expressions seemed pretty ideal as a way to use a single generic parser to handle all kinds of custom languages.

As I was looking into it, I read about Paul Graham's plans for Arc and liked the idea of a lisp with that kind of open-to-the-programmer philosophy (and avoidance of extraneous parentheses). And then I found out Arc existed, and I gradually made my way over to Arc from Groovy.

Arc doesn't do everything I'd like it to: No modules, less polymorphism than I'd like (but way more than Scheme), not enough consistency for the kind of metaprogramming I have in mind. Still, it's pretty close to what I want, and it's the kind of foundation that's allowed me to get closer and closer.

-----


> Maybe it's a way to keep discussions between a few people (Pauan and myself) from spoiling everyone else's ability to view the forum

My guess is that he doesn't want to wedge the server with many long page load requests.

-----

1 point by aw 5148 days ago | link

(for future reference, that is, without speculating on why or why not someone may have made decisions in the past, but if someone runs into a similar problem in the future)

If:

a) you're running a web application on top of Arc, and

b) you have some very long pages that are taking a long time to render, and

c) it's a page that you actually want to be able display to your users

...then there are less drastic alternatives to kicking the page off the front page:

- you can increase caching (at the cost of the displayed page being a bit more out of date)

- break the page up into parts and add "next" and "prev" links

- provide a runnable example (http://awwx.posterous.com/share-your-problems-with-runnable-...) of your problem on the forum and get help

-----

1 point by thaddeus 5148 days ago | link

Knowing the code was written with a news site in mind, you could also theorize (or speculate, which ever makes you happier) that the author (aka pg) would value both the quality and currency of the content over pouring coding efforts into handling of overly active, and by that time, older posts.

All speculation of course. I'm just suggesting that, often, there are simple reasons for the choices made behind these kinds of decisions.

All the ideas you list are great ideas. It's funny though, even I spent a bunch of time writing a blogging platform and I still have not bothered to put paging into the listings. I figure at my current rate of posts, it will take me a year before I'll need to worry about it. There are things we should do, in our ideal world, and then there's what we need to do relative to all other things. So, again, I suggest that maybe the reasons for these kinds decisions can often be much simpler than we think. There's not always some elusive statistical computation with all kinds attention and detail poured into them.

[edit1] ignore the below point... point format tricked me up reading on my ultra small screen :)

I don't fully understand what this point has to do with anything:

- provide a runnable example (http://awwx.posterous.com/share-your-problems-with-runnable-...) of your problem on the forum and get help

I like the work you did, but how does this fit into the discussion or your comment? It seems out of place.

[edit2] Also I used to like the fact that this forum allowed for editing within the first hour. I could correct my mistakes before, I figured, anyone had time to even read them, lol... but, that's not working anymore and trying to respond to changing posts kinda sucks.

I wish this forum had a "save as draft" feature! Maybe I'll just write it somewhere else first.

-----

1 point by aw 5148 days ago | link

I don't fully understand what this point has to do with anything: - provide a runnable example

If you have a web application that is running too slowly and you want help, then you make it possible for other people to help you if you provide a runnable example that demonstrates it running too slowly.

-----

1 point by thaddeus 5153 days ago | link | parent | on: Choosing a default open source license

Can't say I agree with your thoughts so far. And I am not sure how we as a society would benefit from ditching IP notions.

I get the sense you believe that it's a huge waste of time a nothing more than a money pit for legal expenses. I believe if they went away then the openness that we are experiencing in this day and age would dry up.

When a house craftsman comes to my house and builds me a stairwell, I can't take his work and re-sell it. If I could, then he would quickly go out of business.

You speak of being "somewhat creative" in order to get compensation, but the reality is that the playing field becomes so uneven that the dived between the rich (in this case often the corrupt) and poor becomes greater. That's not a good thing.

-----

1 point by waterhouse 5153 days ago | link

> I am not sure how we as a society would benefit from ditching IP notions.

Indirectly, by having a more consistent legal system. As I said, I believe pretty strongly in property rights, and I believe IP is inconsistent with property rights. Debate about either of those things is probably way off topic for the Arc Forum, even more so than it would be for Hacker News.

As for the rest of your arguments, they're all of the form "there are unfortunate consequences". I can take each one of them and argue that it wouldn't be as bad as you think--sometimes because it'd be bad for some people for a while, but people would adapt and we'd all probably be better off at the end of it--as is usually the case with technological revolutions. I could explain myself in more detail and give examples, and in fact I began to do so, but, again, this is probably not the place for such a debate. Suffice to say that I have reasons for my opinions; I've done a lot of reading, thinking, and arguing on the subject (with myself, with the things I read, and with friends); and in an extended debate, you'd probably concede that at least my reasoning made sense even if you didn't agree with some of my premises.

Well, I've stated my opinion, and beyond that, the matter has little practical importance. As I said, I'm inclined to respect people's wishes, and if I copy and paste anyone's code here, it's little trouble for me to copy and paste the text of the copyright and license or whatever as well. (It would only be a problem if you were using the GPL or something, which I believe is supposed to require me to release my entire project under the GPL.) And it certainly shouldn't be a problem when I give code to you guys.

-----

1 point by thaddeus 5153 days ago | link

It's fair to say this is not arc language topic, so I will try to not extend it. It really is an interesting topic. For the record, I am not against your ideas, I just not able to marry the ideas up to the results.

-----

1 point by rocketnia 5153 days ago | link

I for one would like to hear more about how sustainable your ideas are, maybe over email. ^_^

-----

1 point by rocketnia 5153 days ago | link

I can't say I like the concept of encouraging openness through censorship (which is basically how IP works, right?), but I think you're spot on there. I don't know the reality, but the rich have better marketers to determine how best to profit off of an idea and how best to make that profiting seem polite to the original creator. There are already times someone makes a deal with Hollywood and doesn't like the result; I don't think that's distinguishable from someone who doesn't get to have a say in any deal in the first place.

It would be nice if there were another option like the anarchic politeness waterhouse describes, but I think IP is the natural next step from that, being a law system to help courts encourage/enforce politeness on behalf of people who don't have enough marketing dollars or military power to encourage it themselves.

-----


> persisted macro for declaring data structures so that mutations to them will translate to requests to a riak server.

That sounds awesome. I've just started using riak and I can certainly see using that.

-----

3 points by thaddeus 5154 days ago | link | parent | on: Prototypes/methods vs. extending.

I agree with most of what you're saying, but I will add a few things:

There are, generally speaking, two types of people who visit this forum. The first, type-A let's call them, are hardcore hackers, like yourself(ves), who are interested in the language design and the underbelly mechanics of language assembly. Then there are people, like myself, whom are only interested in using the language to build applications.

When I read: > "Arc would be a better solution for my problem if it had...", "It's more rare for this to be followed up by an actual runnable implementation of the feature." I will suggest the two types of people represent the divide within the pattern you're recognizing and I will going to even further to suggest this is not a bad thing. I would like to encourage more type-B user engagement - even, if only, so that I am not all alone :)

While I don't have the time or inclination to understand the full content/depth within these type-A posts, I do try to learn what I can even if only at a surface level. I really do enjoy reading these posts and do appreciate them so I hope they don't go to a back channel as akkartik has mentioned a possibility for.

Furthermore, I would like to highlight some of the points aw's message that I feel are really important (and with my interpretation):

* Inline comments are not the best way to present your ideas. I've struggled assembling all the bits and pieces and knowledge requirements from prior posts/threads. The order alone messes everything up and I simply do not have the time to do the paper chase.

* Writing an external blog post will likely force you to present a fuller picture, with its surrounding context, to an audience that can't always be on top of things.

All that said, please don't give up on the ideas, we need more of them - not less.

-----

2 points by aw 5154 days ago | link

I would like to encourage more type-B user engagement

I added an "Arc Wish List" page to the wiki: https://sites.google.com/site/arclanguagewiki/wish-list It's currently empty :-) Perhaps some type-B users would like to fill in some things they'd like implemented? ^_^

Oh, and by the way, there's an infinite amount of room available in the wiki for other things such as proposals, ideas, arguments, implementation approaches, and so on. So if you're looking for a place where you can write things out and edit them later, the wiki is great place to do that. (You can of course also write your own blog post if you want, and we can link to it from the wiki as well).

-----

1 point by thaddeus 5154 days ago | link

I'm working on it :)

I took a break to write a blogging platform from scratch that includes my own custom markdown.

I even posted my first arc topic here: http://blackstag.com/blog.posting?id=2. I then quickly discovered the auto spam bots are moving from the arc forum to my blog site every night. So I took another break, lol, just to put some spam management code in. I'm glad had read enough of pg's code to implement some good techniques similar to news.arc.

Now I'm ready to do more blogging - I hope. I've accumulated a list of 9 or 10 posts and I plan to get some arc stuff in there as well.

I swear, I don't know how people find the time!

-----

1 point by Pauan 5154 days ago | link

"...there's an infinite amount of room available in the wiki..."

You sure you want to encourage DoS attacks? :)

-----

1 point by thaddeus 5155 days ago | link | parent | on: Prototypes/methods vs. extending.

a reply for one layer down:

> JavaScript allows arbitrary expressions in switch statements

That's right... looks like it was the test data I was thinking of, which isn't entirely relevant, given you can accomplish the same thing in the end.

> Why make the common case difficult?

A fall-through could be nicer than many breaks. Trying to think of all the scenarios required to make this usable, i.e., do you need a break to get out of a fall-through? Maybe that's why they just went with break. either way, it's a good idea.

-----

1 point by Pauan 5155 days ago | link

The current behavior for switch is simple: it will continue until it finds a break statement. Thus:

  switch (true) {
  case true:
      console.log(1);
  case true:
      console.log(2);
  case true:
      console.log(3);
      break;
  case true:
      console.log(4);
  }
...which outputs 1, 2, and 3. If you wanted to have the same behavior using the continue statement, you would use this:

  switch (true) {
  case true:
      console.log(1);
      continue;
  case true:
      console.log(2);
      continue;
  case true:
      console.log(3);
  case true:
      console.log(4);
  }
As far as I know, this would have exactly the same power as using break; but would be much better suited for the very common case of not wanting fallthru. I think it's much more readable, too: makes it very obvious where it falls through. And it's less error prone... no more strange bugs if you accidentally forget to add in a break; statement.

In fact, in my years and years of programming in JavaScript, I have used if/else blocks many many times (some of which could have been switch statements), and only wanted fallthru a handful of times. I think allowing fallthru is fine, but it should be made explicit, rather than implicit.

The only possible argument I can think of in favor of implicit fallthru is using a switch inside a `for` loop:

  for (var i = 0; i < array.length; i += 1) {
      switch (array[i]) {
      case "foo":
          continue;
      }
  }
...but that's actually ridiculous because I'm fairly sure that breaking out of a loop is far more common than continuing. In which case explicit fallthru would be better with loops.

-----

2 points by thaddeus 5155 days ago | link | parent | on: Prototypes/methods vs. extending.

I'm going to argue that you're comparing apples to oranges to pears.

Arc and Javascript case functions are not expected to do the same thing. JS does not allow expressions for input arguments while Arc can. And that break; statement is a feature that some would say Arc lacks. ie, what if you want your case statement to fall through? - now Javascript is golden and one could say Arc is lacking.

I also don't believe developers, generally speaking, prefer if/else chains over switch/case statements as they are different tools intended for different purposes.

They both are not perfect, both are missing features that the other could benefit from.

I think Clojure got it right having it all: case + cond + condp.

-----

1 point by Pauan 5155 days ago | link

Not true... JavaScript allows arbitrary expressions in switch statements, so it does behave like Arc's `case`, only it's much more verbose:

  switch (true) {
  case 5 > 1:
      console.log("5 > 1");
      break;
  }
---

On the contrary, switch should not have a break statement! It should have a fallthru; or continue; statement. Why make the common case difficult? This should be uncontroversial... it's been well established that switch's design is poor, and they should have made it explicit fallthru (like with a continue statement) rather than implicit.

As for Arc "lacking" fallthru... can't you implement that with continuations? That would be the equivalent of explicit fallthru.

---

My point was that switch statements are so atrocious that even in the situations that they were intended for, some developers still prefer if/else chains because they're shorter and more readable.

-----

1 point by waterhouse 5155 days ago | link

> Why make the common case difficult?

I think that's because the above semantics correspond more directly to assembly language, which I imagine was done because "switch" was defined back when that was either important or just not seen to be bad. (Perhaps I'm just making that up, though.) Here's how a switch statement would look in x64 assembly:

  switch:
        ;put desired thing in rax, let's say
  case_1:
        cmp rax, val_1
        jne case_2      ;jump if not equal
        <case 1 code>
  case_2:
        cmp rax, val_2
        jne case_3
        <case 2 code>
  case_3:
        cmp rax, val_2
        jne done
        <case 3 code>
  done:
        <whatever>
By default, the machine will just plow through the remaining cases. If you want it to break out after one case, you have to tell it to do so:

  switch:
        ;put desired thing in rax, let's say
  case_1:
        cmp rax, val_1
        jne case_2      ;jump if not equal
        <case 1 code>
        jmp done        ;jump.
  case_2:
        cmp rax, val_2
        jne case_3
        <case 2 code>
        jmp done
  case_3:
        cmp rax, val_2
        jne done
        <case 3 code>
  done:
        <whatever>
Assembly language is kind of awesome, by the way. And so is the Miller-Rabin primality test. Some disorganized code: http://pastebin.com/raw.php?i=wRyQ2NAx

-----

1 point by Pauan 5155 days ago | link

Fine. That's great and all for C, but I dislike how Java copied C word-for-word, and then JavaScript copied Java. It would have been nice if they had said, "hm... using continue rather than break would make a lot more sense."

It's not a huge deal, and developers can simply avoid switch if they don't like it. My point was merely that "JavaScript's switch sucks, Arc's (case) is awesome."

-----

More