Learn Red – Fundamentals of Red
eBook - ePub

Learn Red – Fundamentals of Red

Get up and running with the Red language for full-stack development

Ivo Balbaert

Condividi libro
  1. 252 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Learn Red – Fundamentals of Red

Get up and running with the Red language for full-stack development

Ivo Balbaert

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

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

Key Features

  • 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.

Book Description

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.

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

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.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Learn Red – Fundamentals of Red è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Learn Red – Fundamentals of Red di Ivo Balbaert in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Programming. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2018
ISBN
9781789133653
Edizione
1
Categoria
Programming

Using Functions and Objects

This chapter is about modularizing code through the use of functions and objects.
We have already encountered a lot of built-in functions, such as print and cd, but of course you can write user-defined functions as well. When a program's code gets longer and more complex, you want to be able to give a name to certain code segments. For example, when processing a data stream from a file or the network, you'll want to have a process-request or process-record function that contains the logic of dealing with one chunk of data. That way, you can call this function each time you need it. This leads to less code that is better structured and more readable. Less code means fewer bugs! Functions can take parameters, local variables, and refinements, and we'll be exploring how to use these later on in the chapter.
Another way to group code is to define an object. Red is not class-based, like most object-oriented languages in common use today, such as Java, Python, C#, or Ruby, it takes a more prototype-based approach, where new objects can be created on the basis of an already existing object—its prototype. In this chapter, we will explore what you can do with objects in Red in depth.
In this chapter, we will cover the following topics:
  • A fauna of functions
  • Function attributes
  • Working with functions
  • Code is data and data is code
  • Using objects

Technical requirements

You'll find the code for this chapter at https://github.com/PacktPublishing/Learn-Red-Fundamentals-of-Red/tree/master/Chapter06. If you have installed Red as indicated in Chapter 2, Setting Up for Development, you are good to go. You can work on Windows, OS X, or Linux. You can type or paste any code in the Red console to see its results, or you can use an editor, such as Visual Studio Code.

A fauna of functions

Red's built-in functions can be categorized as follows. The type is indicated within ():
  • operators (op!), which can be used with infix notation, such as a + b, a / b, and so on.
  • native (native!) functions, such as if, either, while, throw, all, wait, and so on; you can see a complete list by using ? op! in the console.
  • routine (routine!) functions, such as exists?, write-clipboard, and so on; you can see a list using ? routine! It is also used in Red to define a function that calls a Red/System function (see Chapter 10, Advanced Red).
  • action (action!) functions, such as copy, move, clear, to, form, and so on; you can see a complete list using ? action!
The native, routine, and action functions are written in Red/System. Action functions are special in that they are polymorphic—they are defined for more than one datatype. Which action code is executed depends on the type of its first argument.
  • mezzanine (function!) functions, which are higher-level functions written in Red; you can see a complete list using ? function!
In this section, we'll cover the variety of ways that exist to define your own functions.

The do word

We will start by giving a name (a label) to a code block so that you can call that code by its name and evaluate it with the do word, which we already saw in action in the Evaluation with do and reduce section in Chapter 3, Using Words, Values, and Types. Here, the word pri5 is bound to a piece of code, which prints five digits separated by dashes:
;-- see Chapter06/do-does-has-func.red:
pri5: [
repeat i 5 [prin i prin "-"] ]
do pri5 ;== 1-2-3-4-5- ; evaluate code block with label pri5
t...

Indice dei contenuti