Consistency of do: messages in Pharo DataFrame

Different ways to enumerate data series

Oleksandr Zaitsev
May 15, 2019 · 3 min read

This post is based on my long and detailed answer to Atharva Khare’s question about the consistency of do: messages in DataSeries class of the Pharo DataFrame project.

All examples will be shown in Transcript:

To read more about Pharo DataFrame, please visit the project’s GitHub repository and read Data Analysis Made Simple with Pharo DataFrame — also known as the DataFrame booklet.

If you are new to Pharo, be sure to visit http://pharo.org/ and read Pharo by Example.

do: and withIndexDo: in Smalltalk

Collections in Smalltalk respond to a message do: which accepts aBlock as argument and applies that block to every element of the collection. aBlock therefore takes one argument - the element on which it will be applied.

For sequenceable collections, there is also a message withIndexDo: that can be used to enumerate elements together with their indices. This message accepts a two-argument block: first argument is the element, second argument is the index of that element.

do:, withIndexDo:, and withKeyDo: messages of DataSeries

In order to demonstrate the enumeration of elements of a data series, we will create a simple temperature series inspired by the weather dataset used in the DataFrame booklet:

DataSeries has message do: which takes aBlock as an argument and applies it to every element of the series. The block therefore takes one argument - the element to which it should be applied:

There is also a message withIndexDo: which allows us to enumerate elements together with their indices. It takes as argument a two-argument block which expects an element and an index:

And a similar message withKeyDo: that allows you to enumerate elements together with their keys:

Finally, thekeysDo: message allows us to enumerate only keys. It takes a one-argument block and applies it to each key of the data series.

In fact, it is the same as asking temperature series for a collection of its keys and sending do:message to that collection:

Interesting literature on this topic

  1. Section 2.7. Enumerating values of data series of the DataFrame booklet
  2. Section Enumerating Elements (p. 136) of Chapter 9. Protocol for All Collection Classes of the Blue Book
  3. Thread on the mailing list where we discussed the interface for withIndexDo:

RMoD

Joint research team between Inria, CNRS, and the Cristal /…

Oleksandr Zaitsev

Written by

PhD Student at Inria Lille, RMoD team. Researcher of software evolution at Arolla. Pharo contributor and GSoC org from Pharo Consortium. http://oleks.fr

RMoD

RMoD

Joint research team between Inria, CNRS, and the Cristal / Université de Lille. Our goal is to support ever running systems. This objective is tackled from two complementary perspectives: reengineering of large systems and constructs for dynamic reflective programming languages.

Oleksandr Zaitsev

Written by

PhD Student at Inria Lille, RMoD team. Researcher of software evolution at Arolla. Pharo contributor and GSoC org from Pharo Consortium. http://oleks.fr

RMoD

RMoD

Joint research team between Inria, CNRS, and the Cristal / Université de Lille. Our goal is to support ever running systems. This objective is tackled from two complementary perspectives: reengineering of large systems and constructs for dynamic reflective programming languages.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store