Posts on Twitter:

Shout out to dev community; long term remote assignment, building payment platforms. Visit Ireland for some pair-programming (2-3 weeks) this Summer. Explore the coast whilst here. Drop me a line stephen@keepersolutions.com :-)







time once again for me to release my technology radar. is still the gold standard for enterprise software













The room is full for meetup today ! Thanks for hosting us ! The first talk is about for Data Science by



Retweet Retweeted Like Liked



It's always worth reading new stuff about things you (suppose to) already know. Just finished the awesome " " by , took an old exercise (array equilibrium index) and trimmed it down from ~30 to >10 loc. Still not sure is a good version though.



Show this thread




Join a team of engineers who working with functional languages such as , & . This is an unmissable role in for a Senior Functional Engineer. DM for more details or apply below. 👉













RT RealGeneKim "RT stuarthalloway: Try to make better things. "







Naive Riemann sum in . Remember times when I could spend 30 minutes implementing this in C



Retweet Retweeted Like Liked








Posts on Tumblr:

Truchet 4

Valuable Things in Clojure
  • dpsutton: immutable datastructures, a repl, and an alex. all features i value in Clojure
  • alexmiller: tell your friends :)
  • christian767: I do that too :slightly_smiling_face:
youtube

Every Clojure Talk Ever - Alex Engelberg and Derek Slager

Side-effects may include side-effects.

Clojure

   (.setFeedSubmissionIdList request (.setId (IdList.) ids))
   ;; これは下記のようにも書ける
   ;;(-> request
   ;;    (.setFeedSubmissionIdList (.setId (IdList.) ids)))
   ;;
   ;;(-> request
   ;;    (.setFeedSubmissionIdList (-> (IdList.)
   ;;                                  (.setId ids))))

Syndicode Digest #65 – Modest genius

When you’re modest, nobody will know how much you do. But when people claiming too much, they’re not taken seriously as talented ones. Because talent comes with modesty and thoughts that your achievement will be evaluated sooner or later. Better sooner, of course. However, sometimes …

Why I Love Macros

Macros are one of those weird things that programmers sometimes hear about, but unless they’re using a language that has them, they might think macros are weird, archaic, and/or useless. If their only prior exposure to macros have been through C/C++, I can kinda see where they’re coming from.

Like most other features from Lisp, metaprogramming (aka macros) is slowly starting to creep into modern day programming languages. Scala has it, Clojure has it (being a Lisp dialect and all that), Haskell has it (through Template Haskell), JavaScript has it (through Sweet.js), and of course Rust has it.

Coming from a background of C/C++, macros are nothing but a simple text-replacement system, where the preprocessor runs through your code and replaces the text almost verbatim, a good example of a C macro that I’ve used a fair bit is this one:

#define foever for(;;)

so that I can write

forever {
  /* do repeat this forever */
}

All the macro really does, is have the preprocessor go in and replace every occurrence of the word forever, and replacing it with for(;;) (which is the same as while(true) for those uninitiated).

That’s all great and all, but C/C++ macros are just text replacement macros, which means they don’t have the power of “true” macros. If we take good ol’ Lisp for example: since everything in Lisp is a list, that means the data within a macro definition is itself a list, which means we can do list manipulation on the program code itself! List concatenation, iteration, mapping, reducing, all that good stuff becomes possible when macros are data rather than simple preprocessor text!

Now, Lisp syntax is a bit too obtuse to give decent examples in without confusing people too much, so let’s use Rust instead. Fair warning: I haven’t used Rust enough to know if it has quite the same expressive power as Lisp macros, but it’s certainly up there, judging by the lazy_static! macro.

A common example of Rust macros is the vec! macro, since it’s very easy to implement and very easy to explain, so here we go.

The vec! macro is defined as follows:

macro_rules! vec {
  ($($x:expr),*) => ({
    let mut vec = Vec::new();
    $(vec.push($x);)*
    vec
  })
}

I’ll explain what each line does in a moment, but let’s first see it in action: if I write

let v = vec![1, 2, 3, 4];

the macro will actually expand that expression to this:

let v = {
  let mut vec = Vec::new();
  vec.push(1);
  vec.push(2);
  vec.push(3);
  vec.push(4);
  vec
};

That is to say, it creates a new scope, then an empty vector, pushes each value into it one by one, and then returns the vector out of the scope and into v.

Let’s break down how this works then: on the first line we have macro_rules! vec {, which just means “define a new macro called vec”.

Then we have the expression line that looks like this: ($($x:expr),* => ({, which just tells us that we have 0 or more metavariables called x that are separated by a comma. In this case x has to be an expression, which lets us write things like 2 + 3, 4, 2.pow(3) and so on.

On the next line let mut vec = Vec::new();, we define a new vector called vec, and then $(vec.push($x);)* just says “for every x, create a line vec.push($x);, where you replace $x with the corresponding expression.

Then lastly we have vec which simply tells us to return the vector out of the block.

It’s super simple, and the syntax is actually a bit similar to regular expressions: * for "0 or more”, and + for “1 or more”. I believe Rust also has ? for “0 or 1”.

So why is this useful? Because it lets you extend the syntax of the language to suit your needs! If you have any kind of long chain of something that you want to reduce down to just a few expressions, you can probably do it with a macro.

Rust’s error handling syntax, the ? is just a macro behind the scenes, and it lets you write

  let foo = f()?;
  let bar = g(foo)?;
  let baz = h(bar)?;

instead of

  let foo = match f() {
    Ok(x) => x,
    Err(e) => return Err(e)
  };

  let bar = match g(foo) {
    Ok(x) => x,
    Err(e) => return Err(e)
  };

  let baz = match h(bar) {
    Ok(x) => x,
    Err(e) => return Err(e)
  };

The possibilities are virtually endless, and the joys are great! If your favourite language of choice has a macro system, I suggest giving it a go, because it’s a great way of reducing otherwise painful boilerplate.

if-some

;; 条件式が nil ではない場合(false も含む)は then を評価する


boot.user> (if-some [foo false]
            (println “then”)
            (println “else”))
then
nil
boot.user> (if-some [foo nil]
            (println “then”)
            (println “else”))
else
nil
boot.user> (if-some [foo true]
            (println “then”)
            (println “else”))
then
nil
boot.user> (if-some [foo ()]
            (println “then”)
            (println “else”))
then
nil
boot.user> (if-some [foo 0]
            (println “then”)
            (println “else”))
then
nil
boot.user> (if-some [foo “”]
            (println “then”)
            (println “else”))
then
nil
boot.user> (if-some [foo true bar false]
            (println “then”)
            (println “else”))
java.lang.IllegalArgumentException: if-some requires exactly 2 forms in binding vector in boot.user:8

if-not

boot.user> (if-not false
            (println “then”)
            (println “else”))
then
nil
boot.user> (if-not nil
            (println “then”)
            (println “else”))
then
nil
boot.user> (if-not true
            (println “then”)
            (println “else”))
else
nil
boot.user> (if-not ()
            (println “then”)
            (println “else”))
else
nil
boot.user> (if-not 0
            (println “then”)
            (println “else”))
else
nil
boot.user> (if-not “”
            (println “then”)
            (println “else”))
else
nil
boot.user> (if-not false
            :then)
:then