TYL PROGRAMMING LANGUAGE
▶ RECORDS ASSIGNMENT
Assign Record by Function
Let's start with a little experiment:
go:
rec1 { k 'v' }
rec2 echo rec1
print rec1
print rec2
print

rec1.k 'w'
print rec1
print rec2

echo v: v
rec1: {
 k: 'v'
 }
rec2: {
 k: 'v'
 }

rec1: {
 k: 'w'
 }
rec2: {
 k: 'v'
 }
We make use of echo function that basically returns what it gets.

From the results come some facts:

Meaning that though echo function returns what it gets, it actually returns a copy of what it gets.

This way we can use it to declare new objects based on functional activity:
go:
gone_book book
print gone_book

book: { ISBN '' title '' }
gone_book: {
 ISBN: ''
 title: ''
 }
book is a parameterless function that returns a record, and in the assignment line: gone_book book, gone_book is assigned a book record by book function.

To assign a record with data, we modify book function:
go:
gone_book book '978-3-16-148410-0' 'Gone With The Wind'
print gone_book

book isbn_val title_val:
_book {}
_book.ISBN isbn_val
_book.title title_val
_book
gone_book: {
 ISBN: '978-3-16-148410-0'
 title: 'Gone With The Wind'
 }
And a Library example:
library { name 'Carmel Library'}

go:
books
library.books books
add_book '978-3-16-148410-0' 'Gone With The Wind'
print library

add_book isbn_val title_val:
_book {}
_book.ISBN isbn_val
_book.title title_val

_books library.books
_books <- _book
library.books _books
library: {
 name: 'Carmel Library'
 books: [ : {
 ISBN: '978-3-16-148410-0'
 title: 'Gone With The Wind'
 } ]
 }
PART 5