Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learn Red ? Fundamentals of Red

You're reading from   Learn Red ? Fundamentals of Red Get up and running with the Red language for full-stack development

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781789130706
Length 252 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Ivo Balbaert Ivo Balbaert
Author Profile Icon Ivo Balbaert
Ivo Balbaert
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Title Page
Copyright and Credits
Dedication
Packt Upsell
Foreword
Contributors
Preface
1. Red's Mission FREE CHAPTER 2. Setting Up for Development 3. Using Words, Values, and Types 4. Code-Controlling Structures 5. Working with Series and Blocks 6. Using Functions and Objects 7. Working with Files 8. Parsing Data 9. Composing Visual Interfaces 10. Advanced Red 1. Assessments
2. Other Books You May Enjoy Index

Copying a series


Red tries to reuse series and objects in memory as much as possible, for performance reasons. This means that using variables to point to the same series is often a bad idea and is the cause of hard-to-find bugs in your code. We have already told you in theAssigning and copying section in Chapter 3Using Words, Values, and Types, that usingcopyis the safest way to ensure that your variables point to different memory locations. That way, changes to one variable don't affect the other.

To appreciate this fact, examine and try to predict the output of the following code:

;-- see Chapter05/copying.red:
not-expected: [
    var1: ""
    append var1 "*"
    print var1
]

loop3 [do not-expected]

The do word executes the not-expected code block and append joins the var1 string with a *.

You probably expected three * lines to be printed out. But the actual output is the following:

*
**
***

Why is this? Because var1 is a string, and so is a series, and it keeps its value in memory!

The var1...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images