Category Archives: Clojure API

Clojure rand functions

Here are some examples of Clojure random functions.

 

You’re welcome.

Recent REPL Values

This post will look at a few dynamic vars to look at recent return values in the Clojure REPL.

 

You’re welcome.

Working with list*

Today’s look into the Clojure API is a post on list*, and how it differs from list and conj.

list* takes as its args elements you want to add to a collection, followed by the collection. If the elements you are adding are primitives, it will return a flat list, simply adding the elements to the collection. Like conj, it adds the elements to the front of the list. Unlike conj, list* always returns a list, even if you give it a vector. If you are adding two collections, you will not get a flat list.

list takes elements to make into a list. If use this to add an element and a list, you will get a nested list.

 

You’re welcome.

More Clojure Numeric Tests

Here are some more numeric tests.

I went through a Scheme tutorial titled “Teach Yourself Scheme in Fixnum Days”. One page had a nice code excerpt with functions showing all the different kinds of numbers that I found helpful.

  • The set of integers (like 42)
  • Are within the set of rational numbers (like 22/7)
  • Are within the set of real numbers (3.14)
  • Are within the set of complex numbers (like 2+3i)
  • Are within the set of all numbers.

Numbers in Clojure do not quite fit into this hierarchy, since Clojure runs on the JVM. Functions that test for real numbers (like float? or decimal?) return false for integers.

 

You’re welcome.

Working with some numerical test functions

Here are some Clojure functions for numerical tests.

 

You’re welcome.

 

Working With Clojure Arithmetic Functions

Continuing the exploration of the Clojure API, here are some of the arithmetic functions.

 

You’re welcome.

 

Working with structs

Here are some examples working with the Clojure API.

Here I look at various functions based on StuctMaps. The Clojure website says that records are now usually a better option. StructMaps have faster accessors that regular maps.

Here are some examples with defstruct:

Here are some examples with create-struct (pretty much the same):

If you create instances with “struct” instead of “struct-map”, you can list the args in order without the keys.

 

You’re welcome.

Working With conj

Another page exploring the Clojure API.

Today, it’s conj.

Added 2017-10-04_22.55.23

 

 

You’re welcome.

assoc and update

Working with assoc and update in Clojure.

Code entered at 2017-10-04_19.34.11.

 

You’re welcome.