O'Reilly logo

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

Learn Red - Fundamentals of Red

Book Description

Discover how to use the next-generation language Red for full-stack development, from systems coding over user-interfaces to blockchain programming

About This Book
  • Explore the latest features of Red to build scalable, fast, and secure applications
  • Learn graphical programming and build highly sophisticated reactive applications
  • Get familiar with the specific concepts and techniques of Red development, like working with series, viewing code as data, and using dialects.
Who This Book Is For

This book is for software developers and architects who want to learn Red because of its conciseness, flexibility, and expressiveness, and more specifically for its possibilities in GUI apps and blockchain / smart contracts programming. Some knowledge of the basic concepts and experience of any programming language is assumed.

What You Will Learn
  • Set up your Red environment to achieve the highest productivity
  • Get grounded in Red, gaining experience and insight through many examples and exercises
  • Build simple, compact, and portable applications
  • Analyze streams of data through Parse
  • Compose GUI applications with View and Draw
  • Get prepared for smart contract blockchain programming in Red
In Detail

A key problem of software development today is software bloat, where huge toolchains and development environments are needed in software coding and deployment. Red significantly reduces this bloat by offering a minimalist but complete toolchain. This is the first introductory book about it, and it will get you up and running with Red as quickly as possible.

This book shows you how to write effective functions, reduce code redundancies, and improve code reuse. It will be helpful for new programmers who are starting out with Red to explore its wide and ever-growing package ecosystem and also for experienced developers who want to add Red to their skill set.

The book presents the fundamentals of programming in Red and in-depth informative examples using a step-by-step approach. You will be taken through concepts and examples such as doing simple metaprogramming, functions, collections, GUI applications, and more. By the end of the book, you will be fully equipped to start your own projects in Red.

Style and approach

This book will gently guide you step by step into the fascinating programming universe of the Red language, offering real-world examples and practical exercises to sharpen your insight.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Learn Red – Fundamentals of Red
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Foreword
  6. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  8. Red's Mission
    1. Technical requirements
    2. A short history of Red
      1. What Red stands for
      2. Some history
    3. What makes Red special?
      1. A full-stack language – from the metal to the meta
      2. Code is data and data is code
      3. Data types built in
      4. Small toolchain and executables
      5. Dialects
    4. Red's main features
      1. Portability
      2. Like a Swiss Army knife
    5. Summary
    6. Questions
  9. Setting Up for Development
    1. Technical requirements
    2. Installing Red
      1. Installing Red on Windows
      2. Installing Red on Linux and macOS
      3. A look at the source code
    3. Working interactively in the Red console
    4. Running and compiling your first script
      1. Executing a script in the Red console
      2. Compiling a script to an executable
        1. Development mode
        2. Release mode
    5. Other compilation options
    6. Red's compilation model
    7. Development environments for writing Red
      1. Simple text editors
      2. More sophisticated editors
    8. Summary
    9. Questions
  10. Using Words, Values, and Types
    1. Technical requirements
    2. Understanding words and values
    3. Some common datatypes
    4. Using blocks and parens
      1. Comments
    5. Word bindings
      1. Inferring types
      2. Assigning and copying
      3. Working with words
    6. More about types
      1. Converting types
      2. The type system
    7. Evaluating expressions and blocks
      1. Some basic operations
        1. Working with Boolean values
        2. Working with numbers
        3. Making random objects
      2. Order of evaluation
      3. Evaluation with do and reduce
    8. The structure of a Red program
    9. Summary
    10. Questions
    11. Further reading
  11. Code-Controlling Structures
    1. Technical requirements
    2. Getting input from the user – input and ask
    3. Testing conditions
      1. if  
      2. unless
      3. either 
      4. Stopping a program – halt or quit
      5. switch and case
      6. catch and throw
    4. Structuring repetitions
      1. Repeating a number of times – loop or repeat
      2. Repeating with a condition – while or until
    5. A number-guessing game
    6. Handling errors
      1. attempt and try
      2. Using error?
    7. Creating and catching errors
      1. Checking types
    8. Summary
    9. Questions
  12. Working with Series and Blocks
    1. Technical requirements
    2. Series and blocks
    3. Navigating and looping through a series
      1. A step at a time – head, tail, index?, and next
      2. Looping through a series – foreach and forall
    4. Getting information from a series
      1. Selecting an item – pick and /
      2. Searching for an item – select and find
        1. Sorting
    5. Changing a series
      1. Changing items – poke, replace, and change
      2. Adding new items – append, repend, and insert
        1. append
        2. repend
        3. insert
      3. Deleting items – remove and take
      4. Moving items – move and swap
      5. Series as sets
    6. Copying a series
    7. Strings as series
      1. Splitting a string – split
      2. Turning a series into a string – form
      3. Rejoining a block – rejoin
      4. Clearing part of a string – clear and trim
      5. Adding to a string – append and insert
      6. Other useful tricks
    8. Summary
    9. Questions
  13. Using Functions and Objects
    1. Technical requirements
    2. A fauna of functions
      1. The do word
      2. The does word
      3. The has word
      4. The func word
      5. The function word
      6. Copying a local series
    3. Function attributes
      1. Passing arguments
      2. Typing arguments
      3. Return values – return and exit
      4. Refinements
      5. Code style and documentation strings
    4. Working with functions
      1. Error handling
      2. Recursive functions
      3. Importing functions with do
    5. Code is data and data is code
      1. Using reflection on functions
        1. The source word
        2. The body-of function
        3. Changing the header and body of a function through code
      2. Code is just data – load
    6. Using objects
      1. The make word
      2. Working with objects
        1. Creating objects
        2. Working with fields and functions
        3. Copying objects and inheritance
        4. Looking inside an object
    7. Summary
    8. Questions
  14. Working with Files
    1. Technical requirements
    2. Selecting a file or folder
    3. Working with file paths and directories
    4. Reading and writing data files
      1. Working with binary files
        1. The image! datatype
      2. Downloading a file from the internet 
    5. Loading and saving files
      1. Saving and loading the console history
    6. Downloading currency exchange rates
      1. Using query string parameters
    7. Summary
    8. Questions
  15. Parsing Data
    1. Technical requirements
    2. The bitset! datatype
    3. Understanding how parse works
      1. First parse examples
      2. Using some and any
      3. Matching positions
      4. Choosing with |
    4. Searching, extracting, and changing
      1. Working with variables – to, thru, and copy
      2. Executing code on a match
      3. Changing data – change, remove, and insert
    5. More features and examples
      1. Using end
      2. Building special languages
      3. Changing a rule on the fly
      4. Parsing blocks and code
      5. Debugging parse
    6. Summary
    7. Questions
  16. Composing Visual Interfaces
    1. Technical requirements
    2. Structuring an interface
      1. First example – a screen for downloading exchange rates
        1. Running the example
        2. Examining the code
        3. Building a layout
        4. Faces and actions
        5. Two-way binding
      2. Container settings – view
        1. Changing an app's icon
        2. View's refinements
        3. Using do in view
      3. Layout commands
    3. A faces walkthrough
      1. Base, box, and image
      2. Text faces – h1, text, field, and area
      3. Button, check, and radio
      4. List faces – text-list, drop-list, and drop-down
      5. Panel, group-box, and tab-panel
      6. Progress bar and slider
      7. Styles
    4. Events and actors
      1. Multiple events
      2. Timer event
      3. Actors are objects
      4. Detecting the keyboard
      5. Menus
    5. Basic contacts app
    6. An introduction to the draw dialect
    7. Summary
    8. Questions
    9. Further reading
  17. Advanced Red
    1. Technical requirements
    2. Reactive programming
    3. Red/System
      1. Comparing Red and Red/System
      2. Calling a Red/System script from within Red
    4. Interacting with the operating system
      1. Getting input from command-line arguments
      2. Calling an external program – call
      3. Using the OS clipboard – read-clipboard
    5. Datatypes for performance
      1. The vector! datatype
      2. The map! and hash! datatypes
    6. Embedded Red and macros
      1. Embedded Red
      2. Macros
    7. Red for smart contract programming
      1. Red/C3 
      2. Using Red for writing dapps
    8. Red's roadmap
    9. Some useful references
    10. Summary
    11. Questions
    12. Further reading
  18. Assessments
  19. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think