Clojure Goodness: Destructure Sequences

Clojure supports advanced destructure features. In a previous post, we learned about destructuring maps, but we can also destructure vectors, lists, and sequences in Clojure using positional destructuring. We can define symbols for positions in the sequence to assign the value at a certain position to the symbol. The first symbol in the destructure vector gets the value of the first element in the sequence, the second symbol the value of the second element, and so on. To get the remaining elements from the sequence without assigning them to specific symbols we can use & followed by a symbol. Then all remaining elements are assigned as sequence the symbol. Finally, we can use :as to get the original vector, list, or sequence.

The following examples show several destructure definitions for different types of collections and sequences:

Using Datahike’s Java API To Build a Web Application

The goal of this article is to introduce Datahike's Java API. To do so we will create a small web application together. The figure below illustrates the application architecture and lists some of the core advantages of using Datahike. Datahike is an open source, light-weight Datalog runtime with durable and auditable storage. It has an efficient query engine and is written in Clojure. On the left we can see the Spring Boot based application interacting with Datahike's Java API through its Controllers. Since Clojure is also hosted on the JVM, objects such as lists or functions can be transparently passed into Datahike's runtime.
Application structure


There are good reasons for using a Datalog database like Datahike. First, it is simple. It is a very small, well-factored core codebase (< 5000 lines of code) of a few core concepts. This allows it to be flexibly recomposed and integrated with existing data sources in novel ways. Furthermore, it is more declarative than SQL by its roots in logic programming languages like Prolog, which provide first-class support for implicit binding by logic variables. Because of its support for recursion, it is also strictly more expressive than pure relational algebras such as those described by SQL. Compared to non-functional databases, Datahike provides coordination-free read scaling by automatically snapshotting all write operations. These snapshots can be read in parallel in each JVM runtime context of an arbitrary number of reading processes. It can also be audited at any point in time like git. Datahike requires only Java dependencies and can be used in-memory, with a simple file-based backend, with Redis for high throughput, with auto-scaling cloud infrastructure like AWS S3 and DynamoDB, or with all of these backends combined in one query context.

PyDev of the Week: Elana Hashman: The Mouse Vs. The Python

Check out this week's PyDev of the Week!

This week, we welcome Elana Hashman (@ehashdn) as our PyDev of the Week! Elana is a director of the Open Source Initiative and a fellow of the Python Software Foundation. She is also the Clojure Packaging Team Lead and a Java Packaging Team member. You can see some of her work over on GitHub. You can also learn more about Elana on her website. Let's take a few moments to get to know her better!

You may also like: [DZone Refcard] Core Python
Can you tell us a little about yourself (hobbies, education, etc):

I love to bake and cook, so my Twitter feed tends to be full of various bread pictures or whatever dish I've whipped up over the weekend. When I was a kid, I was completely hooked on the cooking channel — my favorite shows were "Iron Chef" and "Good Eats" — and I thought I'd become a chef when I grew up. That's my back up plan if I ever drop out of tech!

Deep Neural Networks With OpenCV and Clojure on AWS Lambda

Learn more about Deep Neural Networks with OpenCV and Clojure

In our previous post, we managed to run a Yolo-based Deep Neural Network directly on a Raspberry Pi with object detection in semi-real-time on pictures and video streams. The processing was done locally, which is kind of optimum for a local video stream. But, it can be a little bit too power-hungry if you have a farm of these.

Here are some not-so-easy-to-get power consumption values for the Raspberry Pi. You can easily see that heavy CPU usage doubles energy consumption. In that case, a possible solution to offload processing out the Raspberry and onto servers is by using easy-to-set-up lambdas.

Raspberry Pi, OpenCV, Deep Neural Networks, and — Of Course— a Bit of Clojure

Learn more about Raspberry Pi, OpenCV, deep neural networks, and Clojure.

I had to write a simple IoT prototype recently that counted the number of people in a queue in real-time. Of course, I could have hired someone to do that and just keep counting people, or ... I could write a program in Clojure using a Raspberry Pi to detect the number of heads via a video stream.

You may also like: IoT OpenCV Scripting With Clojure on a Raspberry Pi

We learned recently that when using inlein, you can easily write scripts in Clojure with dependencies and run them just about anywhere, at a quite decent speed.

The Clojure Programming World: Libraries and Other Tools

With the vibrant community, the Clojure language has a good core of libraries, collections, and other ready-to-use tools. According to a 2019 survey, 25% of Clojure users create or maintain open source solutions. Some programmers also check and fix issues (17%), or report on them (15%).

Clojure users
Closure Users per SurveyMonkey

Although all these libs aim to simplify Clojure programming tasks, they may confuse a beginner. Sometimes, it’s difficult to understand how to put all of them together and find an optimal solution for a specific task. So, now I want to show you my favorite tools for programming in Clojure. We will talk about:

Building a Small Bank With Clojure

Clojure is a passionate language that uses strong mathematical expressions for you to write code. While I am not a language expert, in any language, in fact, I have a general profile. Therefore, I decided to create a small banking application for studying and testing purposes.

Before begin, I have three book recommendations:

Why I Picked Clojure

Clojure is a functional programming language that runs on the JVM (Java Virtual Machine), CLR (Common Language Runtime), and JavaScript platforms.

I was considering learning Lisp for a long time. The reason for this is that my lecturer, Chris Stephenson, had strong discourses on functional programming and was using Racket (a Lisp dialect) in some of his classes.