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

Partager le livre
  1. 252 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Learn Red – Fundamentals of Red

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

Ivo Balbaert

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

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.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Learn Red – Fundamentals of Red est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Learn Red – Fundamentals of Red par Ivo Balbaert en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781789133653
Édition
1
Sous-sujet
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...

Table des matiĂšres