O'Reilly logo

Seven More Languages in Seven Weeks by Bruce Tate, Jack Moffitt, Frederic Daoud, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Day 3: Balancing on a Boat

On our third and final day of Factor, we will focus on data structures called tuples, and use them to create a flexible cart checkout application. We’ll see more of Factor’s sweet spot—function composition in the concatenative style—both in the checkout example and in a revisitation of the classic “FizzBuzz” programming quiz. We’ll wrap up the chapter with a few places to look to continue your exploration of Factor.

Tuples

Factor has an object system, and tuples are classes of objects for storing values into named slots. To define a class, use TUPLE: followed by the class name and the names of the slots:

factor/examples/tuples/tuples.factor
 
USE: kernel
 
 
IN: examples.tuples
 
*
TUPLE: cart-item name price quantity ; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required