News for hackers. Stuff that matters.
Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @08:52PM (#12013088)
Concurrency aside, why is Elixir preferred over Ruby when it doesn't even have a native array implementation? No, lists and tuples are no substitute nor are maps with numeric keys as Jose has suggested. If you want an array in Elixir your only option is Erlang's implementation which ain't pretty - http://erlang.org/doc/man/array.html. When I raised this issue in the mailing list and on IRC the response was invariably a definsive "I've never needed arrays", "We use tuples for most things in Elixir" or "Array performance characteristics are difficult to optimise in a functional language such as Elixir". I just find this disappointing.
Re:Rails 5.0: Action Cable, API mode, and more by rdtsc on Thursday June 30, 2016 @09:05PM (#12013145)
Why do you want an array? You mean you want a memory area with adjacent cells layed out, to talk to C perhaps? Perhaps might want a list, a binary, or a sorted set, a tuple, a map and so on. You have to tell a bit more about your use case.

I used Erlang for many years, and in the last one full time. Not one time have I needed an "array". It seems you picked one odd feature no-one uses and are upset about it, I thik it is just a small misunderstand, if you share a bit more about what you are trying to do, you'll get more help.

> I just find this disappointing

Did you explain your use case to them. If you just said "I need an array" I see their response as perfectly rational. And from what I've seen, that is probably the friendliest and most approachable community, especially for newcomers.

Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @09:21PM (#12013216)
I would need an array for processing any large data set as an indexed collection. Why is that considered an "odd feature no-one uses" when it's a fundamental data type in most mainstream languages?
Re:Rails 5.0: Action Cable, API mode, and more by KallDrexx on Thursday June 30, 2016 @09:30PM (#12013251)
How are you planning on accessing it though?

If it's iterated over sequentially then a list works perfectly.

If it's random access then a map works.

Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @09:39PM (#12013294)
What if I want to push/pop it and also access it randomly by index? PHP gets a lot of stick for making arrays serve double purpose but the Elixir advocates of using maps for array purposes are basically arguing for the same thing, no?
Re:Rails 5.0: Action Cable, API mode, and more by di4na on Friday July 01, 2016 @04:07AM (#12014549)
Then you are not in functional programming place anymore, and you may want to use an imperative language.

I think it is John Hughes that said "The real question is not 'when should i use functional programming?' but 'when should i use imperative programming?' And the answer is 'When you need random access and complete control of your memory'"

Re:Rails 5.0: Action Cable, API mode, and more by kccqzy on Friday July 01, 2016 @03:53AM (#12014499)
Looks like you want a finger tree.
Re:Rails 5.0: Action Cable, API mode, and more by nine_k on Thursday June 30, 2016 @09:14PM (#12013180)
Does absence of arrays look a problem for you, while general immutability of most everything and message-based approach look totally normal and easy to grasp?

I suspect that to use Elixir, you need to study a new way of doing things first. Then you'll see arrays in a different light.

Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @09:26PM (#12013237)
I have studied Elixir and other functional languages such as Clojure where vectors are 1 of the 3 basic collection types so the "new way of doing things" isn't an issue for me. Elixir took a lot of inspiration from Clojure so the 2 languages are not that different.
Re:Rails 5.0: Action Cable, API mode, and more by nine_k on Thursday June 30, 2016 @11:06PM (#12013640)
Expectedly, per Clojure documentation, "Vectors support access to items by index in log32N hops". This means that a Clojure vector is essentially a tree-based map; a "true" array (as in C or Java) would have O(1) time for access by index.

I suspect that Elixir's maps are not different in this regard, as are Erlang's arrays, or maps in Haskell or OCaml. This is the canonical way to make an immutable map (see picture here: http://programmers.stackexchange.com/questions/195718/functi...).

Re:Rails 5.0: Action Cable, API mode, and more by jswny on Thursday June 30, 2016 @09:01PM (#12013125)
I've just started learning Elixir out of interest so I can't quite answer your question. However, I'd like to ask: what have you found to be difficult to do using the Elixir types such as tuples, list, keyword lists, and maps that would otherwise be easy to do using arrays? I'm asking out of genuine curiosity because I've specifically noticed a lack of arrays when learning Elixir and I'm quite used to using them in other languages.
Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @09:13PM (#12013179)
Elixir has no native array syntax nor any array functions in the stlib so arrays are basically second class citizens rather than completely absent. Ask not why I need them but why anyone might need them if the Elixir is supposed to be a general purpose language. Why does Clojure need them or Ruby or Python (lists)? If I want to process data as a large indexed array Elixir isn't going to help me and some Elixir devs have conceded that it may not be suitable for large scale data processing. We all know Elixir/Erlang excels at distributed concurrency but the question here is whether it is deficient in other areas, making it too much of a niche language.
Re:Rails 5.0: Action Cable, API mode, and more by rdtsc on Thursday June 30, 2016 @09:29PM (#12013249)
> Why does Clojure need them or Ruby or Python (lists)?

So you want a list it seems

   > l=[1,2,3]
   > [h | t] = l
       [1, 2, 3]
   > h
       1
   > t
       [2, 3]
> If I want to process data as a large indexed array Elixir isn't going to help me

But neither will Python. You'd want a large indexed array you probably want numpy.

See now you are revealing a bit more about your usecase that's helpful. So you have large amount of data and want to query it and process it. In that case you might want to check out ETS. The nice benefit, you have have cool matching or query list comprehensions of it. Can also access it concurrently from multiple processes:

http://elixir-lang.org/getting-started/mix-otp/ets.html

This is the Erlang side of it:

http://learnyousomeerlang.com/ets

> but the question here is whether it is deficient in other areas, making it too much of a niche language.

Of course it is deficient. C is deficient. Java, C++ is they all. Every language is deficient in some way. I haven't found a Perfect one yet. Still looking... Maybe Rust, who knows, still struggling to learn it.

Re:Rails 5.0: Action Cable, API mode, and more by desdiv on Thursday June 30, 2016 @10:20PM (#12013479)
>But neither will Python. You'd want a large indexed array you probably want numpy.

Python comes with array.array¹ natively.

¹ https://docs.python.org/3/library/array.html#array.array

Re:Rails 5.0: Action Cable, API mode, and more by rdtsc on Thursday June 30, 2016 @10:34PM (#12013537)
Original poster, specifically mentioned lists in Python, i.e. implying they wanted something equivalent to that. (Why does Clojure need them or Ruby or Python (lists)).
Re:Rails 5.0: Action Cable, API mode, and more by IanCal on Friday July 01, 2016 @03:50AM (#12014490)
It definitely doesn't fit as a hardcore number crunching language. People do regularly just setup their number-y code in C or similar and call out to it so you can handle the distributed stuff with a language that works well there and the low level stuff with a different one. Similar to numpy/etc. calling to C or FORTRAN libs.

> making it too much of a niche language.

No language will be the "one true language" that excels at everything.

Re:Rails 5.0: Action Cable, API mode, and more by bratsche on Thursday June 30, 2016 @10:09PM (#12013427)
> Elixir has no native array syntax nor any array functions in the stlib

There is no native array syntax, but there are array functions in the stdlib:

http://erlang.org/doc/man/array.html

Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @11:27PM (#12013693)
That's Erlang. I meant native as in Elixir syntax and the Elixir stdlib.
Re:Rails 5.0: Action Cable, API mode, and more by querulous on Thursday June 30, 2016 @09:23PM (#12013224)
if you need constant time access by index to a sequence of fixed size elements you can use binaries. if you want constant time access to a sequence of fixed size you can use tuples. if you want both you can get close with maps using integer keys or with trees (which i believe are used by clojure behind the scenes for arrays)
Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @09:32PM (#12013261)
If it comes to that I can just use Erlang's implementation but my question is why the omission in Elixir when arrays are supported in Erlang? With Elixir's excellent macro support surely an Elixir wrapper around Erlang's arrays wouldn't be so difficult?
Re:Rails 5.0: Action Cable, API mode, and more by acangiano on Thursday June 30, 2016 @11:29PM (#12013699)
Elixir wrappers that don't significantly enhance what Erlang is already exposing are discouraged within the Elixir community. As I type this, I realize that this might enrage you even more than the lack of arrays ever could. :)
Re:Rails 5.0: Action Cable, API mode, and more by GrinningFool on Thursday June 30, 2016 @09:23PM (#12013220)
This isn't a defensive response, just a genuinely curious one.

For certain types of programming - generally in lower-level languages - arrays can be essential for performance. But then my assumption is that if you needed that kind of performance, you'd be using those languages.

So outside of performance, what's the functional difference between an actual array implementation - and a thing that looks, walks, and quacks like a duck?

Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @09:28PM (#12013248)
Ruby, Python and Javascript all have native array support but can hardly be considered lower-level languages.
Re:Rails 5.0: Action Cable, API mode, and more by asonge on Thursday June 30, 2016 @09:43PM (#12013313)
Just to be clear, Javascript's arrays will, depending on the implementation, dynamically switch between sparse and compact implementations. A sparse javascript array literally behaves like a javascript object or a map with an integer index. Ruby and Python's arrays will grow as long as the allocator can alloc more memory onto the end, but has to copy the entire array if there's memory fragmentation...it's not quite the same as a C array.

Because of the immutable data, your best hopes are actually vectors or maps.

Btw, the erlang library you mention implements arrays on top of a tree of 10-ary(-ish) tuples. It'd need to be measured, but I'd be willing to bet that the native maps are faster at access, insert, and delete. The maps are implemented in C, and worst case for all operations would be O(n log n) or similar.

Re:Rails 5.0: Action Cable, API mode, and more by tedmiston on Thursday June 30, 2016 @09:05PM (#12013141)
Python lacks a native array too but its list type seems to do just fine. What is it you want to do that you that requires an array?
Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @09:18PM (#12013195)
Python's lists are lists in name only when compared with lists in functional languages. Whilst Python may offer additional array/vector implementations its lists are equivalent to arrays or vectors in other languages such as Ruby.
Re:Rails 5.0: Action Cable, API mode, and more by aprdm on Friday July 01, 2016 @03:15PM (#12018930)
incorrect. python has array.array which behaves just like in C. You even give the type of the data.
Re:Rails 5.0: Action Cable, API mode, and more by tbrooks on Thursday June 30, 2016 @09:51PM (#12013352)
In all your replies, you haven't given concrete example of "I need arrays because tuples or lists can't do X".

Complaining in the abstract isn't helpful.

If Elixir had arrays, why would that be better than using other enumerables like lists or tuples?

Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @11:30PM (#12013701)
It would be better because lists are not accessible by index and tuples are only designed for small amounts of data.
Re:Rails 5.0: Action Cable, API mode, and more by frigo_1337 on Friday July 01, 2016 @04:18AM (#12014584)
...but why do you want to access it by index?

Since you refuse to be more specific, it sounds like you're just not willing to learn the language and the way problems are solved with it.

Expecting mutable C-type arrays in elixir/erlang is like expecting classes and lambdas in an assembly language. It's just not a good fit for what the language was designed to do.

Re:Rails 5.0: Action Cable, API mode, and more by alehander42 on Friday July 01, 2016 @07:04AM (#12015090)
not the OP, but I've had a side project in Elixir and often I wanted to browse/play with some of the last saved models in repl. When I get the collection using `ecto`'s `Repo.all..` I can't just `bets[4]` or `bets[-2]`, I have to do weird gymnastics like `hd(tl(bets |> Enum.reverse))`
Re:Rails 5.0: Action Cable, API mode, and more by smss79 on Friday July 01, 2016 @07:36AM (#12015225)
Re:Rails 5.0: Action Cable, API mode, and more by alehander42 on Friday July 01, 2016 @04:34PM (#12019432)
thank you!
Re:Rails 5.0: Action Cable, API mode, and more by cutler on Thursday June 30, 2016 @08:54PM (#12013103)
Sorry if seems a bit off-topic but I raised this issue because there have been a lot of posts about Rails devs switching to Elixir/Phoenix.