I’m working on the Clojure track syllabus and want to cover the concepts of map
, filter
and reduce
(aka fold
), the basic trio of functional iteration.
I’m looking at the various functional language tracks and am not finding any to look at for inspiration or potential ports… I’d be happy to be corrected if I’ve overlooked them.
If this is indeed new territory, maybe we could use this thread to discuss possible ideas.
There is WIP content here (PR context ). I also mention higher-order functions once in the WIP Approaches for Pangram.
Do you have specific questions about how to approach these concepts?
1 Like
No specific questions yet… but I covered them during my livestreams so I can distill the material from them (one of the exercises indeed was hamming). I’m thinking 3 separate learning exercises, first map
, then filter
and finally reduce
.
There’s a couple of old issues:
opened 06:01AM - 08 Feb 21 UTC
This issue describes how to implement the `Map` concept exercise for the Clojure… track.
## Getting started
**Please please please read the docs before starting.** Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
- [The features of v3](https://github.com/exercism/v3/blob/master/docs/features-of-v3.md).
- [Rationale for v3](https://github.com/exercism/v3/blob/master/docs/rationale-for-v3.md).
- [What are concept exercise and how they are structured?](https://github.com/exercism/v3/blob/master/docs/concept-exercises.md)
Please also watch the following video:
- [The Anatomy of a Concept Exercise](https://www.youtube.com/watch?v=gkbBqd7hPrA).
## Goal
The goal of this exercise is to teach the student how the `map` function is implemented in Clojure.
## Learning objectives
The student will gain a general understanding of:
- The concept of mapping a function on a collection
## Out of scope
- Transducers
## Concepts
- `higher-order-functions`
## Prerequisites
- `basics`
## Resources to refer to
[Clojure for the Brave and True - Core Functions in Depth](https://www.braveclojure.com/core-functions-in-depth/)
## Representer
The [Clojure Representer](https://github.com/exercism/clojure-representer) is currently being implemented and contributions are welcome.
## Analyzer
The [Clojure Analyzer](https://github.com/exercism/clojure-analyzer) is currently being implemented and contributions are welcome.
## Implementing
To implement a concept exercise, the following files must be created:
```
languages
└── clojure
└── exercises
└── concept
└── <SLUG>
├── .docs
| ├── instructions.md
| ├── introduction.md
| ├── hints.md
| └── after.md (optional)
├── .meta
| |── design.md
| └── Example.clj
├── <NAME>.clj
└── <NAME>_test.clj
```
## Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue.
opened 06:03AM - 08 Feb 21 UTC
This issue describes how to implement the `Reduce` concept exercise for the Cloj… ure track.
## Getting started
**Please please please read the docs before starting.** Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
- [The features of v3](https://github.com/exercism/v3/blob/master/docs/features-of-v3.md).
- [Rationale for v3](https://github.com/exercism/v3/blob/master/docs/rationale-for-v3.md).
- [What are concept exercise and how they are structured?](https://github.com/exercism/v3/blob/master/docs/concept-exercises.md)
Please also watch the following video:
- [The Anatomy of a Concept Exercise](https://www.youtube.com/watch?v=gkbBqd7hPrA).
## Goal
The goal of this exercise is to teach the student how the `reduce` function is implemented in Clojure.
## Learning objectives
The student will gain a general understanding of:
- The concept of reducing a function on a collection
## Out of scope
- Transducers
## Concepts
- `higher-order-functions`
## Prerequisites
- `basics`
## Resources to refer to
[Clojure for the Brave and True - Core Functions in Depth](https://www.braveclojure.com/core-functions-in-depth/)
## Representer
The [Clojure Representer](https://github.com/exercism/clojure-representer) is currently being implemented and contributions are welcome.
## Analyzer
The [Clojure Analyzer](https://github.com/exercism/clojure-analyzer) is currently being implemented and contributions are welcome.
## Implementing
To implement a concept exercise, the following files must be created:
```
languages
└── clojure
└── exercises
└── concept
└── <SLUG>
├── .docs
| ├── instructions.md
| ├── introduction.md
| ├── hints.md
| └── after.md (optional)
├── .meta
| |── design.md
| └── Example.clj
├── <NAME>.clj
└── <NAME>_test.clj
```
## Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue.
opened 06:09AM - 07 Feb 21 UTC
This issue describes how to implement the `Higher-order functions` concept exerc… ise for the Clojure track.
## Getting started
**Please please please read the docs before starting.** Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
- [The features of v3](https://github.com/exercism/v3/blob/master/docs/features-of-v3.md).
- [Rationale for v3](https://github.com/exercism/v3/blob/master/docs/rationale-for-v3.md).
- [What are concept exercise and how they are structured?](https://github.com/exercism/v3/blob/master/docs/concept-exercises.md)
Please also watch the following video:
- [The Anatomy of a Concept Exercise](https://www.youtube.com/watch?v=gkbBqd7hPrA).
## Goal
The goal of this exercise is to teach the student how to use higher-order functions in Clojure.
It can be a simple port of [elyses-transformative-enchantments](https://github.com/exercism/javascript/tree/main/exercises/concept/elyses-transformative-enchantments) from the JavaScript Track.
## Learning objectives
The student will gain a general understanding of:
- First Class Functions
- Functions that take one or more functions as arguments
- Functions that return a function as its result
## Out of scope
- This is a general overview of the concept, not in-depth usage of specific functions.
## Concepts
- `higher-order-functions`
## Prerequisites
- `basics`
## Resources to refer to
[Clojure guide - Higher Order Functions](https://clojure.org/guides/higher_order_functions)
## Representer
The [Clojure Representer](https://github.com/exercism/clojure-representer) is currently being implemented and contributions are welcome.
## Analyzer
The [Clojure Analyzer](https://github.com/exercism/clojure-analyzer) is currently being implemented and contributions are welcome.
## Implementing
To implement a concept exercise, the following files must be created:
```
languages
└── clojure
└── exercises
└── concept
└── <SLUG>
├── .docs
| ├── instructions.md
| ├── introduction.md
| ├── hints.md
| └── after.md (optional)
├── .meta
| |── design.md
| └── Example.clj
├── <NAME>.clj
└── <NAME>_test.clj
```
## Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue.
In the third one, I mentioned that the elyses-transformative-enchantments from the JavaScript track would work well.
There’s also a port of the coordinate-transformation exercise that’s nearly ready, which teaches closures , which I think nicely introduces the concept of higher-order functions.
To begin, I might adapt this exercise from Advent of Code 2021: Day 1 - Advent of Code 2021
It has an extremely elegant solution which takes advantage of Clojure’s ability to map over multiple collections in parallel.
Would this extremely elegant solution be Clojure’s equivalent of
Haskell: length $ filter id $ zipWith (<) depths (tail depths)
Python: sum(map(operator.lt, depths, depths[1:]))
Yes, it appears so! Nice In my head I’ve been calling that pattern the anti-loop because the imperative solution is a nested for
loop.
At the very latest, 10 years ago I learned about higher-order functions by reading this Learn You A Haskell chapter . (If it was earlier – probably not – it was not through that book.) I do not remember the process at all.
It was while reading that very chapter that it hit me that Clojure is basically Haskell with parentheses
You know… now that I’m looking at the Elyse’s Enchantments exercise again, it appears to be exactly these 3 concepts all in one exercise!
I can’t find this quickly right now: doth Clojure have algebraic data types/tagged unions and type classes?
Clojure will likely be my pick for the 12in23 Lisp month.
The commonalities between Haskell and lisps are very old. They might predate Haskell by decades .
This is reassuring: apparently these functions aren’t as hard to understand as my impression of some introductory materials suggests.
Those concepts do exist in Clojure (kind of… I think), but they aren’t part of the main toolbelt. The philosophy is “just use maps”.
bobahop
February 28, 2023, 7:40pm
11
Perhaps List Ops as done in C, or Strain as done in Go might offer ideas for higher-order functions for Clojure?
1 Like
In the Common Lisp track I have concepts for mapping, filtering and reducing but not yet for functions that create other functions (which I think is the more interesting concept)
The concept exercises are just ways of introducing the student to the functions in the language. I can point to the specific exercises if wanted.
1 Like