News for hackers. Stuff that matters.
Re:Snake in Elm with WebGL by pgt on Monday June 26, 2017 @03:28PM (#14639552)
I made Snake in 103 lines of ClojureScript for a talk from 2015: https://github.com/theronic/cljs-snake

It would be fun to implement WebGL as a renderer.

Re:Snake in Elm with WebGL by DrPhish on Monday June 26, 2017 @04:20PM (#14640020)
I'm going to make this the "Other awesome snake implementations" sub-conversation

Here is a snake in 4k (sn4ke) mapped onto a sphere instead of a 2d playsurface, which is one of my favourites. http://www.pouet.net/prod.php?which=61035 Here is an awesome music-driven one that modifies the songs based on level and "danger" http://www.pouet.net/prod.php?which=57518

But the best snake ever was the one from FastTracker 2 by Triton! http://www.pouet.net/prod.php?which=13350

Re:Snake in Elm with WebGL by dyarosla on Monday June 26, 2017 @03:06PM (#14639351)
Bug: Create snake of length two. Move RIGHT. Quickly press UP LEFT in quick succession. Lose.

Similar bug with RIGHT->DOWN->LEFT

And so on for all the other initial directions.

Re:Snake in Elm with WebGL by fb03 on Monday June 26, 2017 @03:17PM (#14639446)
Not the author, but I've implemented my own snake game and this bug is fairly easy to kill.

(1) - You can only change directions that will change your axis, if you're going left your possible changes are up and down, ....

(2) - You should be only able to consume one direction change per game tick, what is happening here is that rule (1) is working but you can change into the other axis, and then back to the other axis again before the game loop computes another frame. Direction change can be read asynchronously but the actual change should be tied by each tick.

Re:Snake in Elm with WebGL by baddox on Tuesday June 27, 2017 @12:24AM (#14642561)
Maybe it makes it too easy, but I would enjoy the mechanic that quickly pressing UP LEFT when moving right would make the snake head move one square up then turn left and continue left. I suppose that would require some special casing, and you wouldn't want to support longer queued direction changes. Maybe a nice implementation would be that for inputs queued within a single game tick, execute the first input for one square of movement, then the last input for the next tick.
Re:Snake in Elm with WebGL by KurtMueller on Monday June 26, 2017 @03:16PM (#14639441)
Why not file a Github issue? :)
Re:Snake in Elm with WebGL by dyarosla on Monday June 26, 2017 @03:19PM (#14639470)
Done
Re:Snake in Elm with WebGL by fareesh on Monday June 26, 2017 @06:09PM (#14640801)
Yeah happened to me too, thought it was my mistake but now I blame the bug :D
Re:Snake in Elm with WebGL by Kiro on Monday June 26, 2017 @02:44PM (#14639201)
How is the actual game loop executed? I don't know Elm but I only find update, not how it's run.
Re:Snake in Elm with WebGL by kornish on Monday June 26, 2017 @02:51PM (#14639253)
The function `Html.program`, in `main`, takes an update function which handles (among other things) ticking the game loop.

http://package.elm-lang.org/packages/elm-lang/html/latest/Ht...

Re:Snake in Elm with WebGL by donatj on Monday June 26, 2017 @03:06PM (#14639352)
I attended a two day Elm workshop a while back. There is a lot there to love, I just think it's Haskell inspired syntax is a major impediment to it's mainstream adoption. I however would love to be proven wrong as the webs reliability would be so remarkably improved.
Re:Snake in Elm with WebGL by mikekchar on Monday June 26, 2017 @03:16PM (#14639438)
Here's a challenge for you: what syntax would be better? I don't mean that in a derogatory way. I think you are right that the syntax (being very foreign to people) does provide an impediment, but puzzling out how to implement the same functionality with a more familiar syntax would be extremely difficult (though potentially very fun).
Re:Snake in Elm with WebGL by crimsonalucard on Monday June 26, 2017 @04:05PM (#14639893)
Redux follows the same pattern with your more "familiar" syntax.

Typed functional programming offers wins that forces more safety and modularity onto the code. These are all long term wins. Ultimately I would argue that elm's syntax is better suited for extremely complex projects that have low tolerance for bugs.

Re:Snake in Elm with WebGL by lilactown on Monday June 26, 2017 @04:14PM (#14639968)
Redux is a javascript library. It shares some idioms with correct Elm code, but is a very different beast.
Re:Snake in Elm with WebGL by crimsonalucard on Monday June 26, 2017 @04:46PM (#14640216)
Right but the underlying design pattern is the same. This is all I'm saying. Redux can almost be thought of as an Elm pattern implementation with "familiar" imperative syntax.
Re:Snake in Elm with WebGL by winstonewert on Monday June 26, 2017 @03:44PM (#14639694)
Well, something like C-like, for maximum familiarity.

What functionality is difficult to render in C-like syntax?

Re:Snake in Elm with WebGL by orblivion on Monday June 26, 2017 @03:57PM (#14639822)
Currying
Re:Snake in Elm with WebGL by winstonewert on Monday June 26, 2017 @04:24PM (#14640058)
I can get the same effect as currying with C syntax by deliberating invoking a special function:

    functools.partial(old_function, my_new_argument)
Is this such a useful thing that you need the functional style syntax to make it even easier to do?
Re:Snake in Elm with WebGL by orblivion on Monday June 26, 2017 @05:50PM (#14640677)
You can do it in Python as you have, but it becomes second nature with Haskell (I can't speak to Elm directly). You might not even realize you're doing it.

Add 5 to each num in a list (using a pretend function called `add` in both languages to be fair):

  map(functools.partial(add, 5), nums)

  map (add 5) nums
Add 5 to each in a list of list of numbers:

  map(functools.partial(map, functools.partial(add, 5)), nums)

  map (map (add 5)) nums
Re:Snake in Elm with WebGL by winstonewert on Monday June 26, 2017 @07:24PM (#14641266)
I suppose it would make more sense to write these as lambdas in a c style syntax

   nums.map(|sublist| sublist.map(|num| add(num, 5))
Maybe I haven't done enough functional programming yet, but I still like the explicitness of the C-style over the functional style.
Re:Snake in Elm with WebGL by kasbah on Monday June 26, 2017 @08:44PM (#14641674)
Sorry, but there is nothing more explicit about using lambdas as you have done, it's simply redundant (notice the repetition of sublist and num arguments).
Re:Snake in Elm with WebGL by nathancahill on Monday June 26, 2017 @04:48PM (#14640226)
Yes
Re:Snake in Elm with WebGL by chenglou on Monday June 26, 2017 @03:49PM (#14639736)
I work on Reason, which is something you might like: http://facebook.github.io/reason/

Elm has been personally an inspiration too. Nice set of decisions and tradeoffs for what they're trying to achieve, though yeah, mainstream syntax might not be one of them, but that's fine.

Re:Snake in Elm with WebGL by xfer on Tuesday June 27, 2017 @09:54AM (#14645364)
sorry, what are these decisions and tradeoffs? why not just use ocaml(for anyone who doesn't mind not C-like syntax)?
Re:Snake in Elm with WebGL by KurtMueller on Monday June 26, 2017 @03:15PM (#14639436)
Imho, Elm's syntax is more akin to OCaml than to Haskell. Besides OCaml, it reminds me a lot of F#.
Re:Snake in Elm with WebGL by fpoling on Monday June 26, 2017 @04:03PM (#14639868)
Or any other strict language in ML family like SML. Still it tells something about language popularity when is Elm is only compared with Haskell.
Re:Snake in Elm with WebGL by lolc on Monday June 26, 2017 @04:12PM (#14639946)
Cool demo. And I learn there was an Elm conference close to where I live and I missed it.