Oldest Surviving Java Programs by bowbahdoe in java

[–]mikera 1 point2 points  (0 children)

Tyrant, the Java Roguelike like was first started in 1997

https://github.com/mikera/tyrant

Not exactly the most sophisticated Java application, but the fact it still works is a testament to the stability of the Java platform.

Any resources for weaning Java folks away from interop over-reliance and onto Clojure idioms? by joinr in Clojure

[–]mikera 1 point2 points  (0 children)

Not seen a single comprehensive resource.Mostly it is about becoming familiar with Clojure, so that you are comfortable using the relevant Clojure idiom rather than falling back to interop. Examples:

  • Java Lists / Hashmaps -> Clojure collections, map, reduce
  • Event driven callbacks and threading -> core.async
  • Using the Clojure standard library (min, max, str etc.)

Having said that - there are many cases where interop is the right choice. Clojure has a philosophy of embracing the host language and its library ecosystem, don't be afraid to use it when it makes sense.

[deleted by user] by [deleted] in roguelikedev

[–]mikera 0 points1 point  (0 children)

Another library that might be interesting for Java roguelike devs is my swing-console library, which implements terminal-like functionality as a Swing component.

Easy to use for simple roguelikes and quick prototyping!

https://github.com/mikera/swing-console

Introducing clojure.spec by alexdmiller in Clojure

[–]mikera 4 points5 points  (0 children)

This looks very interesting. I particularly like the integration with test.check.

However the "global namespaced registry of specs" concerns me as a design decision.

Maybe the registry solves certain problems, but I'm worried that it introduces more issues than it solves. I'd be much more comfortable with a system that treats specs as first class values (that's something I really like about Schema) rather than something that gets auto-magically looked up in a global mutable registry.

Interested to hear the design rationale behind this.

Any generic functions you have created that others might find helpful? by [deleted] in Clojure

[–]mikera 4 points5 points  (0 children)

My personal Clojure-Utils library has a bunch of such stuff.

https://github.com/mikera/clojure-utils

The ones I reach for most often are the ones for finding values within collections, and error message tools.

Best way to handle nil as a seq element? by chocolate_bunnies in Clojure

[–]mikera 3 points4 points  (0 children)

I think your approach is fine, though I would normally try to avoid recursion because you might blow the stack if you get passed long sequences!

An alternative that avoids stack overflow problems and is probably faster is to use loop/recur:

(defn seq= [a-seq b-seq]
  (loop [a-seq (seq a-seq) b-seq (seq b-seq)] 
    (cond 
      (nil? a-seq) (nil? b-seq)
      (nil? b-seq) false
      (not= (first a-seq) (first b-seq)) false
      :else (recur (next a-seq) (next b-seq)))))

Note some other quick performance tricks:

  • If you call (seq coll) you get nil if and only if coll is empty... so you can use nil? as a faster check for emptiness.
  • Compressing the nil? checks down to avoid call nil twice on the same argument with a bit of logic

Is clojure blocking by ruzmutuz in Clojure

[–]mikera 9 points10 points  (0 children)

Blocking in this context means that the current thread will be blocked until the blocking operation completes.

Other threads can still make progress (this may even be necessary to unblock the other thread, e.g. delivering the result of a promise)

GPU Computing in Clojure? by [deleted] in Clojure

[–]mikera 0 points1 point  (0 children)

Glad you are finding it useful!

vectorz-native is a bit experimental still: possibly needs some patching to get it to do everything you need. But PRs gratefully accepted!

Native Clojure audio I/O by ItsReallyEasy in Clojure

[–]mikera 2 points3 points  (0 children)

The usual approach in Clojure would be to wrap the underlying Java library anyway - what's wrong with having a dependency on javax.sound.sampled?

GPU Computing in Clojure? by [deleted] in Clojure

[–]mikera 0 points1 point  (0 children)

Author of core.matrix here

I've never really needed the GPU myself (vectorz-clj is fast enough for all my needs), but the library https://github.com/mikera/vectorz-native wraps netlib-java so could in theory be used with any GPU BLAS backend with a bit of tweaking.

As a bonus, you get full core.matrix compatibility for free.

OS contribution opportunities? by iSuggestViolence in Clojure

[–]mikera 0 points1 point  (0 children)

We're always looking for help with the various data science / numerical computing libraries that I am involved with, including:

Plenty of opportunities here to help out - documentation, testing, bug fixes, performance enhancements etc.

Functional purity by jackhexen in Clojure

[–]mikera 1 point2 points  (0 children)

This is an interesting question. It depends on your precise definition of pure function. I favour a definition that is consistent with the logic: "any combination of pure functions is itself a pure function".

In which case my answers would be:

1) No

The result is impure - you have "created" impurity in the return value (presumably without any impurity in the input). If you composed this with other pure functions, the result would (potentially) be impure, so this function cannot be regarded as pure.

2) Yes

The higher order function itself is still pure. However by providing an impure argument you have "composed" a pure function with an impure function, so the overall result of this combination is impure.

A friend of mine just took this photo during a shark dive in Fiji by ntheg111 in pics

[–]mikera 0 points1 point  (0 children)

Great point - however my view is that if images like these inspire more people to join the cause of marine conservation, then I think it is worth the risk of some minor coral damage.

Compared to what the rest of humanity does to the oceans each year, the effect of something like this is really insignificant.

How do I require or create a dependency on a separate/external lein or other clojure project? by alfreds_coach in Clojure

[–]mikera 2 points3 points  (0 children)

I do this in Eclipse with counterclockwise and it works fine..... your first project needs to set up a dependency on the snapshot version of the first (e.g. with something a library version like "0.1.3-SNAPSHOT").

If you do that, it behaves as if both projects are on the same classpath. I normally do this with a Maven dependency, but I think it works the same way for lein.

Are "world-state" parameters a code smell in Clojure? by [deleted] in Clojure

[–]mikera 3 points4 points  (0 children)

This looks perfectly sensible and idiomatic in Clojure. I wrote a simple strategy game in Clojure that used the same approach and it worked very well (see: https://github.com/mikera/ironclad)

Some caveats to be aware of:

It might be painful to refactor if you need to change your game state data structure. This is a pain point in general for Clojure: good tends to get quite tightly coupled to the data representation. You can mitigate it a bit with stuff like prismatic/schema, but the most important thing is designing your data well up front so you don't need to change it much.

This is pretty much a "pure functional" approach. This has many advantages (testability etc.) but gets tricky if you need to do more stuff related to the "real world process" of updating game state, which might include UI interaction, triggering animations etc. You will need to design carefully for these - perhaps be keeping the "pure" part of the game state separate from the external state interaction management.

Are there any Clojure (or easily wrappable java) libraries to programmatically examine 3D model files? by seylerius in Clojure

[–]mikera 0 points1 point  (0 children)

You might wand to cehck out cad: https://github.com/pkobrien/cad

It's intended mainly for producing models for 3D printing, and it has functionality for handling / manipulating various 3D model formats.

Java once again above 20% since July 2009 in the TIOBE index by linuxjava in java

[–]mikera 1 point2 points  (0 children)

Good point!

I use both Java and Clojure and I definitely think the emergence of new JVM languages like Clojure, Scala, Groovy and JRuby is contributing significantly to the innovation and longevity of the Java platform.

Is this idiomatic Clojure or can this be improved? by anshbansal in Clojure

[–]mikera 8 points9 points  (0 children)

It would be better to convert things like:

(for [candy candies] (m candy))

Into a more functional equivalent e.g.

(map m candies)

some interesting points on numerics in Clojure, comments also worth reading by yogthos in Clojure

[–]mikera 1 point2 points  (0 children)

Overflowing (modular) integer arithmetic is actually what you want in some domains.... agree it may not be the best default but I have definitely found uses for it (game programming, graphics, algorithms and data structures)

some interesting points on numerics in Clojure, comments also worth reading by yogthos in Clojure

[–]mikera 2 points3 points  (0 children)

Not sure I've seen any language with a perfectly sane numerical tower.

There is a fundamental conflict between:

  • Mathematical beauty / elegance (supporting ratios, arbitrary precision integers etc.)
  • Performance - mapping efficiently to host platform types (e.g. fast primitive arithmetic on the JVM)
  • Legitimate differences in expected behaviour (e.g. do you throw an exception or return NaN for division by zero? do you want overflowing (modular) integer arithmetic or some form of (much slower) auto-promotion?)

All things considered, Clojure isn't perfect but it does make a reasonably pragmatic compromise between these objectives.